Repository Public License
1import XCTest23/// Mac flows. XCUITest drives the real keyboard and pointer and brings the app to the front: run this suite4/// only on a machine nobody is using (`ORIX_ALLOW_MAC_UITEST=1 scripts/uitest.sh mac`).5@MainActor6final class NavigatorMacUITests: XCTestCase {7 private var dataDirectory = ""8 private var fixtureBase: String { ProcessInfo.processInfo.environment["ORIX_FIXTURE_URL"] ?? "http://127.0.0.1:8765" }910 override func setUp() async throws {11 continueAfterFailure = false12 // The app is sandboxed: its throwaway data lives in its own container.13 dataDirectory = NSHomeDirectory() + "/Library/Containers/ai.spboucher.orix.navigator/Data/tmp/orix-uitest-\(UUID().uuidString)"14 }1516 override func tearDown() async throws {17 try? FileManager.default.removeItem(atPath: dataDirectory)18 }1920 private func launch(_ extra: [String] = []) -> XCUIApplication {21 let app = XCUIApplication()22 app.launchArguments = ["-ORIXDataDir", dataDirectory, "-ORIXSkipOnboarding", "YES", "-ApplePersistenceIgnoreState", "YES", "-AppleLanguages", "(en)"] + extra23 app.launch()24 return app25 }2627 private func open(_ address: String, in app: XCUIApplication) {28 app.typeKey("l", modifierFlags: .command)29 let field = app.textFields["omnibox.field"]30 XCTAssertTrue(field.waitForExistence(timeout: 5))31 field.typeText(address + "\n")32 }3334 func testBrowsingTabsAndRestoration() throws {35 var app = launch()36 XCTAssertTrue(app.windows.firstMatch.waitForExistence(timeout: 20))37 open("\(fixtureBase)/one.html", in: app)38 XCTAssertTrue(app.webViews.staticTexts["Fixture page one"].waitForExistence(timeout: 20))3940 app.typeKey("t", modifierFlags: .command)41 open("\(fixtureBase)/two.html", in: app)42 XCTAssertTrue(app.webViews.staticTexts["Fixture page two"].waitForExistence(timeout: 20))4344 app.typeKey("1", modifierFlags: .command)45 XCTAssertTrue(app.webViews.staticTexts["Fixture page one"].waitForExistence(timeout: 10))46 app.typeKey("2", modifierFlags: .command)47 app.typeKey("w", modifierFlags: .command)48 XCTAssertTrue(app.webViews.staticTexts["Fixture page one"].waitForExistence(timeout: 10))49 app.typeKey("t", modifierFlags: [.command, .shift])50 XCTAssertTrue(app.webViews.staticTexts["Fixture page two"].waitForExistence(timeout: 20))5152 app.typeKey("q", modifierFlags: .command)53 XCTAssertTrue(app.wait(for: .notRunning, timeout: 10))54 app = launch()55 XCTAssertTrue(app.webViews.staticTexts["Fixture page two"].waitForExistence(timeout: 20), "the selected tab is restored")56 XCTAssertFalse(app.buttons["Restore"].exists)57 }5859 func testMenusAndPanels() throws {60 let app = launch()61 XCTAssertTrue(app.windows.firstMatch.waitForExistence(timeout: 20))62 XCTAssertFalse(app.menuBars.menuItems["Back"].isEnabled, "Back is disabled on a new tab")63 XCTAssertFalse(app.menuBars.menuItems["Find in Page…"].isEnabled)64 app.typeKey("y", modifierFlags: .command)65 XCTAssertTrue(app.descendants(matching: .any)["panel.history"].waitForExistence(timeout: 5))66 app.typeKey(",", modifierFlags: .command)67 XCTAssertTrue(app.descendants(matching: .any)["panel.settings"].waitForExistence(timeout: 5))68 app.typeKey("s", modifierFlags: .command)69 XCTAssertFalse(app.descendants(matching: .any)["sidebar"].exists, "⌘S hides the sidebar")70 app.typeKey("s", modifierFlags: .command)71 XCTAssertTrue(app.descendants(matching: .any)["sidebar"].waitForExistence(timeout: 5))72 }7374 func testAccessibilityAudit() throws {75 let app = launch()76 XCTAssertTrue(app.windows.firstMatch.waitForExistence(timeout: 20))77 try app.performAccessibilityAudit()78 }79}80