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

--HG--
extra : rebase_source : 9839d7b96195f2323328d1a37c3d946032bbb652
This commit is contained in:
Shane Caraveo 2018-03-09 16:30:49 -06:00
Родитель 296a409c95
Коммит 25d47480bb
3 изменённых файлов: 76 добавлений и 1 удалений

Просмотреть файл

@ -89,7 +89,16 @@ var gBrowser = {
},
};
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,

Просмотреть файл

@ -140,6 +140,7 @@ disabled = bug 1438663
[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]

Просмотреть файл

@ -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();
});