forked from qodo-benchmark/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDomainAutocompleteTests.swift
More file actions
226 lines (196 loc) · 9.18 KB
/
DomainAutocompleteTests.swift
File metadata and controls
226 lines (196 loc) · 9.18 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
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
// 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 Common
import XCTest
let website = [
"url": "mozilla.org",
"value": "mozilla.org",
"subDomain": "https://www.mozilla.org/en-US/firefox/products"
]
let websiteExample = [
"url": "www.example.com",
"value": "www.example.com"
]
class DomainAutocompleteTests: BaseTestCase {
let testWithDB = [
"test1Autocomplete",
"test3AutocompleteDeletingChars",
"test5NoMatches",
"testMixedCaseAutocompletion",
"testDeletingCharsUpdateTheResults"
]
// This DB contains 3 entries mozilla.com/github.com/git.es
let historyDB = "browserAutocomplete-places.db"
override func setUp() async throws {
// Test name looks like: "[Class testFunc]", parse out the function name
let parts = name.replacingOccurrences(of: "]", with: "").split(separator: " ")
let key = String(parts[1])
if testWithDB.contains(key) {
// for the current test name, add the db fixture used
launchArguments = [LaunchArguments.SkipIntro,
LaunchArguments.SkipWhatsNew,
LaunchArguments.SkipETPCoverSheet,
LaunchArguments.LoadDatabasePrefix + historyDB,
LaunchArguments.SkipContextualHints,
LaunchArguments.DisableAnimations]
}
try await super.setUp()
}
// https://mozilla.testrail.io/index.php?/cases/view/2334558
func test1Autocomplete() {
// Basic autocompletion cases
// The autocomplete does not display the history item from the DB. Workaround is to manually visit "mozilla.org".
navigator.openURL("mozilla.org")
waitUntilPageLoad()
navigator.nowAt(BrowserTab)
if isTablet {
navigator.performAction(Action.AcceptRemovingAllTabs)
} else {
navigator.performAction(Action.CloseTabFromTabTrayLongPressMenu)
}
navigator.goto(URLBarOpen)
urlBarAddress.typeText("moz")
mozWaitForValueContains(urlBarAddress, value: website["value"]!)
let value = urlBarAddress.value
XCTAssertEqual(value as? String, website["value"]!, "Wrong autocompletion")
// Enter the complete website and check that there is not more text added, just what user typed
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText(website["value"]!)
mozWaitForValueContains(urlBarAddress, value: website["value"]!)
let value2 = urlBarAddress.value
XCTAssertEqual(value2 as? String, website["value"]!, "Wrong autocompletion")
}
// Test that deleting characters works correctly with autocomplete
// https://mozilla.testrail.io/index.php?/cases/view/2334647
func test3AutocompleteDeletingChars() {
// The autocomplete does not display the history item from the DB. Workaround is to manually visit "mozilla.org".
navigator.openURL("mozilla.org")
waitUntilPageLoad()
navigator.goto(TabTray)
navigator.goto(CloseTabMenu)
navigator.performAction(Action.AcceptRemovingAllTabs)
urlBarAddress.waitAndTap()
mozWaitForElementToExist(urlBarAddress)
urlBarAddress.typeText("moz")
// First delete the autocompleted part
urlBarAddress.typeText("\u{0008}")
// Then remove an extra char and check that the autocompletion stops working
urlBarAddress.typeText("\u{0008}")
mozWaitForValueContains(urlBarAddress, value: "mo")
// Then write another letter and the autocompletion works again
urlBarAddress.typeText("z")
mozWaitForValueContains(urlBarAddress, value: "moz")
if #available(iOS 16, *) {
let value = urlBarAddress.value
XCTAssertEqual(value as? String, website["value"]!, "Wrong autocompletion")
}
}
// Delete the entire string and verify that the home panels are shown again.
// https://mozilla.testrail.io/index.php?/cases/view/2334648
func test6DeleteEntireString() {
navigator.goto(URLBarOpen)
urlBarAddress.typeText("www.moz")
app.buttons["Clear text"].waitAndTap()
// Check that the address field is empty and that the home panels are shown
let value = urlBarAddress.value
XCTAssertEqual(value as? String, "Search or enter address", "The url has not been removed correctly")
mozWaitForElementToExist(app.links[AccessibilityIdentifiers.FirefoxHomepage.TopSites.itemCell])
}
// Ensure that the scheme is included in the autocompletion.
// https://mozilla.testrail.io/index.php?/cases/view/2334649
func test4EnsureSchemeIncludedAutocompletion() {
navigator.openURL(websiteExample["url"]!)
waitUntilPageLoad()
navigator.nowAt(BrowserTab)
navigator.goto(URLBarOpen)
urlBarAddress.typeText("ex")
if #available(iOS 16, *) {
mozWaitForValueContains(urlBarAddress, value: "example.com")
let value = urlBarAddress.value
XCTAssertEqual(value as? String, "example.com", "Wrong autocompletion")
}
}
// Non-matches.
// https://mozilla.testrail.io/index.php?/cases/view/2334650
func test5NoMatches() {
navigator.openURL("twitter.com/login")
waitUntilPageLoad()
navigator.nowAt(BrowserTab)
navigator.goto(URLBarOpen)
urlBarAddress.typeText("baz")
let value = urlBarAddress.value
// Check there is not more text added, just what user typed
XCTAssertEqual(value as? String, "baz", "Wrong autocompletion")
// Ensure we don't match against TLDs.
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText(".com")
let value2 = urlBarAddress.value
// Check there is not more text added, just what user typed
XCTAssertEqual(value2 as? String, ".com", "Wrong autocompletion")
// Ensure we don't match other characters ie: ., :, /
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText(".")
let value3 = urlBarAddress.value
XCTAssertEqual(value3 as? String, ".", "Wrong autocompletion")
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText(":")
let value4 = urlBarAddress.value
XCTAssertEqual(value4 as? String, ":", "Wrong autocompletion")
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText("/")
let value5 = urlBarAddress.value
XCTAssertEqual(value5 as? String, "/", "Wrong autocompletion")
// Ensure we don't match strings that don't start a word.
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText("tter")
let value6 = urlBarAddress.value
XCTAssertEqual(value6 as? String, "tter", "Wrong autocompletion")
// Ensure we don't match words outside of the domain
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText("login")
let value7 = urlBarAddress.value
XCTAssertEqual(value7 as? String, "login", "Wrong autocompletion")
}
// Test default domains.
// https://mozilla.testrail.io/index.php?/cases/view/2334651
func test2DefaultDomains() {
navigator.goto(URLBarOpen)
urlBarAddress.typeText("a")
mozWaitForValueContains(urlBarAddress, value: "a")
let value = urlBarAddress.value
XCTAssertEqual(value as? String, "a", "Wrong autocompletion")
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText("an")
mozWaitForValueContains(urlBarAddress, value: "an")
let value2 = urlBarAddress.value
XCTAssertEqual(value2 as? String, "an", "Wrong autocompletion")
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText("anc")
mozWaitForValueContains(urlBarAddress, value: "anc")
let value3 = urlBarAddress.value
XCTAssertEqual(value3 as? String, "anc", "Wrong autocompletion")
}
// Test mixed case autocompletion.
// https://mozilla.testrail.io/index.php?/cases/view/2334653
func testMixedCaseAutocompletion() {
navigator.goto(URLBarOpen)
urlBarAddress.typeText("MoZ")
mozWaitForValueContains(urlBarAddress, value: ".org")
let value = urlBarAddress.value
XCTAssertEqual(value as? String, "MoZilla.org", "Wrong autocompletion")
// Test that leading spaces still show suggestions.
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText(" moz")
mozWaitForValueContains(urlBarAddress, value: ".org")
let value2 = urlBarAddress.value
XCTAssertEqual(value2 as? String, " mozilla.org", "Wrong autocompletion")
// Test that trailing spaces do *not* show suggestions.
app.buttons["Clear text"].waitAndTap()
urlBarAddress.typeText(" moz ")
mozWaitForValueContains(urlBarAddress, value: "moz")
let value3 = urlBarAddress.value
// No autocompletion, just what user typed
XCTAssertEqual(value3 as? String, " moz ", "Wrong autocompletion")
}
}