Bug 1443749 only reload sidebar when the url has changed r=kmag
authorShane Caraveo <scaraveo@mozilla.com>
Fri, 09 Mar 2018 16:30:49 -0600
changeset 460016 3bf5123d0218751b86fdff5654ab5bcdefabec6d
parent 460015 14f77d01522bf9881b6659e6f8bbbf2677f81ee3
child 460017 5f5da5116bfa9b16e9b9cd35cd7e9237dfc2785a
push id8824
push userarchaeopteryx@coole-files.de
push dateMon, 12 Mar 2018 14:54:48 +0000
treeherdermozilla-beta@8d9daab95d68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1443749, 1398713
milestone60.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 1443749 only reload sidebar when the url has changed r=kmag Regression from bug 1398713. Before that, we reloaded the entire webext-panel.xul if the sidebar changed. This verifies we don't reload unecessarily as well as discards the browser to force a runtime disconnect for the extension if it does change. MozReview-Commit-ID: LuYxmj9mSb7
browser/base/content/webext-panels.js
browser/components/extensions/test/browser/browser-common.ini
browser/components/extensions/test/browser/browser_ext_sidebarAction_runtime.js
--- a/browser/base/content/webext-panels.js
+++ b/browser/base/content/webext-panels.js
@@ -84,17 +84,26 @@ var gBrowser = {
   getTabModalPromptBox(browser) {
     if (!browser.tabModalPromptBox) {
       browser.tabModalPromptBox = new TabModalPromptBox(browser);
     }
     return browser.tabModalPromptBox;
   },
 };
 
-async function loadPanel(extensionId, extensionUrl, browserStyle) {
+function loadPanel(extensionId, extensionUrl, browserStyle) {
+  let browserEl = document.getElementById("webext-panels-browser");
+  if (browserEl) {
+    if (browserEl.currentURI.spec === extensionUrl) {
+      return;
+    }
+    // Forces runtime disconnect.  Remove the stack (parent).
+    browserEl.parentNode.remove();
+  }
+
   let policy = WebExtensionPolicy.getByID(extensionId);
   let sidebar = {
     uri: extensionUrl,
     remote: policy.extension.remote,
     browserStyle,
   };
   getBrowser(sidebar).then(browser => {
     let uri = Services.io.newURI(policy.getURL());
--- a/browser/components/extensions/test/browser/browser-common.ini
+++ b/browser/components/extensions/test/browser/browser-common.ini
@@ -135,16 +135,17 @@ disabled = bug 1438663
 [browser_ext_sessions_restore.js]
 [browser_ext_sessions_window_tab_value.js]
 [browser_ext_settings_overrides_default_search.js]
 [browser_ext_settings_overrides_search.js]
 [browser_ext_sidebarAction.js]
 [browser_ext_sidebarAction_browser_style.js]
 [browser_ext_sidebarAction_context.js]
 [browser_ext_sidebarAction_contextMenu.js]
+[browser_ext_sidebarAction_runtime.js]
 [browser_ext_sidebarAction_tabs.js]
 [browser_ext_sidebarAction_windows.js]
 [browser_ext_simple.js]
 [browser_ext_slow_script.js]
 skip-if = !e10s || debug || asan
 [browser_ext_tab_runtimeConnect.js]
 [browser_ext_tabs_audio.js]
 [browser_ext_tabs_captureTab.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/extensions/test/browser/browser_ext_sidebarAction_runtime.js
@@ -0,0 +1,65 @@
+"use strict";
+
+function background() {
+  browser.runtime.onConnect.addListener(port => {
+    browser.test.assertEq(port.name, "ernie", "port name correct");
+    port.onDisconnect.addListener(() => {
+      browser.test.assertEq(null, port.error, "The port is implicitly closed without errors when the other context unloads");
+      port.disconnect();
+      browser.test.sendMessage("disconnected");
+    });
+    browser.test.sendMessage("connected");
+  });
+}
+
+let extensionData = {
+  background,
+  manifest: {
+    sidebar_action: {
+      default_panel: "sidebar.html",
+    },
+  },
+  useAddonManager: "temporary",
+
+  files: {
+    "sidebar.html": `
+      <!DOCTYPE html>
+      <html>
+      <head><meta charset="utf-8"/>
+      <script src="sidebar.js"></script>
+      </head>
+      <body>
+      A Test Sidebar
+      </body></html>
+    `,
+
+    "sidebar.js": function() {
+      window.onload = () => {
+        browser.runtime.connect({name: "ernie"});
+      };
+    },
+  },
+};
+
+add_task(async function test_sidebar_disconnect() {
+  let extension = ExtensionTestUtils.loadExtension(extensionData);
+  let connected = extension.awaitMessage("connected");
+  await extension.startup();
+  await connected;
+
+  // switching sidebar to another extension
+  let extension2 = ExtensionTestUtils.loadExtension(extensionData);
+  let switched = Promise.all([
+    extension.awaitMessage("disconnected"),
+    extension2.awaitMessage("connected")]);
+  await extension2.startup();
+  await switched;
+
+  // switching sidebar to built-in sidebar
+  let disconnected = extension2.awaitMessage("disconnected");
+  window.SidebarUI.show("viewBookmarksSidebar");
+  await disconnected;
+
+  await extension.unload();
+  await extension2.unload();
+});