/
NavigationTest.swift
285 lines (236 loc) · 11.4 KB
/
NavigationTest.swift
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/* 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
let website_1 = ["url": "www.mozilla.org", "label": "Internet for people, not profit — Mozilla", "value": "mozilla.org"]
let website_2 = ["url": "www.yahoo.com", "label": "Yahoo", "value": "yahoo"]
let urlAddOns = "addons.mozilla.org"
class NavigationTest: BaseTestCase {
var navigator: Navigator!
var app: XCUIApplication!
override func setUp() {
super.setUp()
app = XCUIApplication()
navigator = createScreenGraph(app).navigator(self)
}
override func tearDown() {
super.tearDown()
}
func testNavigation() {
navigator.goto(URLBarOpen)
let urlPlaceholder = "Search or enter address"
XCTAssert(app.textFields["url"].exists)
let defaultValuePlaceholder = app.textFields["url"].placeholderValue!
// Check the url placeholder text and that the back and forward buttons are disabled
XCTAssert(urlPlaceholder == defaultValuePlaceholder)
if iPad() {
app.buttons["Cancel"].tap()
XCTAssertFalse(app.buttons["URLBarView.backButton"].isEnabled)
XCTAssertFalse(app.buttons["Forward"].isEnabled)
app.textFields["url"].tap()
} else {
XCTAssertFalse(app.buttons["TabToolbar.backButton"].isEnabled)
XCTAssertFalse(app.buttons["TabToolbar.forwardButton"].isEnabled)
}
// Once an url has been open, the back button is enabled but not the forward button
navigator.openURL(urlString: website_1["url"]!)
waitForValueContains(app.textFields["url"], value: website_1["value"]!)
if iPad() {
XCTAssertTrue(app.buttons["URLBarView.backButton"].isEnabled)
XCTAssertFalse(app.buttons["Forward"].isEnabled)
} else {
XCTAssertTrue(app.buttons["TabToolbar.backButton"].isEnabled)
XCTAssertFalse(app.buttons["TabToolbar.forwardButton"].isEnabled)
}
// Once a second url is open, back button is enabled but not the forward one till we go back to url_1
navigator.openURL(urlString: website_2["url"]!)
waitForValueContains(app.textFields["url"], value: website_2["value"]!)
if iPad() {
XCTAssertTrue(app.buttons["URLBarView.backButton"].isEnabled)
XCTAssertFalse(app.buttons["Forward"].isEnabled)
// Go back to previous visited web site
app.buttons["URLBarView.backButton"].tap()
} else {
XCTAssertTrue(app.buttons["TabToolbar.backButton"].isEnabled)
XCTAssertFalse(app.buttons["TabToolbar.forwardButton"].isEnabled)
// Go back to previous visited web site
app.buttons["TabToolbar.backButton"].tap()
}
waitForValueContains(app.textFields["url"], value: website_1["value"]!)
if iPad() {
app.buttons["Forward"].tap()
} else {
// Go forward to next visited web site
app.buttons["TabToolbar.forwardButton"].tap()
}
waitForValueContains(app.textFields["url"], value: website_2["value"]!)
}
func testTapSignInShowsFxAFromTour() {
navigator.goto(SettingsScreen)
// Open FxAccount from tour option in settings menu and go throughout all the screens there
// Tour's first screen Organize
navigator.goto(Intro_Welcome)
// Tour's last screen Sync
navigator.goto(Intro_Sync)
// Finally Sign in to Firefox screen should be shown correctly
app.buttons["Sign in to Firefox"].tap()
checkFirefoxSyncScreenShown()
// Go back to NewTabScreen
app.navigationBars["Client.FxAContentView"].buttons["Done"].tap()
navigator.nowAt(NewTabScreen)
}
func testTapSigninShowsFxAFromSettings() {
navigator.goto(SettingsScreen)
// Open FxAccount from settings menu and check the Sign in to Firefox scren
let signInToFirefoxStaticText = app.tables["AppSettingsTableViewController.tableView"].staticTexts["Sign in to Sync"]
signInToFirefoxStaticText.tap()
checkFirefoxSyncScreenShown()
// After that it is possible to go back to Settings
let settingsButton = app.navigationBars["Client.FxAContentView"].buttons["Settings"]
settingsButton.tap()
}
func testTapSignInShowsFxAFromRemoteTabPanel() {
navigator.goto(NewTabScreen)
// Open FxAccount from remote tab panel and check the Sign in to Firefox scren
navigator.goto(HomePanel_History)
XCTAssertTrue(app.tables["History List"].staticTexts["Synced Devices"].isEnabled)
app.tables["History List"].staticTexts["Synced Devices"].tap()
app.tables.buttons["Sign in"].tap()
checkFirefoxSyncScreenShown()
app.navigationBars["Client.FxAContentView"].buttons["Done"].tap()
navigator.nowAt(HomePanel_History)
}
private func checkFirefoxSyncScreenShown() {
waitforExistence(app.webViews.staticTexts["Sign in"])
XCTAssertTrue(app.webViews.textFields["Email"].exists)
XCTAssertTrue(app.webViews.secureTextFields["Password"].exists)
XCTAssertTrue(app.webViews.buttons["Sign in"].exists)
}
func testScrollsToTopWithMultipleTabs() {
navigator.goto(TabTray)
navigator.openURL(urlString: website_1["url"]!)
waitForValueContains(app.textFields["url"], value: website_1["value"]!)
// Element at the TOP. TBChanged once the web page is correclty shown
let topElement = app.webViews.staticTexts["Internet for people, "]
// Element at the BOTTOM
let bottomElement = app.webViews.links.staticTexts["Contact Us"]
// Scroll to bottom
bottomElement.tap()
if iPad() {
app.buttons["URLBarView.backButton"].tap()
} else {
app.buttons["TabToolbar.backButton"].tap()
}
// Scroll to top
topElement.tap()
}
private func checkMobileView() {
let mobileViewElement = app.webViews.links.staticTexts["View classic desktop site"]
waitforExistence(mobileViewElement)
XCTAssertTrue (mobileViewElement.exists, "Mobile view is not available")
}
private func checkDesktopView() {
let desktopViewElement = app.webViews.links.staticTexts["View Mobile Site"]
waitforExistence(desktopViewElement)
XCTAssertTrue (desktopViewElement.exists, "Desktop view is not available")
}
private func clearData() {
navigator.goto(ClearPrivateDataSettings)
app.tables.staticTexts["Clear Private Data"].tap()
app.alerts.buttons["OK"].tap()
navigator.goto(NewTabScreen)
}
func testToggleBetweenMobileAndDesktopSiteFromSite() {
clearData()
let goToDesktopFromMobile = app.webViews.links.staticTexts["View classic desktop site"]
// Open URL by default in mobile view
navigator.openURL(urlString: urlAddOns)
waitForValueContains(app.textFields["url"], value: urlAddOns)
waitforExistence(goToDesktopFromMobile)
// From the website go to Desktop view
goToDesktopFromMobile.tap()
checkDesktopView()
// From the website go back to Mobile view
app.webViews.links.staticTexts["View Mobile Site"].tap()
checkMobileView()
}
func testToggleBetweenMobileAndDesktopSiteFromMenu() {
clearData()
navigator.openURL(urlString: urlAddOns)
waitForValueContains(app.textFields["url"], value: urlAddOns)
// Mobile view by default, desktop view should be available
navigator.browserPerformAction(.requestDesktop)
checkDesktopSite()
// From desktop view it is posible to change to mobile view again
navigator.nowAt(BrowserTab)
navigator.browserPerformAction(.requestMobile)
checkMobileSite()
}
private func checkMobileSite() {
app.buttons["TabToolbar.menuButton"].tap()
waitforExistence(app.collectionViews.cells["RequestDesktopMenuItem"])
navigator.goto(BrowserTab)
}
private func checkDesktopSite() {
app.buttons["TabToolbar.menuButton"].tap()
waitforExistence(app.collectionViews.cells["RequestMobileMenuItem"])
navigator.goto(BrowserTab)
}
func testNavigationPreservesDesktopSiteOnSameHost() {
clearData()
navigator.openURL(urlString: urlAddOns)
// Mobile view by default, desktop view should be available
//navigator.browserPerformAction(.requestDesktop)
navigator.goto(BrowserTabMenu)
waitforExistence(app.collectionViews.cells["RequestDesktopMenuItem"])
app.collectionViews.cells["RequestDesktopMenuItem"].tap()
checkDesktopView()
// Select any link to navigate to another site and check if the view is kept in desktop view
waitforExistence(app.webViews.links["Featured ›"])
app.webViews.links["Featured ›"].tap()
checkDesktopView()
}
func testReloadPreservesMobileOrDesktopSite() {
clearData()
navigator.openURL(urlString: urlAddOns)
// Mobile view by default, desktop view should be available
navigator.browserPerformAction(.requestDesktop)
// After reloading a website the desktop view should be kept
app.buttons["Reload"].tap()
waitForValueContains(app.textFields["url"], value: urlAddOns)
checkDesktopView()
// From desktop view it is posible to change to mobile view again
navigator.nowAt(BrowserTab)
navigator.browserPerformAction(.requestMobile)
waitForValueContains(app.textFields["url"], value: urlAddOns)
// After reloading a website the mobile view should be kept
app.buttons["Reload"].tap()
checkMobileView()
}
/* Test disabled till bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1346157 is fixed
func testBackForwardNavigationRestoresMobileOrDesktopSite() {
clearData()
let desktopViewElement = app.webViews.links.staticTexts["Mobile"]
let collectionViewsQuery = app.collectionViews
// Open first url and keep it in mobile view
navigator.openURL(urlString: urlAddOns)
waitForValueContains(app.textFields["url"], value: urlAddOns)
checkMobileView()
// Open a second url and change it to desktop view
navigator.openURL(urlString: "www.linkedin.com")
navigator.goto(BrowserTabMenu)
waitforExistence(collectionViewsQuery.cells["RequestDesktopMenuItem"])
collectionViewsQuery.cells["RequestDesktopMenuItem"].tap()
waitforExistence(desktopViewElement)
XCTAssertTrue (desktopViewElement.exists, "Desktop view is not available")
// Go back to first url and check that the view is still mobile view
app.buttons["TabToolbar.backButton"].tap()
waitForValueContains(app.textFields["url"], value: urlAddOns)
checkMobileView()
// Go forward to second url and check that the view is still desktop view
app.buttons["TabToolbar.forwardButton"].tap()
waitForValueContains(app.textFields["url"], value: "www.linkedin.com")
waitforExistence(desktopViewElement)
XCTAssertTrue (desktopViewElement.exists, "Desktop view is not available after coming from another site in mobile view")
}*/
}