mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 936271 - Add tests to ensure we ignore dynamic history entries r=yoric
--HG-- rename : browser/components/sessionstore/test/browser_597315_a.html => browser/components/sessionstore/test/browser_frame_history_a.html rename : browser/components/sessionstore/test/browser_597315_c.html => browser/components/sessionstore/test/browser_frame_history_c.html rename : browser/components/sessionstore/test/browser_597315_c1.html => browser/components/sessionstore/test/browser_frame_history_c1.html rename : browser/components/sessionstore/test/browser_597315_c2.html => browser/components/sessionstore/test/browser_frame_history_c2.html
This commit is contained in:
parent
00ebd57789
commit
54128ba531
@ -16,6 +16,14 @@ support-files =
|
||||
browser_formdata_xpath_sample.html
|
||||
browser_frametree_sample.html
|
||||
browser_frametree_sample_frameset.html
|
||||
browser_frame_history_index.html
|
||||
browser_frame_history_index2.html
|
||||
browser_frame_history_index_blank.html
|
||||
browser_frame_history_a.html
|
||||
browser_frame_history_b.html
|
||||
browser_frame_history_c.html
|
||||
browser_frame_history_c1.html
|
||||
browser_frame_history_c2.html
|
||||
browser_form_restore_events_sample.html
|
||||
browser_formdata_format_sample.html
|
||||
browser_pageStyle_sample.html
|
||||
@ -33,12 +41,6 @@ support-files =
|
||||
browser_463206_sample.html
|
||||
browser_466937_sample.html
|
||||
browser_485482_sample.html
|
||||
browser_597315_index.html
|
||||
browser_597315_a.html
|
||||
browser_597315_b.html
|
||||
browser_597315_c.html
|
||||
browser_597315_c1.html
|
||||
browser_597315_c2.html
|
||||
browser_662743_sample.html
|
||||
browser_739531_sample.html
|
||||
browser_911547_sample.html
|
||||
@ -58,11 +60,13 @@ support-files =
|
||||
[browser_broadcast.js]
|
||||
[browser_capabilities.js]
|
||||
[browser_dying_cache.js]
|
||||
[browser_dynamic_frames.js]
|
||||
[browser_form_restore_events.js]
|
||||
[browser_formdata.js]
|
||||
[browser_formdata_format.js]
|
||||
[browser_formdata_xpath.js]
|
||||
[browser_frametree.js]
|
||||
[browser_frame_history.js]
|
||||
[browser_global_store.js]
|
||||
[browser_label_and_icon.js]
|
||||
[browser_merge_closed_tabs.js]
|
||||
@ -141,7 +145,6 @@ skip-if = true
|
||||
[browser_590268.js]
|
||||
[browser_590563.js]
|
||||
[browser_595601-restore_hidden.js]
|
||||
[browser_597315.js]
|
||||
[browser_599909.js]
|
||||
[browser_600545.js]
|
||||
[browser_601955.js]
|
||||
|
@ -1,58 +0,0 @@
|
||||
/* 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/. */
|
||||
|
||||
function test() {
|
||||
/** Test for Bug 597315 - Frameset history does not work properly when restoring a tab **/
|
||||
waitForExplicitFinish();
|
||||
|
||||
let testURL = getRootDirectory(gTestPath) + "browser_597315_index.html";
|
||||
let tab = gBrowser.addTab(testURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
waitForLoadsInBrowser(tab.linkedBrowser, 4, function() {
|
||||
let browser_b = tab.linkedBrowser.contentDocument.getElementsByTagName("frame")[1];
|
||||
let document_b = browser_b.contentDocument;
|
||||
let links = document_b.getElementsByTagName("a");
|
||||
|
||||
// We're going to click on the first link, so listen for another load event
|
||||
waitForLoadsInBrowser(tab.linkedBrowser, 1, function() {
|
||||
waitForLoadsInBrowser(tab.linkedBrowser, 1, function() {
|
||||
|
||||
gBrowser.removeTab(tab);
|
||||
// wait for 4 loads again...
|
||||
let newTab = ss.undoCloseTab(window, 0);
|
||||
|
||||
waitForLoadsInBrowser(newTab.linkedBrowser, 4, function() {
|
||||
gBrowser.goBack();
|
||||
waitForLoadsInBrowser(newTab.linkedBrowser, 1, function() {
|
||||
|
||||
let expectedURLEnds = ["a.html", "b.html", "c1.html"];
|
||||
let frames = newTab.linkedBrowser.contentDocument.getElementsByTagName("frame");
|
||||
for (let i = 0; i < frames.length; i++) {
|
||||
is(frames[i].contentDocument.location,
|
||||
getRootDirectory(gTestPath) + "browser_597315_" + expectedURLEnds[i],
|
||||
"frame " + i + " has the right url");
|
||||
}
|
||||
gBrowser.removeTab(newTab);
|
||||
executeSoon(finish);
|
||||
});
|
||||
});
|
||||
});
|
||||
EventUtils.sendMouseEvent({type:"click"}, links[1], browser_b.contentWindow);
|
||||
});
|
||||
EventUtils.sendMouseEvent({type:"click"}, links[0], browser_b.contentWindow);
|
||||
});
|
||||
}
|
||||
|
||||
// helper function
|
||||
function waitForLoadsInBrowser(aBrowser, aLoadCount, aCallback) {
|
||||
let loadCount = 0;
|
||||
aBrowser.addEventListener("load", function(aEvent) {
|
||||
if (++loadCount < aLoadCount)
|
||||
return;
|
||||
|
||||
aBrowser.removeEventListener("load", arguments.callee, true);
|
||||
aCallback();
|
||||
}, true);
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
I'm B!<br/>
|
||||
<a target="c" href="browser_597315_c1.html">click me first</a><br/>
|
||||
<a target="c" href="browser_597315_c2.html">then click me</a><br/>
|
||||
Close this tab.<br/>
|
||||
Restore this tab.<br/>
|
||||
Click back.<br/>
|
||||
</body>
|
||||
</html>
|
@ -1,10 +0,0 @@
|
||||
<html>
|
||||
<frameset cols="20%,80%">
|
||||
<frameset rows="30%,70%">
|
||||
<frame src="browser_597315_a.html"/>
|
||||
<frame src="browser_597315_b.html"/>
|
||||
</frameset>
|
||||
<frame src="browser_597315_c.html" name="c"/>
|
||||
</frameset>
|
||||
</html>
|
||||
|
@ -178,6 +178,10 @@ function testOnWindow(aIsPrivate, aCallback) {
|
||||
}
|
||||
|
||||
function waitForTabLoad(aWin, aURL, aCallback) {
|
||||
whenBrowserLoaded(aWin.gBrowser.selectedBrowser, aCallback);
|
||||
aWin.gBrowser.selectedBrowser.loadURI(aURL);
|
||||
let browser = aWin.gBrowser.selectedBrowser;
|
||||
whenBrowserLoaded(browser, function () {
|
||||
SyncHandlers.get(browser).flush();
|
||||
executeSoon(aCallback);
|
||||
});
|
||||
browser.loadURI(aURL);
|
||||
}
|
||||
|
@ -0,0 +1,95 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Ensure that static frames of framesets are serialized but dynamically
|
||||
* inserted iframes are ignored.
|
||||
*/
|
||||
add_task(function () {
|
||||
// This URL has the following frames:
|
||||
// + about:mozilla (static)
|
||||
// + about:robots (static)
|
||||
// + about:rights (dynamic iframe)
|
||||
const URL = "data:text/html;charset=utf-8," +
|
||||
"<frameset cols=50%25,50%25><frame src=about%3Amozilla>" +
|
||||
"<frame src=about%3Arobots></frameset>" +
|
||||
"<script>var i=document.createElement('iframe');" +
|
||||
"i.setAttribute('src', 'about%3Arights');" +
|
||||
"document.body.appendChild(i);</script>";
|
||||
|
||||
// Add a new tab with two "static" and one "dynamic" frame.
|
||||
let tab = gBrowser.addTab(URL);
|
||||
let browser = tab.linkedBrowser;
|
||||
yield promiseBrowserLoaded(browser);
|
||||
|
||||
SyncHandlers.get(browser).flush();
|
||||
let {entries} = JSON.parse(ss.getTabState(tab));
|
||||
|
||||
// Check URLs.
|
||||
ok(entries[0].url.startsWith("data:text/html"), "correct root url");
|
||||
is(entries[0].children[0].url, "about:mozilla", "correct url for 1st frame");
|
||||
is(entries[0].children[1].url, "about:robots", "correct url for 2nd frame");
|
||||
|
||||
// Check the number of children.
|
||||
is(entries.length, 1, "there is one root entry ...");
|
||||
is(entries[0].children.length, 2, "... with two child entries");
|
||||
|
||||
// Cleanup.
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
/**
|
||||
* Ensure that iframes created by the network parser are serialized but
|
||||
* dynamically inserted iframes are ignored. Navigating a subframe should
|
||||
* create a second root entry that doesn't contain any dynamic children either.
|
||||
*/
|
||||
add_task(function () {
|
||||
// This URL has the following frames:
|
||||
// + about:mozilla (static iframe)
|
||||
// + about:rights (dynamic iframe)
|
||||
const URL = "data:text/html;charset=utf-8," +
|
||||
"<iframe name=t src=about%3Amozilla></iframe>" +
|
||||
"<a id=lnk href=about%3Arobots target=t>clickme</a>" +
|
||||
"<script>var i=document.createElement('iframe');" +
|
||||
"i.setAttribute('src', 'about%3Arights');" +
|
||||
"document.body.appendChild(i);</script>";
|
||||
|
||||
// Add a new tab with one "static" and one "dynamic" frame.
|
||||
let tab = gBrowser.addTab(URL);
|
||||
let browser = tab.linkedBrowser;
|
||||
yield promiseBrowserLoaded(browser);
|
||||
|
||||
SyncHandlers.get(browser).flush();
|
||||
let {entries} = JSON.parse(ss.getTabState(tab));
|
||||
|
||||
// Check URLs.
|
||||
ok(entries[0].url.startsWith("data:text/html"), "correct root url");
|
||||
is(entries[0].children[0].url, "about:mozilla", "correct url for static frame");
|
||||
|
||||
// Check the number of children.
|
||||
is(entries.length, 1, "there is one root entry ...");
|
||||
is(entries[0].children.length, 1, "... with a single child entry");
|
||||
|
||||
// Navigate the subframe.
|
||||
browser.messageManager.sendAsyncMessage("ss-test:click", {id: "lnk"});
|
||||
yield promiseBrowserLoaded(browser, false /* don't ignore subframes */);
|
||||
|
||||
SyncHandlers.get(browser).flush();
|
||||
let {entries} = JSON.parse(ss.getTabState(tab));
|
||||
|
||||
// Check URLs.
|
||||
ok(entries[0].url.startsWith("data:text/html"), "correct 1st root url");
|
||||
ok(entries[1].url.startsWith("data:text/html"), "correct 2nd root url");
|
||||
is(entries[0].children[0].url, "about:mozilla", "correct url for 1st static frame");
|
||||
is(entries[1].children[0].url, "about:robots", "correct url for 2ns static frame");
|
||||
|
||||
// Check the number of children.
|
||||
is(entries.length, 2, "there are two root entries ...");
|
||||
is(entries[0].children.length, 1, "... with a single child entry ...");
|
||||
is(entries[1].children.length, 1, "... each");
|
||||
|
||||
// Cleanup.
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
170
browser/components/sessionstore/test/browser_frame_history.js
Normal file
170
browser/components/sessionstore/test/browser_frame_history.js
Normal file
@ -0,0 +1,170 @@
|
||||
/* 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/. */
|
||||
|
||||
/**
|
||||
Ensure that frameset history works properly when restoring a tab,
|
||||
provided that the frameset is static.
|
||||
*/
|
||||
|
||||
// Loading a toplevel frameset
|
||||
add_task(function() {
|
||||
let testURL = getRootDirectory(gTestPath) + "browser_frame_history_index.html";
|
||||
let tab = gBrowser.addTab(testURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
info("Opening a page with three frames, 4 loads should take place");
|
||||
yield waitForLoadsInBrowser(tab.linkedBrowser, 4);
|
||||
|
||||
let browser_b = tab.linkedBrowser.contentDocument.getElementsByTagName("frame")[1];
|
||||
let document_b = browser_b.contentDocument;
|
||||
let links = document_b.getElementsByTagName("a");
|
||||
|
||||
// We're going to click on the first link, so listen for another load event
|
||||
info("Clicking on link 1, 1 load should take place");
|
||||
let promise = waitForLoadsInBrowser(tab.linkedBrowser, 1);
|
||||
EventUtils.sendMouseEvent({type:"click"}, links[0], browser_b.contentWindow);
|
||||
yield promise;
|
||||
|
||||
info("Clicking on link 2, 1 load should take place");
|
||||
promise = waitForLoadsInBrowser(tab.linkedBrowser, 1);
|
||||
EventUtils.sendMouseEvent({type:"click"}, links[1], browser_b.contentWindow);
|
||||
yield promise;
|
||||
|
||||
info("Close then un-close page, 4 loads should take place");
|
||||
gBrowser.removeTab(tab);
|
||||
let newTab = ss.undoCloseTab(window, 0);
|
||||
yield waitForLoadsInBrowser(newTab.linkedBrowser, 4);
|
||||
|
||||
info("Go back in time, 1 load should take place");
|
||||
gBrowser.goBack();
|
||||
yield waitForLoadsInBrowser(newTab.linkedBrowser, 1);
|
||||
|
||||
let expectedURLEnds = ["a.html", "b.html", "c1.html"];
|
||||
let frames = newTab.linkedBrowser.contentDocument.getElementsByTagName("frame");
|
||||
for (let i = 0; i < frames.length; i++) {
|
||||
is(frames[i].contentDocument.location,
|
||||
getRootDirectory(gTestPath) + "browser_frame_history_" + expectedURLEnds[i],
|
||||
"frame " + i + " has the right url");
|
||||
}
|
||||
gBrowser.removeTab(newTab);
|
||||
});
|
||||
|
||||
// Loading the frameset inside an iframe
|
||||
add_task(function() {
|
||||
let testURL = getRootDirectory(gTestPath) + "browser_frame_history_index2.html";
|
||||
let tab = gBrowser.addTab(testURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
|
||||
info("iframe: Opening a page with an iframe containing three frames, 5 loads should take place");
|
||||
yield waitForLoadsInBrowser(tab.linkedBrowser, 5);
|
||||
|
||||
let browser_b = tab.linkedBrowser.contentDocument.
|
||||
getElementById("iframe").contentDocument.
|
||||
getElementsByTagName("frame")[1];
|
||||
let document_b = browser_b.contentDocument;
|
||||
let links = document_b.getElementsByTagName("a");
|
||||
|
||||
// We're going to click on the first link, so listen for another load event
|
||||
info("iframe: Clicking on link 1, 1 load should take place");
|
||||
let promise = waitForLoadsInBrowser(tab.linkedBrowser, 1);
|
||||
EventUtils.sendMouseEvent({type:"click"}, links[0], browser_b.contentWindow);
|
||||
yield promise;
|
||||
|
||||
info("iframe: Clicking on link 2, 1 load should take place");
|
||||
promise = waitForLoadsInBrowser(tab.linkedBrowser, 1);
|
||||
EventUtils.sendMouseEvent({type:"click"}, links[1], browser_b.contentWindow);
|
||||
yield promise;
|
||||
|
||||
info("iframe: Close then un-close page, 5 loads should take place");
|
||||
gBrowser.removeTab(tab);
|
||||
let newTab = ss.undoCloseTab(window, 0);
|
||||
yield waitForLoadsInBrowser(newTab.linkedBrowser, 5);
|
||||
|
||||
info("iframe: Go back in time, 1 load should take place");
|
||||
gBrowser.goBack();
|
||||
yield waitForLoadsInBrowser(newTab.linkedBrowser, 1);
|
||||
|
||||
let expectedURLEnds = ["a.html", "b.html", "c1.html"];
|
||||
let frames = newTab.linkedBrowser.contentDocument.
|
||||
getElementById("iframe").contentDocument.
|
||||
getElementsByTagName("frame");
|
||||
for (let i = 0; i < frames.length; i++) {
|
||||
is(frames[i].contentDocument.location,
|
||||
getRootDirectory(gTestPath) + "browser_frame_history_" + expectedURLEnds[i],
|
||||
"frame " + i + " has the right url");
|
||||
}
|
||||
gBrowser.removeTab(newTab);
|
||||
});
|
||||
|
||||
// Now, test that we don't record history if the iframe is added dynamically
|
||||
add_task(function() {
|
||||
// Start with an empty history
|
||||
let blankState = JSON.stringify({
|
||||
windows: [{
|
||||
tabs: [{ entries: [{ url: "about:blank" }] }],
|
||||
_closedTabs: []
|
||||
}],
|
||||
_closedWindows: []
|
||||
});
|
||||
ss.setBrowserState(blankState);
|
||||
|
||||
let testURL = getRootDirectory(gTestPath) + "browser_frame_history_index_blank.html";
|
||||
let tab = gBrowser.addTab(testURL);
|
||||
gBrowser.selectedTab = tab;
|
||||
yield waitForLoadsInBrowser(tab.linkedBrowser, 1);
|
||||
|
||||
info("dynamic: Opening a page with an iframe containing three frames, 4 dynamic loads should take place");
|
||||
let doc = tab.linkedBrowser.contentDocument;
|
||||
let iframe = doc.createElement("iframe");
|
||||
iframe.id = "iframe";
|
||||
iframe.src="browser_frame_history_index.html";
|
||||
doc.body.appendChild(iframe);
|
||||
yield waitForLoadsInBrowser(tab.linkedBrowser, 4);
|
||||
|
||||
let browser_b = tab.linkedBrowser.contentDocument.
|
||||
getElementById("iframe").contentDocument.
|
||||
getElementsByTagName("frame")[1];
|
||||
let document_b = browser_b.contentDocument;
|
||||
let links = document_b.getElementsByTagName("a");
|
||||
|
||||
// We're going to click on the first link, so listen for another load event
|
||||
info("dynamic: Clicking on link 1, 1 load should take place");
|
||||
let promise = waitForLoadsInBrowser(tab.linkedBrowser, 1);
|
||||
EventUtils.sendMouseEvent({type:"click"}, links[0], browser_b.contentWindow);
|
||||
yield promise;
|
||||
|
||||
info("dynamic: Clicking on link 2, 1 load should take place");
|
||||
promise = waitForLoadsInBrowser(tab.linkedBrowser, 1);
|
||||
EventUtils.sendMouseEvent({type:"click"}, links[1], browser_b.contentWindow);
|
||||
yield promise;
|
||||
|
||||
info("Check in the state that we have not stored this history");
|
||||
let state = ss.getBrowserState();
|
||||
info(JSON.stringify(JSON.parse(state), null, "\t"));
|
||||
is(state.indexOf("c1.html"), -1, "History entry was not stored in the session state");;
|
||||
gBrowser.removeTab(tab);
|
||||
});
|
||||
|
||||
// helper functions
|
||||
function waitForLoadsInBrowser(aBrowser, aLoadCount) {
|
||||
let deferred = Promise.defer();
|
||||
let loadCount = 0;
|
||||
aBrowser.addEventListener("load", function(aEvent) {
|
||||
if (++loadCount < aLoadCount) {
|
||||
info("Got " + loadCount + " loads, waiting until we have " + aLoadCount);
|
||||
return;
|
||||
}
|
||||
|
||||
aBrowser.removeEventListener("load", arguments.callee, true);
|
||||
deferred.resolve();
|
||||
}, true);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
function timeout(delay, task) {
|
||||
let deferred = Promise.defer();
|
||||
setTimeout(() => deferred.resolve(true), delay);
|
||||
task.then(() => deferred.resolve(false), deferred.reject);
|
||||
return deferred.promise;
|
||||
}
|
10
browser/components/sessionstore/test/browser_frame_history_b.html
Executable file
10
browser/components/sessionstore/test/browser_frame_history_b.html
Executable file
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<body>
|
||||
I'm B!<br/>
|
||||
<a target="c" href="browser_frame_history_c1.html">click me first</a><br/>
|
||||
<a target="c" href="browser_frame_history_c2.html">then click me</a><br/>
|
||||
Close this tab.<br/>
|
||||
Restore this tab.<br/>
|
||||
Click back.<br/>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,10 @@
|
||||
<html>
|
||||
<frameset cols="20%,80%">
|
||||
<frameset rows="30%,70%">
|
||||
<frame src="browser_frame_history_a.html"/>
|
||||
<frame src="browser_frame_history_b.html"/>
|
||||
</frameset>
|
||||
<frame src="browser_frame_history_c.html" name="c"/>
|
||||
</frameset>
|
||||
</html>
|
||||
|
@ -0,0 +1,4 @@
|
||||
<html>
|
||||
<iframe src="browser_frame_history_index.html" id="iframe" />
|
||||
</html>
|
||||
|
@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
Reference in New Issue
Block a user