Bug 1293583 - add test that checks whether the main frame has frame ID 0 r=billm
authorRob Wu <rob@robwu.nl>
Tue, 09 Aug 2016 00:12:09 -0700
changeset 309136 f90cbdbd61d2beed65814c1940bb0ddaaaf65601
parent 309135 2c7b15b477edf62c55d197623f3517028c94daa1
child 309282 c385cb6a0838b9e5593fc2d81a6f44fc709548e1
push id31320
push userkwierso@gmail.com
push dateFri, 12 Aug 2016 23:29:09 +0000
treeherderautoland@f90cbdbd61d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbillm
bugs1293583
milestone51.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1293583 - add test that checks whether the main frame has frame ID 0 r=billm Tests cannot be run in a new process, so when this test is run along with other tests, the faulty behavior is not caught. You can manually check whether the bug is still present by running the test in isolation: mach mochitest browser/components/extensions/test/browser/browser_ext_webNavigation_frameId0.js MozReview-Commit-ID: LwumSU7zh8R
browser/components/extensions/test/browser/browser.ini
browser/components/extensions/test/browser/browser_ext_webNavigation_frameId0.js
--- a/browser/components/extensions/test/browser/browser.ini
+++ b/browser/components/extensions/test/browser/browser.ini
@@ -72,16 +72,17 @@ support-files =
 [browser_ext_tabs_query.js]
 [browser_ext_tabs_reload.js]
 [browser_ext_tabs_reload_bypass_cache.js]
 [browser_ext_tabs_sendMessage.js]
 [browser_ext_tabs_update.js]
 [browser_ext_tabs_zoom.js]
 [browser_ext_tabs_update_url.js]
 [browser_ext_topwindowid.js]
+[browser_ext_webNavigation_frameId0.js]
 [browser_ext_webNavigation_getFrames.js]
 [browser_ext_webNavigation_urlbar_transitions.js]
 [browser_ext_windows.js]
 [browser_ext_windows_create.js]
 tags = fullscreen
 [browser_ext_windows_create_tabId.js]
 [browser_ext_windows_events.js]
 [browser_ext_windows_size.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_webNavigation_frameId0.js
@@ -0,0 +1,47 @@
+/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set sts=2 sw=2 et tw=80: */
+"use strict";
+
+add_task(function* webNavigation_getFrameId_of_existing_main_frame() {
+  // Whether the frame ID in the extension API is 0 is determined by a map that
+  // is maintained by |Frames| in ExtensionManagement.jsm. This map is filled
+  // using data from content processes. But if ExtensionManagement.jsm is not
+  // imported, then the "Extension:TopWindowID" message gets lost.
+  // As a result, if the state is not synchronized again, the webNavigation API
+  // will mistakenly report a non-zero frame ID for top-level frames.
+  //
+  // If you want to be absolutely sure that the frame ID is correct, don't open
+  // tabs before starting an extension, or explicitly load the module in the
+  // main process:
+  // Cu.import("resource://gre/modules/ExtensionManagement.jsm", {});
+  //
+  // Or simply run the test again.
+  const BASE = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/";
+  const DUMMY_URL = BASE + "file_dummy.html";
+  let tab = yield BrowserTestUtils.openNewForegroundTab(gBrowser, DUMMY_URL, true);
+
+  function background(DUMMY_URL) {
+    browser.tabs.query({active: true, currentWindow: true}).then(tabs => {
+      return browser.webNavigation.getAllFrames({tabId: tabs[0].id});
+    }).then(frames => {
+      browser.test.assertEq(1, frames.length, "The dummy page has one frame");
+      browser.test.assertEq(0, frames[0].frameId, "Main frame's ID must be 0");
+      browser.test.assertEq(DUMMY_URL, frames[0].url, "Main frame URL must match");
+      browser.test.notifyPass("frameId checked");
+    });
+  }
+
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      "permissions": ["webNavigation"],
+    },
+
+    background: `(${background})(${JSON.stringify(DUMMY_URL)});`,
+  });
+
+  yield extension.startup();
+  yield extension.awaitFinish("frameId checked");
+  yield extension.unload();
+
+  yield BrowserTestUtils.removeTab(tab);
+});