Bug 1032398 repalce socialShow/Hide with visibility api, r=markh

This commit is contained in:
Shane Caraveo 2016-03-17 18:25:09 -07:00
Родитель c3a25096a7
Коммит d26cfde891
8 изменённых файлов: 51 добавлений и 58 удалений

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

@ -376,7 +376,6 @@ SocialFlyout = {
iframe.docShellIsActive = true;
if (iframe.contentDocument.readyState == "complete") {
this._dynamicResizer.start(panel, iframe);
this.dispatchPanelEvent("socialFrameShow");
} else {
// first time load, wait for load and dispatch after load
iframe.addEventListener("load", function panelBrowserOnload(e) {
@ -384,7 +383,6 @@ SocialFlyout = {
setTimeout(function() {
if (SocialFlyout._dynamicResizer) { // may go null if hidden quickly
SocialFlyout._dynamicResizer.start(panel, iframe);
SocialFlyout.dispatchPanelEvent("socialFrameShow");
}
}, 0);
}, true);
@ -395,7 +393,6 @@ SocialFlyout = {
this._dynamicResizer.stop();
this._dynamicResizer = null;
this.iframe.docShellIsActive = false;
this.dispatchPanelEvent("socialFrameHide");
},
load: function(aURL, cb) {
@ -838,9 +835,6 @@ SocialSidebar = {
if (aEnabled == sbrowser.docShellIsActive)
return;
sbrowser.docShellIsActive = aEnabled;
let evt = sbrowser.contentDocument.createEvent("CustomEvent");
evt.initCustomEvent(aEnabled ? "socialFrameShow" : "socialFrameHide", true, true, {});
sbrowser.contentDocument.documentElement.dispatchEvent(evt);
},
updateToggleNotifications: function() {

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

@ -152,6 +152,8 @@
<setter>
this.content.docShellIsActive = !!val;
// Bug 1256431 to remove socialFrameShow/Hide from hello, keep this
// until that is complete.
// let the chat frame know if it is being shown or hidden
this.content.messageManager.sendAsyncMessage("Social:CustomEvent", {
name: val ? "socialFrameShow" : "socialFrameHide"

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

@ -291,13 +291,11 @@
let sizeSocialPanelToContent = Cu.import("resource:///modules/Social.jsm", {}).sizeSocialPanelToContent;
if (!this._loading && this.contentDocument &&
this.contentDocument.readyState == "complete") {
this.dispatchPanelEvent("socialFrameShow");
if (this._useDynamicResizer)
sizeSocialPanelToContent(this.panel, this.content);
} else {
let panelBrowserOnload = (e) => {
this.content.removeEventListener("load", panelBrowserOnload, true);
this.dispatchPanelEvent("socialFrameShow");
if (this._useDynamicResizer)
sizeSocialPanelToContent(this.panel, this.content);
};
@ -350,7 +348,6 @@
this.onShown();
]]></handler>
<handler event="popuphidden"><![CDATA[
this.dispatchPanelEvent("socialFrameHide");
this._anchor.removeAttribute("open");
this.update();
this.content.removeEventListener("click", this);

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

@ -8,13 +8,9 @@ function test() {
addMessageListener("socialTest-CloseSelf", function(e) {
content.close();
});
addEventListener("socialFrameShow", function(e) {
sendAsyncMessage("social-visibility", "shown");
}, false);
addEventListener("socialFrameHide", function(e) {
sendAsyncMessage("social-visibility", "hidden");
}, false);
addEventListener("visibilitychange", function() {
sendAsyncMessage("social-visibility", content.document.hidden ? "hidden" : "shown");
});
addMessageListener("socialTest-sendEvent", function(msg) {
let data = msg.data;
let evt = content.document.createEvent("CustomEvent");

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

@ -13,12 +13,9 @@ function test() {
};
let frameScript = "data:,(" + function frame_script() {
addEventListener("socialFrameShow", function(e) {
sendAsyncMessage("visibility", "shown");
}, false);
addEventListener("socialFrameHide", function(e) {
sendAsyncMessage("visibility", "hidden");
}, false);
addEventListener("visibilitychange", function() {
sendAsyncMessage("visibility", content.document.hidden ? "hidden" : "shown");
});
}.toString() + ")();";
let mm = getGroupMessageManager("social");
mm.loadFrameScript(frameScript, true);

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

@ -26,12 +26,9 @@ function test() {
waitForExplicitFinish();
let frameScript = "data:,(" + function frame_script() {
addEventListener("socialFrameShow", function(e) {
sendAsyncMessage("visibility", "shown");
}, false);
addEventListener("socialFrameHide", function(e) {
sendAsyncMessage("visibility", "hidden");
}, false);
addEventListener("visibilitychange", function() {
sendAsyncMessage("visibility", content.document.hidden ? "hidden" : "shown");
});
}.toString() + ")();";
let mm = getGroupMessageManager("social");
mm.loadFrameScript(frameScript, true);

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

@ -14,6 +14,18 @@ var manifest = { // normal provider
function test() {
waitForExplicitFinish();
let frameScript = "data:,(" + function frame_script() {
addEventListener("visibilitychange", function() {
sendAsyncMessage("visibility", content.document.hidden ? "hidden" : "shown");
});
}.toString() + ")();";
let mm = getGroupMessageManager("social");
mm.loadFrameScript(frameScript, true);
registerCleanupFunction(function () {
mm.removeDelayedFrameScript(frameScript);
});
SocialService.addProvider(manifest, function() {
// the test will remove the provider
doTest();
@ -27,12 +39,16 @@ function doTest() {
let command = document.getElementById("Social:ToggleSidebar");
let sidebar = document.getElementById("social-sidebar-box");
let browser = sidebar.lastChild;
ok(!browser.docShellIsActive, "sidebar is not active");
is(sidebar.hidden, true, "sidebar should be hidden");
is(command.getAttribute("checked"), "false", "toggle command should be unchecked");
function checkShown(shouldBeShown) {
is(command.getAttribute("checked"), shouldBeShown ? "true" : "false",
"toggle command should be " + (shouldBeShown ? "checked" : "unchecked"));
is(sidebar.hidden, !shouldBeShown,
"sidebar should be " + (shouldBeShown ? "visible" : "hidden"));
is(browser.docShellIsActive, shouldBeShown, "sidebar isActive in correct state");
if (shouldBeShown) {
is(browser.getAttribute('src'), SocialSidebar.provider.sidebarURL, "sidebar url should be set");
// We don't currently check docShellIsActive as this is only set
@ -52,31 +68,31 @@ function doTest() {
}
}
}
// First check the the sidebar is initially visible, and loaded
ok(!command.hidden, "toggle command should be visible");
ensureEventFired(browser, "socialFrameShow").then(function sidebarhide() {
checkShown(true);
ensureEventFired(browser, "socialFrameHide").then(function sidebarshow() {
checkShown(false);
// disable social.
SocialService.disableProvider(SocialSidebar.provider.origin, function() {
checkShown(false);
is(Social.providers.length, 0, "no providers left");
defaultFinishChecks();
// Finish the test
executeSoon(finish);
});
ensureEventFired(browser, "load").then(() => {
// First check the the sidebar is initially visible, and loaded
ok(!command.hidden, "toggle command should be visible");
let mm = getGroupMessageManager("social");
mm.addMessageListener("visibility", function shown(msg) {
if (msg.data == "shown") {
mm.removeMessageListener("visibility", shown);
checkShown(true);
info("Toggling sidebar to closed");
SocialSidebar.toggleSidebar();
}
});
mm.addMessageListener("visibility", function handler(msg) {
if (msg.data == "hidden") {
mm.removeMessageListener("visibility", handler);
// disable social.
SocialService.disableProvider(SocialSidebar.provider.origin, function() {
checkShown(false);
is(Social.providers.length, 0, "no providers left");
defaultFinishChecks();
// Finish the test
executeSoon(finish);
});
}
});
// Toggle it back on
info("Toggling sidebar back on");
SocialSidebar.toggleSidebar();
});
SocialSidebar.show();
}

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

@ -39,12 +39,6 @@ function test() {
waitForExplicitFinish();
let frameScript = "data:,(" + function frame_script() {
addEventListener("socialFrameShow", function(e) {
sendAsyncMessage("visibility", "shown");
}, false);
addEventListener("socialFrameHide", function(e) {
sendAsyncMessage("visibility", "hidden");
}, false);
addMessageListener("socialTest-sendEvent", function(msg) {
let data = msg.data;
let evt = content.document.createEvent("CustomEvent");