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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* This tests ensures the urlbar reflects the correct value if a page load is
* stopped immediately after loading.
*/
"use strict";
const goodURL = "http://mochi.test:8888/";
const badURL = "http://mochi.test:8888/whatever.html";
add_task(async function () {
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, goodURL);
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
is(
gURLBar.value,
BrowserUIUtils.trimURL(goodURL),
"location bar reflects loaded page"
);
await typeAndSubmitAndStop(badURL);
is(
gURLBar.value,
BrowserUIUtils.trimURL(goodURL),
"location bar reflects loaded page after stop()"
);
gBrowser.removeCurrentTab();
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:blank");
is(gURLBar.value, "", "location bar is empty");
await typeAndSubmitAndStop(badURL);
is(
gURLBar.value,
BrowserUIUtils.trimURL(badURL),
"location bar reflects stopped page in an empty tab"
);
gBrowser.removeCurrentTab();
});
async function typeAndSubmitAndStop(url) {
await UrlbarTestUtils.promiseAutocompleteResultPopup({
window,
value: url,
fireInputEvent: true,
});
let docLoadPromise = BrowserTestUtils.waitForDocLoadAndStopIt(
url,
gBrowser.selectedBrowser
);
// When the load is stopped, tabbrowser calls gURLBar.setURI and then calls
// onStateChange on its progress listeners. So to properly wait until the
// urlbar value has been updated, add our own progress listener here.
let progressPromise = new Promise(resolve => {
let listener = {
onStateChange(browser, webProgress, request, stateFlags, status) {
if (
webProgress.isTopLevel &&
stateFlags & Ci.nsIWebProgressListener.STATE_STOP
) {
gBrowser.removeTabsProgressListener(listener);
resolve();
}
},
};
gBrowser.addTabsProgressListener(listener);
});
gURLBar.handleCommand();
await Promise.all([docLoadPromise, progressPromise]);
}
|