mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-25 20:01:50 +00:00
Bug 1093221: RemoteWebNavigation.loadURI should accept and pass referrer argument. r=mconley
This commit is contained in:
parent
db1430878f
commit
71056da8c6
@ -166,7 +166,7 @@ let WebNavigation = {
|
||||
this.gotoIndex(message.data.index);
|
||||
break;
|
||||
case "WebNavigation:LoadURI":
|
||||
this.loadURI(message.data.uri, message.data.flags);
|
||||
this.loadURI(message.data.uri, message.data.flags, message.data.referrer);
|
||||
break;
|
||||
case "WebNavigation:Reload":
|
||||
this.reload(message.data.flags);
|
||||
@ -192,12 +192,14 @@ let WebNavigation = {
|
||||
this._webNavigation.gotoIndex(index);
|
||||
},
|
||||
|
||||
loadURI: function(uri, flags) {
|
||||
loadURI: function(uri, flags, referrer) {
|
||||
#ifdef MOZ_CRASHREPORTER
|
||||
if (CrashReporter.enabled)
|
||||
CrashReporter.annotateCrashReport("URL", uri);
|
||||
#endif
|
||||
this._webNavigation.loadURI(uri, flags, null, null, null);
|
||||
if (referrer)
|
||||
referrer = Services.io.newURI(referrer, null, null);
|
||||
this._webNavigation.loadURI(uri, flags, referrer, null, null);
|
||||
},
|
||||
|
||||
reload: function(flags) {
|
||||
|
@ -5,9 +5,7 @@
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["RemoteWebNavigation"];
|
||||
|
||||
const Ci = Components.interfaces;
|
||||
const Cc = Components.classes;
|
||||
const Cu = Components.utils;
|
||||
const { interfaces: Ci, classes: Cc, utils: Cu, results: Cr } = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
@ -60,8 +58,15 @@ RemoteWebNavigation.prototype = {
|
||||
this._sendMessage("WebNavigation:GotoIndex", {index: aIndex});
|
||||
},
|
||||
loadURI: function(aURI, aLoadFlags, aReferrer, aPostData, aHeaders) {
|
||||
if (aPostData || aHeaders)
|
||||
throw Components.Exception("RemoteWebNavigation doesn't accept postdata or headers.", Cr.NS_ERROR_INVALID_ARGS);
|
||||
|
||||
this._browser._contentTitle = "";
|
||||
this._sendMessage("WebNavigation:LoadURI", {uri: aURI, flags: aLoadFlags});
|
||||
this._sendMessage("WebNavigation:LoadURI", {
|
||||
uri: aURI,
|
||||
flags: aLoadFlags,
|
||||
referrer: aReferrer ? aReferrer.spec : null
|
||||
});
|
||||
},
|
||||
reload: function(aReloadFlags) {
|
||||
this._sendMessage("WebNavigation:Reload", {flags: aReloadFlags});
|
||||
|
@ -1,4 +1,6 @@
|
||||
[DEFAULT]
|
||||
support-files =
|
||||
dummy_page.html
|
||||
|
||||
[browser_Battery.js]
|
||||
[browser_Deprecated.js]
|
||||
@ -6,4 +8,5 @@
|
||||
skip-if = e10s # Bug ?????? - test already uses content scripts, but still fails only under e10s.
|
||||
[browser_Geometry.js]
|
||||
[browser_InlineSpellChecker.js]
|
||||
[browser_RemoteWebNavigation.js]
|
||||
[browser_Troubleshoot.js]
|
||||
|
150
toolkit/modules/tests/browser/browser_RemoteWebNavigation.js
Normal file
150
toolkit/modules/tests/browser/browser_RemoteWebNavigation.js
Normal file
@ -0,0 +1,150 @@
|
||||
const { interfaces: Ci, classes: Cc, utils: Cu, results: Cr } = Components;
|
||||
|
||||
const DUMMY1 = "http://example.com/browser/toolkit/modules/tests/browser/dummy_page.html";
|
||||
const DUMMY2 = "http://example.org/browser/toolkit/modules/tests/browser/dummy_page.html"
|
||||
|
||||
function waitForLoad(browser = gBrowser.selectedBrowser) {
|
||||
return new Promise(resolve => {
|
||||
browser.addEventListener("load", function listener() {
|
||||
browser.removeEventListener("load", listener, true);
|
||||
resolve();
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
function waitForPageShow(browser = gBrowser.selectedBrowser) {
|
||||
return new Promise(resolve => {
|
||||
browser.addEventListener("pageshow", function listener() {
|
||||
browser.removeEventListener("pageshow", listener, true);
|
||||
resolve();
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
function makeURI(url) {
|
||||
return Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService).
|
||||
newURI(url, null, null);
|
||||
}
|
||||
|
||||
// Tests that loadURI accepts a referrer and it is included in the load.
|
||||
add_task(function* test_referrer() {
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
browser.webNavigation.loadURI(DUMMY1,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
||||
makeURI(DUMMY2),
|
||||
null, null);
|
||||
yield waitForLoad();
|
||||
is(browser.contentWindow.location, DUMMY1, "Should have loaded the right URL");
|
||||
is(browser.contentDocument.referrer, DUMMY2, "Should have the right referrer");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
||||
|
||||
// Tests that remote access to webnavigation.sessionHistory works.
|
||||
add_task(function* test_history() {
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
browser.webNavigation.loadURI(DUMMY1,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
||||
null, null, null);
|
||||
yield waitForLoad();
|
||||
|
||||
browser.webNavigation.loadURI(DUMMY2,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
||||
null, null, null);
|
||||
yield waitForLoad();
|
||||
|
||||
let history = browser.webNavigation.sessionHistory;
|
||||
is(history.count, 2, "Should be two history items");
|
||||
is(history.index, 1, "Should be at the right place in history");
|
||||
let entry = history.getEntryAtIndex(0, false);
|
||||
is(entry.URI.spec, DUMMY1, "Should have the right history entry");
|
||||
entry = history.getEntryAtIndex(1, false);
|
||||
is(entry.URI.spec, DUMMY2, "Should have the right history entry");
|
||||
|
||||
let promise = waitForPageShow();
|
||||
browser.webNavigation.goBack();
|
||||
yield promise;
|
||||
is(history.index, 0, "Should be at the right place in history");
|
||||
|
||||
promise = waitForPageShow();
|
||||
browser.webNavigation.goForward();
|
||||
yield promise;
|
||||
is(history.index, 1, "Should be at the right place in history");
|
||||
|
||||
promise = waitForPageShow();
|
||||
browser.webNavigation.gotoIndex(0);
|
||||
yield promise;
|
||||
is(history.index, 0, "Should be at the right place in history");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
||||
|
||||
// Tests that load flags are passed through to the content process.
|
||||
add_task(function* test_flags() {
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
browser.webNavigation.loadURI(DUMMY1,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
||||
null, null, null);
|
||||
yield waitForLoad();
|
||||
|
||||
browser.webNavigation.loadURI(DUMMY2,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_REPLACE_HISTORY,
|
||||
null, null, null);
|
||||
yield waitForLoad();
|
||||
|
||||
let history = browser.webNavigation.sessionHistory;
|
||||
is(history.count, 1, "Should be one history item");
|
||||
is(history.index, 0, "Should be at the right place in history");
|
||||
let entry = history.getEntryAtIndex(0, false);
|
||||
is(entry.URI.spec, DUMMY2, "Should have the right history entry");
|
||||
|
||||
browser.webNavigation.loadURI(DUMMY1,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY,
|
||||
null, null, null);
|
||||
yield waitForLoad();
|
||||
|
||||
is(history.count, 1, "Should still be one history item");
|
||||
is(history.index, 0, "Should be at the right place in history");
|
||||
entry = history.getEntryAtIndex(0, false);
|
||||
is(entry.URI.spec, DUMMY2, "Should have the right history entry");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
||||
|
||||
// Tests that attempts to use unsupported arguments throw an exception.
|
||||
add_task(function* test_badarguments() {
|
||||
if (!gMultiProcessBrowser)
|
||||
return;
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
let browser = gBrowser.selectedBrowser;
|
||||
|
||||
try {
|
||||
browser.webNavigation.loadURI(DUMMY1,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
||||
null, {}, null);
|
||||
ok(false, "Should have seen an exception from trying to pass some postdata");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Should have seen an exception from trying to pass some postdata");
|
||||
}
|
||||
|
||||
try {
|
||||
browser.webNavigation.loadURI(DUMMY1,
|
||||
Ci.nsIWebNavigation.LOAD_FLAGS_NONE,
|
||||
null, null, {});
|
||||
ok(false, "Should have seen an exception from trying to pass some headers");
|
||||
}
|
||||
catch (e) {
|
||||
ok(true, "Should have seen an exception from trying to pass some headers");
|
||||
}
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
});
|
7
toolkit/modules/tests/browser/dummy_page.html
Normal file
7
toolkit/modules/tests/browser/dummy_page.html
Normal file
@ -0,0 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
<body>
|
||||
<p>Page</p>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user