<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import XCTest

class SettingAppearanceTest: BaseTestCase {
    override func setUp() {
        super.setUp()
        dismissFirstRunUI()
    }
    
    override func tearDown() {
        app.terminate()
        super.tearDown()
    }
    
    // Check for the basic appearance of the Settings Menu
    func testCheckSetting() {
        waitforHittable(element: app.buttons["Settings"])
        app.buttons["Settings"].tap()
        
        // Check About page
        app.tables.firstMatch.swipeUp()
        let aboutCell = app.cells["settingsViewController.about"]
        waitforHittable(element: aboutCell)
        aboutCell.tap()
        
        let tablesQuery = app.tables
        
        // Check Help page, wait until the webpage is shown
        waitforHittable(element: tablesQuery.staticTexts["Help"])
        tablesQuery.staticTexts["Help"].tap()
        if app.label == "Firefox Focus" {
            waitforHittable(element: app.staticTexts["What is Firefox Focus?"])
            app.navigationBars["Firefox_Focus.SettingsContentView"].buttons["About"].tap()
        } else {
            waitforHittable(element: app.staticTexts["Firefox Klar"])
            app.navigationBars["Firefox_Klar.SettingsContentView"].buttons["About"].tap()
        }
        
        // Check Your Rights page, until the text is displayed
        tablesQuery.staticTexts["Your Rights"].tap()
        if app.label == "Firefox Focus" {
            waitforHittable(element: app.staticTexts["Your Rights"])
            app.navigationBars["Firefox_Focus.SettingsContentView"].buttons["About"].tap()
        } else {
            waitforHittable(element: app.staticTexts["Ihre Rechte"])
            app.navigationBars["Firefox_Klar.SettingsContentView"].buttons["About"].tap()
        }
        
        // Go to Settings
        waitforHittable(element: app.navigationBars["About"].buttons["Settings"])
        app.navigationBars["About"].buttons["Settings"].tap()
        
        //Check the initial state of the switch values
        let safariSwitch = app.tables.switches["Safari"]
        let otherContentSwitch = app.tables.switches["BlockerToggle.BlockOther"]
        
        XCTAssertEqual(safariSwitch.value as! String, "0")
        safariSwitch.tap()
        
        // Check the information page
        XCTAssert(app.staticTexts["Open Settings App"].exists)
        XCTAssert(app.staticTexts["Tap Safari, then select Content Blockers"].exists)
        if app.label == "Firefox Focus" {
            XCTAssert(app.staticTexts["Firefox Focus is not enabled."].exists)
            XCTAssert(app.staticTexts["Enable Firefox Focus"].exists)
            app.navigationBars["Firefox_Focus.SafariInstructionsView"].buttons["Settings"].tap()
        } else {
            XCTAssert(app.staticTexts["Firefox Klar is not enabled."].exists)
            XCTAssert(app.staticTexts["Enable Firefox Klar"].exists)
            app.navigationBars["Firefox_Klar.SafariInstructionsView"].buttons["Settings"].tap()
        }
        
        // Swipe up
        waitforExistence(element: app.tables.switches["BlockerToggle.BlockAds"])
        app.tables.firstMatch.swipeUp()
        
        XCTAssertEqual(app.tables.switches["BlockerToggle.BlockAds"].value as! String, "1")
        XCTAssertEqual(app.tables.switches["BlockerToggle.BlockAnalytics"].value as! String, "1")
        XCTAssertEqual(app.tables.switches["BlockerToggle.BlockSocial"].value as! String, "1")
        XCTAssertEqual(otherContentSwitch.value as! String, "0")
        XCTAssertEqual(app.tables.switches["BlockerToggle.BlockFonts"].value as! String, "0")
        if app.label == "Firefox Focus" {
            XCTAssertEqual(app.tables.switches["Send usage data"].value as! String, "1")
        } else {
            XCTAssertEqual(app.tables.switches["Send usage data"].value as! String, "0")
        }
        
        otherContentSwitch.tap()
        let alertsQuery = app.alerts
        
        // Say yes this time, the switch should be enabled
        alertsQuery.buttons["I Understand"].tap()
        XCTAssertEqual(otherContentSwitch.value as! String, "1")
        otherContentSwitch.tap()
        
        // Say No this time, the switch should remain disabled
        otherContentSwitch.tap()
        alertsQuery.buttons["No, Thanks"].tap()
        XCTAssertEqual(otherContentSwitch.value as! String, "0")
        
        // Check navigate to app store review and back
        let reviewCell = app.cells["settingsViewController.rateFocus"]
        let safariApp = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.mobilesafari")!
        
        waitforHittable(element: reviewCell)
        reviewCell.tap()
        waitforExistence(element: safariApp)
        XCTAssert(safariApp.state == .runningForeground)
        app.activate()
    }
    
    func testOpenInSafari() {
        let safariapp = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.mobilesafari")!
        loadWebPage("https://www.google.com", waitForLoadToFinish: true)
        
        waitforHittable(element: app.buttons["Share"])
        app.buttons["Share"].tap()
        let requestDesktop = app.buttons["Request Desktop Site"]
        waitforHittable(element: requestDesktop)
        requestDesktop.swipeLeft()
        
        let safariButton = app.buttons["Open in Safari"]
        waitforHittable(element: safariButton)
        safariButton.tap()
        
        // Now in Safari
        let safariLabel = safariapp.otherElements["Address"]
        waitForValueContains(element: safariLabel, value: "google")
        
        // Go back to Focus
        app.activate()
        
        // Now back to Focus
        waitForValueContains(element: app.textFields["Search or enter address"], value: "https://www.google")
        waitForWebPageLoad()
        app.buttons["ERASE"].tap()
        waitforExistence(element: app.staticTexts["Your browsing history has been erased."])
    }
    
    func testDisableAutocomplete() {
        // Navigate to Settings
        waitforHittable(element: app.buttons["Settings"])
        app.buttons["Settings"].tap()
        <commit_msg>Fixes #1026: Open in Safari UI test fails (#1027)<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import XCTest

class SettingAppearanceTest: BaseTestCase {
    override func setUp() {
        super.setUp()
        dismissFirstRunUI()
    }
    
    override func tearDown() {
        app.terminate()
        super.tearDown()
    }
    
    // Check for the basic appearance of the Settings Menu
    func testCheckSetting() {
        waitforHittable(element: app.buttons["Settings"])
        app.buttons["Settings"].tap()
        
        // Check About page
        app.tables.firstMatch.swipeUp()
        let aboutCell = app.cells["settingsViewController.about"]
        waitforHittable(element: aboutCell)
        aboutCell.tap()
        
        let tablesQuery = app.tables
        
        // Check Help page, wait until the webpage is shown
        waitforHittable(element: tablesQuery.staticTexts["Help"])
        tablesQuery.staticTexts["Help"].tap()
        if app.label == "Firefox Focus" {
            waitforHittable(element: app.staticTexts["What is Firefox Focus?"])
            app.navigationBars["Firefox_Focus.SettingsContentView"].buttons["About"].tap()
        } else {
            waitforHittable(element: app.staticTexts["Firefox Klar"])
            app.navigationBars["Firefox_Klar.SettingsContentView"].buttons["About"].tap()
        }
        
        // Check Your Rights page, until the text is displayed
        tablesQuery.staticTexts["Your Rights"].tap()
        if app.label == "Firefox Focus" {
            waitforHittable(element: app.staticTexts["Your Rights"])
            app.navigationBars["Firefox_Focus.SettingsContentView"].buttons["About"].tap()
        } else {
            waitforHittable(element: app.staticTexts["Ihre Rechte"])
            app.navigationBars["Firefox_Klar.SettingsContentView"].buttons["About"].tap()
        }
        
        // Go to Settings
        waitforHittable(element: app.navigationBars["About"].buttons["Settings"])
        app.navigationBars["About"].buttons["Settings"].tap()
        
        //Check the initial state of the switch values
        let safariSwitch = app.tables.switches["Safari"]
        let otherContentSwitch = app.tables.switches["BlockerToggle.BlockOther"]
        
        XCTAssertEqual(safariSwitch.value as! String, "0")
        safariSwitch.tap()
        
        // Check the information page
        XCTAssert(app.staticTexts["Open Settings App"].exists)
        XCTAssert(app.staticTexts["Tap Safari, then select Content Blockers"].exists)
        if app.label == "Firefox Focus" {
            XCTAssert(app.staticTexts["Firefox Focus is not enabled."].exists)
            XCTAssert(app.staticTexts["Enable Firefox Focus"].exists)
            app.navigationBars["Firefox_Focus.SafariInstructionsView"].buttons["Settings"].tap()
        } else {
            XCTAssert(app.staticTexts["Firefox Klar is not enabled."].exists)
            XCTAssert(app.staticTexts["Enable Firefox Klar"].exists)
            app.navigationBars["Firefox_Klar.SafariInstructionsView"].buttons["Settings"].tap()
        }
        
        // Swipe up
        waitforExistence(element: app.tables.switches["BlockerToggle.BlockAds"])
        app.tables.firstMatch.swipeUp()
        
        XCTAssertEqual(app.tables.switches["BlockerToggle.BlockAds"].value as! String, "1")
        XCTAssertEqual(app.tables.switches["BlockerToggle.BlockAnalytics"].value as! String, "1")
        XCTAssertEqual(app.tables.switches["BlockerToggle.BlockSocial"].value as! String, "1")
        XCTAssertEqual(otherContentSwitch.value as! String, "0")
        XCTAssertEqual(app.tables.switches["BlockerToggle.BlockFonts"].value as! String, "0")
        if app.label == "Firefox Focus" {
            XCTAssertEqual(app.tables.switches["Send usage data"].value as! String, "1")
        } else {
            XCTAssertEqual(app.tables.switches["Send usage data"].value as! String, "0")
        }
        
        otherContentSwitch.tap()
        let alertsQuery = app.alerts
        
        // Say yes this time, the switch should be enabled
        alertsQuery.buttons["I Understand"].tap()
        XCTAssertEqual(otherContentSwitch.value as! String, "1")
        otherContentSwitch.tap()
        
        // Say No this time, the switch should remain disabled
        otherContentSwitch.tap()
        alertsQuery.buttons["No, Thanks"].tap()
        XCTAssertEqual(otherContentSwitch.value as! String, "0")
        
        // Check navigate to app store review and back
        let reviewCell = app.cells["settingsViewController.rateFocus"]
        let safariApp = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.mobilesafari")!
        
        waitforHittable(element: reviewCell)
        reviewCell.tap()
        waitforExistence(element: safariApp)
        XCTAssert(safariApp.state == .runningForeground)
        app.activate()
    }
    
    func testOpenInSafari() {
        let safariapp = XCUIApplication(privateWithPath: nil, bundleID: "com.apple.mobilesafari")!
        loadWebPage("https://www.google.com", waitForLoadToFinish: true)
        
        waitforHittable(element: app.buttons["Share"])
        app.buttons["Share"].tap()
        let findInPage = app.buttons["Find in Page"]
        waitforHittable(element: findInPage)
        findInPage.swipeLeft()
        
        let safariButton = app.buttons["Open in Safari"]
        waitforHittable(element: safariButton)
        safariButton.tap()
        
        // Now in Safari
        let safariLabel = safariapp.otherElements["Address"]
        waitForValueContains(element: safariLabel, value: "google")
        
        // Go back to Focus
        app.activate()
        
        // Now back to Focus
        waitForWebPageLoad()
        app.buttons["ERASE"].tap()
        waitforExistence(element: app.staticTexts["Your browsing history has been erased."])
    }
    
    func testDisableAutocomplete() {
        // Navigate to Settings
        waitforHittable(element: app.buttons["Settings"])
        app.buttons["Settings"].tap()
        
{'fraction_non_alphanumeric': 0.11252973830293418, 'fraction_numerical': 0.0028548770816812052, 'mean_word_length': 2.568477645727221, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2538756', 'n_tokens_mistral': 3583, 'n_tokens_neox': 3493, 'n_words': 731}