1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
5 * Helper function for encoding override tests, loads URL, runs check1,
6 * forces encoding detection, runs check2.
8 function runCharsetTest(url, check1, check2) {
9 waitForExplicitFinish();
11 BrowserTestUtils.openNewForegroundTab(gBrowser, url, true).then(afterOpen);
13 function afterOpen() {
14 BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(
18 SpecialPowers.spawn(gBrowser.selectedBrowser, [], check1).then(() => {
19 BrowserForceEncodingDetection();
23 function afterChangeCharset() {
24 SpecialPowers.spawn(gBrowser.selectedBrowser, [], check2).then(() => {
25 gBrowser.removeCurrentTab();
32 * Helper function for charset tests. It loads |url| in a new tab,
35 function runCharsetCheck(url, check) {
36 waitForExplicitFinish();
38 BrowserTestUtils.openNewForegroundTab(gBrowser, url, true).then(afterOpen);
40 function afterOpen() {
41 SpecialPowers.spawn(gBrowser.selectedBrowser, [], check).then(() => {
42 gBrowser.removeCurrentTab();
48 async function pushState(url, frameId) {
50 `Doing a pushState, expecting to load ${url} ${
51 frameId ? "in an iframe" : ""
54 let browser = gBrowser.selectedBrowser;
55 let bc = browser.browsingContext;
57 bc = await SpecialPowers.spawn(bc, [frameId], function (id) {
58 return content.document.getElementById(id).browsingContext;
61 let loaded = BrowserTestUtils.waitForLocationChange(gBrowser, url);
62 await SpecialPowers.spawn(bc, [url], function (url) {
63 content.history.pushState({}, "", url);
66 info(`Loaded ${url} ${frameId ? "in an iframe" : ""}`);
69 async function loadURI(url) {
70 info(`Doing a top-level loadURI, expecting to load ${url}`);
71 let browser = gBrowser.selectedBrowser;
72 let loaded = BrowserTestUtils.browserLoaded(browser, false, url);
73 BrowserTestUtils.startLoadingURIString(browser, url);
75 info(`Loaded ${url}`);
78 async function followLink(url, frameId) {
80 `Creating and following a link to ${url} ${frameId ? "in an iframe" : ""}`
82 let browser = gBrowser.selectedBrowser;
83 let bc = browser.browsingContext;
85 bc = await SpecialPowers.spawn(bc, [frameId], function (id) {
86 return content.document.getElementById(id).browsingContext;
89 let loaded = BrowserTestUtils.browserLoaded(browser, !!frameId, url);
90 await SpecialPowers.spawn(bc, [url], function (url) {
91 let a = content.document.createElement("a");
93 content.document.body.appendChild(a);
97 info(`Loaded ${url} ${frameId ? "in an iframe" : ""}`);
100 async function goForward(url, useFrame = false) {
102 `Clicking the forward button, expecting to load ${url} ${
103 useFrame ? "in an iframe" : ""
106 let loaded = BrowserTestUtils.waitForLocationChange(gBrowser, url);
107 let forwardButton = document.getElementById("forward-button");
108 forwardButton.click();
110 info(`Loaded ${url} ${useFrame ? "in an iframe" : ""}`);
113 async function goBack(url, useFrame = false) {
115 `Clicking the back button, expecting to load ${url} ${
116 useFrame ? "in an iframe" : ""
119 let loaded = BrowserTestUtils.waitForLocationChange(gBrowser, url);
120 let backButton = document.getElementById("back-button");
123 info(`Loaded ${url} ${useFrame ? "in an iframe" : ""}`);
126 function assertBackForwardState(canGoBack, canGoForward) {
127 let backButton = document.getElementById("back-button");
128 let forwardButton = document.getElementById("forward-button");
133 `${gBrowser.currentURI.spec}: back button is ${
134 canGoBack ? "not" : ""
138 forwardButton.disabled,
140 `${gBrowser.currentURI.spec}: forward button is ${
141 canGoForward ? "not" : ""
149 static GotoIndex = 2;
151 static ReplaceEntry = 4;
152 static async waitForHistory(history, event) {
153 return new Promise(resolve => {
155 OnHistoryNewEntry: () => {},
156 OnHistoryReload: () => {
159 OnHistoryGotoIndex: () => {},
160 OnHistoryPurge: () => {},
161 OnHistoryReplaceEntry: () => {},
163 QueryInterface: ChromeUtils.generateQI([
164 "nsISHistoryListener",
165 "nsISupportsWeakReference",
170 history.removeSHistoryListener(listener);
175 listener.OnHistoryNewEntry = finish;
178 listener.OnHistoryReload = () => {
184 listener.OnHistoryGotoIndex = finish;
187 listener.OnHistoryPurge = finish;
189 case this.ReplaceEntry:
190 listener.OnHistoryReplaceEntry = finish;
194 history.addSHistoryListener(listener);