diff --git a/toolkit/content/browser-child.js b/toolkit/content/browser-child.js index a5a79115db3..9d7d9a7657e 100644 --- a/toolkit/content/browser-child.js +++ b/toolkit/content/browser-child.js @@ -140,6 +140,7 @@ let WebProgressListener = { json.charset = content.document.characterSet; json.mayEnableCharacterEncodingMenu = docShell.mayEnableCharacterEncodingMenu; json.principal = content.document.nodePrincipal; + json.synthetic = content.document.mozSyntheticDocument; } sendAsyncMessage("Content:LocationChange", json, objects); @@ -326,22 +327,6 @@ addEventListener("ImageContentLoaded", function (aEvent) { } }, false); -let DocumentObserver = { - init: function() { - Services.obs.addObserver(this, "document-element-inserted", false); - addEventListener("unload", () => { - Services.obs.removeObserver(this, "document-element-inserted"); - }); - }, - - observe: function(aSubject, aTopic, aData) { - if (aSubject == content.document) { - sendAsyncMessage("DocumentInserted", {synthetic: aSubject.mozSyntheticDocument}); - } - }, -}; -DocumentObserver.init(); - const ZoomManager = { get fullZoom() { return this._cache.fullZoom; diff --git a/toolkit/content/tests/browser/browser.ini b/toolkit/content/tests/browser/browser.ini index 43846829790..2cb88db1179 100644 --- a/toolkit/content/tests/browser/browser.ini +++ b/toolkit/content/tests/browser/browser.ini @@ -18,6 +18,9 @@ skip-if = e10s skip-if = e10s # Disabled for e10s: Bug ?????? - seems to be a timing issue with RemoteFinder.jsm messages coming later than the tests expect. [browser_input_file_tooltips.js] skip-if = e10s # Bug ?????? - test directly manipulates content (TypeError: doc.createElement is not a function) +[browser_isSynthetic.js] +support-files = + empty.png [browser_keyevents_during_autoscrolling.js] skip-if = e10s # Bug 921935 - focusmanager issues with e10s [browser_save_resend_postdata.js] diff --git a/toolkit/content/tests/browser/browser_isSynthetic.js b/toolkit/content/tests/browser/browser_isSynthetic.js new file mode 100644 index 00000000000..9bea87e798f --- /dev/null +++ b/toolkit/content/tests/browser/browser_isSynthetic.js @@ -0,0 +1,60 @@ +function waitForLoad(browser) { + return new Promise(resolve => { + let wasSynthetic = browser.isSyntheticDocument; + + browser.addProgressListener({ + onLocationChange: function(webProgress, request, location, flags) { + wasSynthetic = browser.isSyntheticDocument; + }, + + onStateChange: function(webProgress, request, flags, status) { + let docStop = Ci.nsIWebProgressListener.STATE_IS_NETWORK | + Ci.nsIWebProgressListener.STATE_STOP; + if ((flags & docStop) == docStop) { + browser.removeProgressListener(this); + resolve(wasSynthetic); + } + }, + + QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebProgressListener, + Ci.nsISupportsWeakReference]) + }); + }); +} + +const FILES = gTestPath.replace("browser_isSynthetic.js", "") + .replace("chrome://mochitests/content/", "http://example.com/"); + +add_task(function*() { + let tab = gBrowser.addTab("about:blank"); + let browser = tab.linkedBrowser; + yield waitForLoad(browser); + + is(browser.isSyntheticDocument, false, "Should not be synthetic"); + + let loadPromise = waitForLoad(browser); + browser.loadURI("data:text/html;charset=utf-8,"); + let wasSynthetic = yield loadPromise; + is(wasSynthetic, false, "Should not be synthetic"); + is(browser.isSyntheticDocument, false, "Should not be synthetic"); + + loadPromise = waitForLoad(browser); + browser.loadURI(FILES + "empty.png"); + wasSynthetic = yield loadPromise; + is(wasSynthetic, true, "Should be synthetic"); + is(browser.isSyntheticDocument, true, "Should be synthetic"); + + loadPromise = waitForLoad(browser); + browser.goBack(); + wasSynthetic = yield loadPromise; + is(wasSynthetic, false, "Should not be synthetic"); + is(browser.isSyntheticDocument, false, "Should not be synthetic"); + + loadPromise = waitForLoad(browser); + browser.goForward(); + wasSynthetic = yield loadPromise; + is(wasSynthetic, true, "Should be synthetic"); + is(browser.isSyntheticDocument, true, "Should be synthetic"); + + gBrowser.removeTab(tab); +}); diff --git a/toolkit/content/tests/browser/empty.png b/toolkit/content/tests/browser/empty.png new file mode 100644 index 00000000000..17ddf0c3ee9 Binary files /dev/null and b/toolkit/content/tests/browser/empty.png differ diff --git a/toolkit/content/widgets/remote-browser.xml b/toolkit/content/widgets/remote-browser.xml index 01944668907..c74745cfe4b 100644 --- a/toolkit/content/widgets/remote-browser.xml +++ b/toolkit/content/widgets/remote-browser.xml @@ -322,10 +322,6 @@ break; } - case "DocumentInserted": - this._isSyntheticDocument = data.synthetic; - break; - case "FullZoomChange": { this._fullZoom = data.value; let event = document.createEvent("Events"); diff --git a/toolkit/modules/RemoteWebProgress.jsm b/toolkit/modules/RemoteWebProgress.jsm index a06140b5f5d..489629bc445 100644 --- a/toolkit/modules/RemoteWebProgress.jsm +++ b/toolkit/modules/RemoteWebProgress.jsm @@ -198,6 +198,7 @@ RemoteWebProgressManager.prototype = { this._browser._imageDocument = null; this._browser._mayEnableCharacterEncodingMenu = json.mayEnableCharacterEncodingMenu; this._browser._contentPrincipal = json.principal; + this._browser._isSyntheticDocument = json.synthetic; } this._callProgressListeners("onLocationChange", webProgress, request, location, flags);