forked from agentic-review-benchmarks/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCookiePersistenceTests.swift
More file actions
122 lines (97 loc) · 3.96 KB
/
CookiePersistenceTests.swift
File metadata and controls
122 lines (97 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// 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
final class CookiePersistenceTests: BaseTestCase {
let cookieSiteURL = "http://localhost:\(serverPort)/test-fixture/test-cookie-store.html"
let topSitesTitle = ["Facebook", "YouTube", "Wikipedia"]
override func setUp() async throws {
// Fresh install the app
// removeApp() does not work on iOS 15 and 16 intermittently
if #available(iOS 17, *) {
removeApp()
}
// The app is correctly installed
try await super.setUp()
}
func testCookiePersistenceBasic() {
// Open URL for Cookie login
openCookieSite()
let webview = app.webViews.firstMatch
mozWaitForElementToExist(webview.staticTexts["LOGGED_OUT"])
// Tap on Log in
webview.buttons["Login"].waitAndTap()
mozWaitForElementToExist(webview.staticTexts["LOGGED_IN"])
// Relaunch app
relaunchApp()
openCookieSite()
mozWaitForElementToExist(webview.staticTexts["LOGGED_IN"])
}
func testCookiePersistenceOpenNewTab() {
// Open URL for Cookie login
openCookieSite()
let webview = app.webViews.firstMatch
mozWaitForElementToExist(webview.staticTexts["LOGGED_OUT"])
// Tap on Log in
webview.buttons["Login"].waitAndTap()
mozWaitForElementToExist(webview.staticTexts["LOGGED_IN"])
// Open a few tabs
topSitesTitle.forEach { title in
navigator.performAction(Action.OpenNewTabFromTabTray)
navigator.nowAt(NewTabScreen)
app.collectionViews.links.staticTexts[title].waitAndTap()
waitUntilPageLoad()
navigator.nowAt(BrowserTab)
}
// Relaunch app
relaunchApp()
// Open a new tab for cookie website and check login status
openCookieSite()
mozWaitForElementToExist(webview.staticTexts["LOGGED_IN"])
}
func testCookiePersistenceOpenRegularTabAfterPrivateTab() {
// Go to private tab
navigator.toggleOn(userState.isPrivate, withAction: Action.ToggleExperimentPrivateMode)
if userState.isPrivate {
app.buttons[AccessibilityIdentifiers.TabTray.newTabButton].waitAndTap()
navigator.nowAt(BrowserTab)
}
// Open URL for Cookie login
openCookieSite()
let webview = app.webViews.firstMatch
mozWaitForElementToExist(webview.staticTexts["LOGGED_OUT"])
// Tap on Log in
webview.buttons["Login"].waitAndTap()
mozWaitForElementToExist(webview.staticTexts["LOGGED_IN"])
// Open regular tabs
// navigate to website and expect not to be login
app.buttons[AccessibilityIdentifiers.Toolbar.tabsButton].tap()
mozWaitForElementToExist(app.buttons["Private"])
if iPad() {
app.segmentedControls.buttons.firstMatch.waitAndTap()
} else {
app.buttons["Tabs"].tap()
}
app.buttons[AccessibilityIdentifiers.TabTray.newTabButton].waitAndTap()
openCookieSite()
mozWaitForElementToExist(webview.staticTexts["LOGGED_OUT"])
}
private func relaunchApp() {
// Restart the app
app.terminate()
// Wait a moment if needed (optional but sometimes helpful)
sleep(1)
// Launch it again
app.launch()
}
private func openCookieSite() {
navigator.openURL(path(forTestPage: "test-cookie-store.html"))
waitUntilPageLoad()
navigator.nowAt(BrowserTab)
let webview = app.webViews.firstMatch
mozWaitForElementToExist(webview.staticTexts["Cookie Test Page"])
mozWaitForElementToExist(webview.textFields.firstMatch)
mozWaitForElementToExist(webview.buttons["Login"])
mozWaitForElementToExist(webview.buttons["Logout"])
}
}