-
Notifications
You must be signed in to change notification settings - Fork 27
/
PrivateBrowsingTest.swift
166 lines (134 loc) · 7.04 KB
/
PrivateBrowsingTest.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
/* 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 url1 = "www.mozilla.org"
let url2 = "www.facebook.com"
let url1Label = "Internet for people, not profit — Mozilla"
let url2Label = "Facebook - Log In or Sign Up"
class PrivateBrowsingTest: 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 testPrivateTabDoesNotTrackHistory() {
navigator.openURL(urlString: url1)
navigator.goto(BrowserTabMenu)
// Go to History screen
waitforExistence(app.tables.cells["History"])
app.tables.cells["History"].tap()
navigator.nowAt(BrowserTab)
waitforExistence(app.tables["History List"])
XCTAssertTrue(app.tables["History List"].staticTexts[url1Label].exists)
// History without counting Recently Closed and Synced devices
let history = app.tables["History List"].cells.count - 2
XCTAssertEqual(history, 1, "History entries in regular browsing do not match")
// Go to Private browsing to open a website and check if it appears on History
navigator.goto(PrivateTabTray)
navigator.openURL(urlString: url2)
navigator.nowAt(PrivateBrowserTab)
waitForValueContains(app.textFields["url"], value: "facebook")
navigator.goto(BrowserTabMenu)
waitforExistence(app.tables.cells["History"])
app.tables.cells["History"].tap()
waitforExistence(app.tables["History List"])
XCTAssertTrue(app.tables["History List"].staticTexts[url1Label].exists)
XCTAssertFalse(app.tables["History List"].staticTexts[url2Label].exists)
// Open one tab in private browsing and check the total number of tabs
let privateHistory = app.tables["History List"].cells.count - 2
XCTAssertEqual(privateHistory, 1, "History entries in private browsing do not match")
}
func testTabCountShowsOnlyNormalOrPrivateTabCount() {
// Open two tabs in normal browsing and check the number of tabs open
navigator.openNewURL(urlString: url1)
waitUntilPageLoad()
navigator.goto(TabTray)
navigator.goto(BrowserTab)
navigator.goto(TabTray)
waitforExistence(app.collectionViews.cells[url1Label])
let numTabs = app.collectionViews.cells.count
XCTAssertEqual(numTabs, 3, "The number of regular tabs is not correct")
// Open one tab in private browsing and check the total number of tabs
navigator.goto(PrivateTabTray)
navigator.goto(URLBarOpen)
waitUntilPageLoad()
navigator.openURL(urlString: url2)
waitUntilPageLoad()
navigator.nowAt(PrivateBrowserTab)
waitForValueContains(app.textFields["url"], value: "facebook")
navigator.goto(PrivateTabTray)
waitforExistence(app.collectionViews.cells[url2Label])
let numPrivTabs = app.collectionViews.cells.count
XCTAssertEqual(numPrivTabs, 1, "The number of private tabs is not correct")
// Go back to regular mode and check the total number of tabs
navigator.goto(TabTray)
waitforExistence(app.collectionViews.cells[url1Label])
waitforNoExistence(app.collectionViews.cells[url2Label])
let numRegularTabs = app.collectionViews.cells.count
XCTAssertEqual(numRegularTabs, 3, "The number of regular tabs is not correct")
}
func testClosePrivateTabsOptionClosesPrivateTabs() {
// Check that Close Private Tabs when closing the Private Browsing Button is off by default
navigator.goto(SettingsScreen)
let settingsTableView = app.tables["AppSettingsTableViewController.tableView"]
while settingsTableView.staticTexts["Close Private Tabs"].exists == false {
settingsTableView.swipeUp()
}
let closePrivateTabsSwitch = settingsTableView.switches["Close Private Tabs, When Leaving Private Browsing"]
XCTAssertFalse(closePrivateTabsSwitch.isSelected)
// Open a Private tab
navigator.goto(PrivateTabTray)
navigator.openURL(urlString: url1)
//Wait until the page loads
waitUntilPageLoad()
navigator.nowAt(PrivateBrowserTab)
navigator.goto(PrivateTabTray)
// Go back to regular browser
navigator.goto(TabTray)
// Go back to private browsing and check that the tab has not been closed
navigator.goto(PrivateTabTray)
waitforExistence(app.collectionViews.cells[url1Label])
let numPrivTabs = app.collectionViews.cells.count
XCTAssertEqual(numPrivTabs, 1, "The number of tabs is not correct, the private tab should not have been closed")
app.collectionViews.cells[url1Label].tap()
navigator.nowAt(PrivateBrowserTab)
// Now the enable the Close Private Tabs when closing the Private Browsing Button
navigator.goto(SettingsScreen)
closePrivateTabsSwitch.tap()
navigator.goto(PrivateBrowserTab)
// Go back to regular browsing and check that the private tab has been closed and that the initial Private Browsing message appears when going back to Private Browsing
navigator.goto(PrivateTabTray)
navigator.goto(TabTray)
navigator.goto(PrivateTabTray)
waitforNoExistence(app.collectionViews.cells[url1Label])
let numPrivTabsAfterClosing = app.collectionViews.cells.count
XCTAssertEqual(numPrivTabsAfterClosing, 0, "The number of tabs is not correct, the private tab should have been closed")
XCTAssertTrue(app.staticTexts["Private Browsing"].exists, "Private Browsing screen is not shown")
}
func testPrivateBrowserPanelView() {
// If no private tabs are open, there should be a initial screen with label Private Browsing
navigator.goto(PrivateTabTray)
XCTAssertTrue(app.staticTexts["Private Browsing"].exists, "Private Browsing screen is not shown")
let numPrivTabsFirstTime = app.collectionViews.cells.count
XCTAssertEqual(numPrivTabsFirstTime, 0, "The number of tabs is not correct, there should not be any private tab yet")
// If a private tab is open Private Browsing screen is not shown anymore
navigator.goto(PrivateBrowserTab)
//Wait until the page loads
waitUntilPageLoad()
navigator.goto(PrivateTabTray)
// Go to regular browsing
navigator.goto(TabTray)
// Go back to private brosing
navigator.goto(PrivateTabTray)
waitforNoExistence(app.staticTexts["Private Browsing"])
XCTAssertFalse(app.staticTexts["Private Browsing"].exists, "Private Browsing screen is shown")
let numPrivTabsOpen = app.collectionViews.cells.count
XCTAssertEqual(numPrivTabsOpen, 1, "The number of tabs is not correct, there should be one private tab")
}
}