File: tst_AddressBar.qml

package info (click to toggle)
morph-browser 1.1.2%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,424 kB
  • sloc: cpp: 12,201; javascript: 2,042; xml: 92; makefile: 43
file content (370 lines) | stat: -rw-r--r-- 14,191 bytes parent folder | download
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/*
 * Copyright 2013-2015 Canonical Ltd.
 *
 * This file is part of webbrowser-app.
 *
 * webbrowser-app is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * webbrowser-app is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import QtTest 1.0
import "../../../src/app/webbrowser"

Item {
    width: 300
    height: 60

    FocusScope {
        anchors.fill: parent

        AddressBar {
            id: addressBar

            anchors {
                top: parent.top
                left: parent.left
                right: parent.right
            }
            height: parent.height / 2

            searchUrl: "http://www.ubuntu.com/search?q={searchTerms}"

            editing: activeFocus
            canSimplifyText: true

            findController: QtObject {
                property int current
                property int count
            }

            searchTextTimerInterval: 50
        }

        // only exists to steal focus from the address bar
        TextInput {
            id: textInput

            anchors {
                bottom: parent.bottom
                left: parent.left
                right: parent.right
            }
            height: parent.height / 2
        }
    }

    SignalSpy {
        id: validatedSpy
        target: addressBar
        signalName: "validated"
    }

    WebbrowserTestCase {
        name: "AddressBar"
        when: windowShown

        function verifyAddressBarText(text) {
            tryCompare(addressBar, "text", text)
        }

        function typeStringAndVerify(text) {
            typeString(text)
            verifyAddressBarText(text)
        }

        function init() {
            addressBar.actualUrl = ""
            validatedSpy.clear()
            // Ensure the address bar has active focus
            clickItem(addressBar)
            verify(addressBar.activeFocus)
            // Clear it
            var clearButton = findChild(addressBar, "clear_button")
            verify(clearButton != null)
            clickItem(clearButton)
            compare(addressBar.text, "")
            // Ensure it still has active focus
            verify(addressBar.activeFocus)
        }

        function test_validUrlShouldNotBeRewritten_data() {
            return [
                {url: "file:///usr/share/doc/ubuntu-online-tour/index.html"},
                {url: "http://ubuntu.com"},
                {url: "https://ubports.com"},
                {url: "ftp://ubuntu.com"},
                {url: "about:blank"},
                {url: "data:,A brief note"},
                {url: "http://com.ubports"}
            ]
        }

        function test_validUrlShouldNotBeRewritten(data) {
            typeStringAndVerify(data.url)
            keyClick(Qt.Key_Return)
            validatedSpy.wait()
            compare(addressBar.requestedUrl, data.url)
        }

        function test_urlWithoutSchemeShouldBeRewritten_data() {
            return [
                {text: "ubuntu.com", requestedUrl: "http://ubuntu.com"},
                {text: "192.168.1.1", requestedUrl: "http://192.168.1.1"},
                {text: "192.168.1.1:8000", requestedUrl: "http://192.168.1.1:8000"},
                {text: "192.168.1.1:8000/dummy.html", requestedUrl: "http://192.168.1.1:8000/dummy.html"},
                {text: "/usr/share/doc/ubuntu-online-tour/index.html", requestedUrl: "file:///usr/share/doc/ubuntu-online-tour/index.html"},
            ]
        }

        function test_urlWithoutSchemeShouldBeRewritten(data) {
            typeStringAndVerify(data.text)
            keyClick(Qt.Key_Return)
            validatedSpy.wait()
            compare(addressBar.requestedUrl, data.requestedUrl)
        }

        function test_leadingAndTrailingWhitespacesShouldBeTrimmed_data() {
            return [
                {text: "   http://ubuntu.com", requestedUrl: "http://ubuntu.com"},
                {text: "http://ubuntu.com  ", requestedUrl: "http://ubuntu.com"},
                {text: "  http://ubuntu.com   ", requestedUrl: "http://ubuntu.com"},
            ]
        }

        function test_leadingAndTrailingWhitespacesShouldBeTrimmed(data) {
            typeStringAndVerify(data.text)
            keyClick(Qt.Key_Return)
            validatedSpy.wait()
            compare(addressBar.requestedUrl, data.requestedUrl)
        }

        function test_searchQueryShouldBeRewritten_data() {
            return [
                {text: "lorem ipsum dolor sit amet", start: "http://www.ubuntu.com", query: "lorem+ipsum+dolor+sit+amet"},
                {text: "ubuntu", start: "http://www.ubuntu.com", query: "ubuntu"},
            ]
        }

        function test_searchQueryShouldBeRewritten(data) {
            typeStringAndVerify(data.text)
            keyClick(Qt.Key_Return)
            validatedSpy.wait()
            compare(addressBar.requestedUrl.toString().indexOf(data.start), 0)
            verify(addressBar.requestedUrl.toString().indexOf("q=" + data.query) > 0)
        }

        function test_htmlEntitiesShouldBeEscapedInSearchQueries_data() {
            return [
                {text: "tom & jerry", escaped: "tom+%26+jerry"},
                {text: "a+ rating", escaped: "a%2B+rating"},
                {text: "\"kung fu\"", escaped: "%22kung+fu%22"},
                {text: "surfin' usa", escaped: "surfin'+usa"},
                {text: "to be or not to be?", escaped: "to+be+or+not+to+be%3F"},
                {text: "c++ cout", escaped: "c%2B%2B+cout"},
            ]
        }

        function test_htmlEntitiesShouldBeEscapedInSearchQueries(data) {
            typeStringAndVerify(data.text)
            keyClick(Qt.Key_Return)
            validatedSpy.wait()
            verify(addressBar.requestedUrl.toString().indexOf("q=" + data.escaped) > 0)
        }

        function test_uppercaseDomainsShouldBeRewritten_data() {
            return [
                {text: "WWW.UBUNTU.COM", requestedUrl: "http://www.ubuntu.com"},
                {text: "EN.WIKIPEDIA.ORG/wiki/Ubuntu", requestedUrl: "http://en.wikipedia.org/wiki/Ubuntu"},
                {text: "EN.WIKIPEDIA.ORG/wiki/UBUNTU", requestedUrl: "http://en.wikipedia.org/wiki/UBUNTU"},
            ]
        }

        function test_uppercaseDomainsShouldBeRewritten(data) {
            typeStringAndVerify(data.text)
            keyClick(Qt.Key_Return)
            validatedSpy.wait()
            compare(addressBar.requestedUrl, data.requestedUrl)
        }

        function test_uppercaseSchemeShouldBeRewritten_data() {
            return [
                {text: "HTTP://WWW.UBUNTU.COM", requestedUrl: "http://www.ubuntu.com"},
                {text: "HTTP://www.ubuntu.com", requestedUrl: "http://www.ubuntu.com"},
                {text: "HTTPS://www.ubuntu.com", requestedUrl: "https://www.ubuntu.com"},
                {text: "FILE:///usr/share/doc/ubuntu-online-tour/index.html", requestedUrl: "file:///usr/share/doc/ubuntu-online-tour/index.html"},
                {text: "FTP://ubuntu.com", requestedUrl: "ftp://ubuntu.com"},
                {text: "ABOUT:BLANK", requestedUrl: "about:BLANK"},
                {text: "DATA:,A brief note", requestedUrl: "data:,A brief note"},
                {text: "HTTP://com.UBPORTS", requestedUrl: "http://com.ubports"}
            ]
        }

        function test_uppercaseSchemeShouldBeRewritten(data) {
            typeStringAndVerify(data.text)
            keyClick(Qt.Key_Return)
            validatedSpy.wait()
            compare(addressBar.requestedUrl, data.requestedUrl)
        }

        function test_urlShouldBeSimplifiedWhenUnfocused_data() {
            return [
                {input: "http://www.ubuntu.com",
                 simplified: "ubuntu.com",
                 actualUrl: "http://www.ubuntu.com"},
                {input: "http://www.ubuntu.com/",
                 simplified: "ubuntu.com",
                 actualUrl: "http://www.ubuntu.com/"},
                {input: "http://www.ubuntu.com:80",
                 simplified: "ubuntu.com",
                 actualUrl: "http://www.ubuntu.com:80"},
                {input: "http://www.ubuntuwww.com",
                 simplified: "ubuntuwww.com",
                 actualUrl: "http://www.ubuntuwww.com"},
                {input: "http://www.com",
                 simplified: "www.com",
                 actualUrl: "http://www.com"},
                {input: "http://user@www.ubuntu.com",
                 simplified: "ubuntu.com",
                 actualUrl: "http://user@www.ubuntu.com"},
                {input: "http://user:password@www.ubuntu.com",
                 simplified: "ubuntu.com",
                 actualUrl: "http://user:password@www.ubuntu.com"},
                {input: "http://user:password@www.ubuntu.com:80",
                 simplified: "ubuntu.com",
                 actualUrl: "http://user:password@www.ubuntu.com:80"},
                {input: "file:///home/phablet/",
                 simplified: "file:///home/phablet/",
                 actualUrl: "file:///home/phablet/"},
                {input: "http://en.wikipedia.org/wiki/Ubuntu",
                 simplified: "en.wikipedia.org",
                 actualUrl: "http://en.wikipedia.org/wiki/Ubuntu"},
                {input: "en.wikipedia.org",
                 simplified: "en.wikipedia.org",
                 actualUrl: "http://en.wikipedia.org"},
                {input: "en.wikipedia.org/wiki/Foo",
                 simplified: "en.wikipedia.org",
                 actualUrl: "http://en.wikipedia.org/wiki/Foo"},
                {input: "http://com.ubports",
                 simplified: "com.ubports",
                 actualUrl: "http://com.ubports"},
            ]
        }

        function test_urlShouldBeSimplifiedWhenUnfocused(data) {
            typeStringAndVerify(data.input)
            keyClick(Qt.Key_Return)
            validatedSpy.wait()
            addressBar.actualUrl = addressBar.requestedUrl
            compare(addressBar.text, data.input)
            clickItem(textInput)
            compare(addressBar.text, data.simplified)
            clickItem(addressBar)
            compare(addressBar.text, data.actualUrl)
        }

        function test_actionButtonShouldBeDisabledWhenEmpty() {
            verify(!addressBar.__actionButton.enabled)
            keyClick(Qt.Key_U)
            wait(500)
            verify(addressBar.text != "")
            verify(addressBar.__actionButton.enabled)
        }

        function test_clickingWhenUnfocusedShouldSelectAll() {
            var url = "http://example.org/"
            typeStringAndVerify(url)
            addressBar.actualUrl = url
            clickItem(textInput)
            verify(!addressBar.activeFocus)
            clickItem(addressBar)
            compare(addressBar.__textField.selectedText, url)
        }

        function test_clickingWhenFocusedShouldDeselectText() {
            var url = "http://example.org/"
            typeStringAndVerify(url)
            addressBar.actualUrl = url
            clickItem(textInput)
            verify(!addressBar.activeFocus)
            clickItem(addressBar)
            compare(addressBar.__textField.selectedText, url)
            clickItem(addressBar)
            compare(addressBar.__textField.selectedText, "")
            verify(addressBar.__textField.cursorPosition > 0)
        }

        function test_clickingActionButtonWhenUnfocusedShouldNotSelectAll() {
            var url = "http://example.org/"
            typeStringAndVerify(url)
            clickItem(textInput)
            verify(!addressBar.activeFocus)
            clickItem(addressBar.__actionButton)
            compare(addressBar.__textField.selectedText, "")
        }

        function test_shouldNotAllowBookmarkingWhenEmpty() {
            // focused
            var toggle = addressBar.__bookmarkToggle
            verify(!toggle.visible)
            // and unfocused
            clickItem(textInput)
            verify(!toggle.visible)
        }

        function test_shouldNotAllowBookmarkingWhileFocused() {
            addressBar.actualUrl = "http://example.org"
            var toggle = addressBar.__bookmarkToggle
            verify(!toggle.visible)
            clickItem(textInput)
            verify(toggle.visible)
        }

        function test_togglingIndicatorShouldBookmark() {
            skip("Skipped due to what seems to be a bug in the UITK: https://launchpad.net/bugs/1483279")
            addressBar.actualUrl = "http://example.org"
            clickItem(textInput)
            verify(!addressBar.bookmarked)
            var toggle = addressBar.__bookmarkToggle
            clickItem(toggle)
            verify(addressBar.bookmarked)
            clickItem(toggle)
            verify(!addressBar.bookmarked)
        }

        function test_unfocusingWhileEditingShouldResetUrl() {
            var host = "example.org"
            var url = "http://" + host + "/"
            typeStringAndVerify(url)
            addressBar.actualUrl = url
            var clearButton = findChild(addressBar, "clear_button")
            verify(clearButton != null)
            clickItem(clearButton)
            verifyAddressBarText("")
            clickItem(textInput)
            verifyAddressBarText(host)
            clickItem(addressBar)
            verifyAddressBarText(url)
        }

        function test_exitingFindInPageRestoresUrl() {
            var host = "example.org"
            addressBar.actualUrl = "http://" + host + "/"
            addressBar.findInPageMode = true
            verify(addressBar.activeFocus)
            compare(addressBar.text, "")
            typeStringAndVerify("hello")
            addressBar.findInPageMode = false
            verifyAddressBarText(host)
        }
    }
}