This repository was archived by the owner on Feb 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathBrowsingHistoryTests.swift
173 lines (157 loc) · 8.98 KB
/
BrowsingHistoryTests.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
//
// BrowsingHistoryTests.swift
//
// Copyright © 2024 DuckDuckGo. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import XCTest
class BrowsingHistoryTests: UITestCase {
private var app: XCUIApplication!
private var historyMenuBarItem: XCUIElement!
private var clearAllHistoryMenuItem: XCUIElement!
private var clearAllHistoryAlertClearButton: XCUIElement!
private var fakeFireButton: XCUIElement!
private var addressBarTextField: XCUIElement!
private let lengthForRandomPageTitle = 8
override class func setUp() {
super.setUp()
UITests.firstRun()
}
override func setUpWithError() throws {
continueAfterFailure = false
app = XCUIApplication()
app.launchEnvironment["UITEST_MODE"] = "1"
historyMenuBarItem = app.menuBarItems["History"]
clearAllHistoryMenuItem = app.menuItems["HistoryMenu.clearAllHistory"]
clearAllHistoryAlertClearButton = app.buttons["ClearAllHistoryAndDataAlert.clearButton"]
fakeFireButton = app.buttons["FireViewController.fakeFireButton"]
addressBarTextField = app.windows.textFields["AddressBarViewController.addressBarTextField"]
app.launch()
app.typeKey("w", modifierFlags: [.command, .option, .shift]) // Enforce a single window
app.typeKey("n", modifierFlags: .command)
XCTAssertTrue(
historyMenuBarItem.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"History menu bar item didn't appear in a reasonable timeframe."
)
historyMenuBarItem.click()
XCTAssertTrue(
clearAllHistoryMenuItem.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"Clear all history item didn't appear in a reasonable timeframe."
)
clearAllHistoryMenuItem.click()
XCTAssertTrue(
clearAllHistoryAlertClearButton.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"Clear all history item didn't appear in a reasonable timeframe."
)
clearAllHistoryAlertClearButton.click() // Manually remove the history
XCTAssertTrue( // Let any ongoing fire animation or data processes complete
fakeFireButton.waitForNonExistence(timeout: UITests.Timeouts.fireAnimation),
"Fire animation didn't finish and cease existing in a reasonable timeframe."
)
}
func test_recentlyVisited_showsLastVisitedSite() throws {
let historyPageTitleExpectedToBeFirstInRecentlyVisited = UITests.randomPageTitle(length: lengthForRandomPageTitle)
let url = UITests.simpleServedPage(titled: historyPageTitleExpectedToBeFirstInRecentlyVisited)
let firstSiteInRecentlyVisitedSection = app.menuItems["HistoryMenu.recentlyVisitedMenuItem.0"]
XCTAssertTrue(
addressBarTextField.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"The address bar text field didn't become available in a reasonable timeframe."
)
addressBarTextField.typeURL(url)
XCTAssertTrue(
app.windows.webViews[historyPageTitleExpectedToBeFirstInRecentlyVisited]
.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"Visited site didn't load with the expected title in a reasonable timeframe."
)
XCTAssertTrue(
historyMenuBarItem.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"History menu bar item didn't appear in a reasonable timeframe."
)
historyMenuBarItem.click() // The visited sites identifiers will not be available until after the History menu has been accessed.
XCTAssertTrue(
firstSiteInRecentlyVisitedSection.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"The first site in the recently visited section didn't appear in a reasonable timeframe."
)
XCTAssertEqual(historyPageTitleExpectedToBeFirstInRecentlyVisited, firstSiteInRecentlyVisitedSection.title)
}
func test_history_showsVisitedSiteAfterClosingAndReopeningWindow() throws {
let historyPageTitleExpectedToBeFirstInTodayHistory = UITests.randomPageTitle(length: lengthForRandomPageTitle)
let url = UITests.simpleServedPage(titled: historyPageTitleExpectedToBeFirstInTodayHistory)
let firstSiteInHistory = app.menuItems["HistoryMenu.historyMenuItem.Today.0"]
XCTAssertTrue(
addressBarTextField.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"The address bar text field didn't become available in a reasonable timeframe."
)
addressBarTextField.typeURL(url)
XCTAssertTrue(
app.windows.webViews[historyPageTitleExpectedToBeFirstInTodayHistory].waitForExistence(timeout: UITests.Timeouts.elementExistence),
"Visited site didn't load with the expected title in a reasonable timeframe."
)
app.typeKey("w", modifierFlags: [.command, .option, .shift]) // Close all windows
app.typeKey("n", modifierFlags: .command) // New window
XCTAssertTrue(
historyMenuBarItem.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"History menu bar item didn't appear in a reasonable timeframe."
)
historyMenuBarItem.click() // The visited sites identifiers will not be available until after the History menu has been accessed.
XCTAssertTrue(
firstSiteInHistory.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"The first site in the recently visited section didn't appear in a reasonable timeframe."
)
XCTAssertEqual(historyPageTitleExpectedToBeFirstInTodayHistory, firstSiteInHistory.title)
}
func test_reopenLastClosedWindowMenuItem_canReopenTabsOfLastClosedWindow() throws {
let titleOfFirstTabWhichShouldRestore = UITests.randomPageTitle(length: lengthForRandomPageTitle)
let titleOfSecondTabWhichShouldRestore = UITests.randomPageTitle(length: lengthForRandomPageTitle)
let urlForFirstTab = UITests.simpleServedPage(titled: titleOfFirstTabWhichShouldRestore)
let urlForSecondTab = UITests.simpleServedPage(titled: titleOfSecondTabWhichShouldRestore)
XCTAssertTrue(
addressBarTextField.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"The address bar text field didn't become available in a reasonable timeframe."
)
addressBarTextField.typeURL(urlForFirstTab)
XCTAssertTrue(
app.windows.webViews[titleOfFirstTabWhichShouldRestore].waitForExistence(timeout: UITests.Timeouts.elementExistence),
"Visited site didn't load with the expected title in a reasonable timeframe."
)
app.typeKey("t", modifierFlags: .command)
addressBarTextField.typeURL(urlForSecondTab)
XCTAssertTrue(
app.windows.webViews[titleOfSecondTabWhichShouldRestore].waitForExistence(timeout: UITests.Timeouts.elementExistence),
"Visited site didn't load with the expected title in a reasonable timeframe."
)
app.typeKey("w", modifierFlags: [.command, .option, .shift]) // Close all windows
app.typeKey("n", modifierFlags: .command) // New window
XCTAssertTrue(
historyMenuBarItem.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"History menu bar item didn't appear in a reasonable timeframe."
)
historyMenuBarItem.click() // The visited sites identifiers will not be available until after the History menu has been accessed.
let reopenLastClosedWindowMenuItem = app.menuItems["HistoryMenu.reopenLastClosedWindow"]
XCTAssertTrue(
reopenLastClosedWindowMenuItem.waitForExistence(timeout: UITests.Timeouts.elementExistence),
"The \"Reopen Last Closed Window\" menu item didn't appear in a reasonable timeframe."
)
reopenLastClosedWindowMenuItem.click()
XCTAssertTrue(
app.windows.webViews[titleOfFirstTabWhichShouldRestore].waitForExistence(timeout: UITests.Timeouts.elementExistence),
"Restored visited tab 1 wasn't available with the expected title in a reasonable timeframe."
)
app.typeKey("w", modifierFlags: [.command])
XCTAssertTrue(
app.windows.webViews[titleOfSecondTabWhichShouldRestore].waitForExistence(timeout: UITests.Timeouts.elementExistence),
"Restored visited tab 2 wasn't available with the expected title in a reasonable timeframe."
)
}
}