mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 795518 - window.close() in social windows should close social panel. r=jaws
This commit is contained in:
parent
a521376e23
commit
c1ed6de18a
@ -116,6 +116,33 @@ var tests = {
|
|||||||
}
|
}
|
||||||
port.postMessage({topic: "test-worker-chat", data: chatUrl});
|
port.postMessage({topic: "test-worker-chat", data: chatUrl});
|
||||||
},
|
},
|
||||||
|
testCloseSelf: function(next) {
|
||||||
|
let chats = document.getElementById("pinnedchats");
|
||||||
|
let port = Social.provider.getWorkerPort();
|
||||||
|
ok(port, "provider has a port");
|
||||||
|
port.onmessage = function (e) {
|
||||||
|
let topic = e.data.topic;
|
||||||
|
switch (topic) {
|
||||||
|
case "test-init-done":
|
||||||
|
port.postMessage({topic: "test-chatbox-open"});
|
||||||
|
break;
|
||||||
|
case "got-chatbox-visibility":
|
||||||
|
is(e.data.result, "shown", "chatbox shown");
|
||||||
|
port.close(); // don't want any more visibility messages.
|
||||||
|
let chat = chats.selectedChat;
|
||||||
|
ok(chat.parentNode, "chat has a parent node before it is closed");
|
||||||
|
// ask it to close itself.
|
||||||
|
let doc = chat.iframe.contentDocument;
|
||||||
|
let evt = doc.createEvent("CustomEvent");
|
||||||
|
evt.initCustomEvent("socialTest-CloseSelf", true, true, {});
|
||||||
|
doc.documentElement.dispatchEvent(evt);
|
||||||
|
ok(!chat.parentNode, "chat is now closed");
|
||||||
|
next();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
port.postMessage({topic: "test-init", data: { id: 1 }});
|
||||||
|
},
|
||||||
testCloseOnLogout: function(next) {
|
testCloseOnLogout: function(next) {
|
||||||
const chatUrl = "https://example.com/browser/browser/base/content/test/social_chat.html";
|
const chatUrl = "https://example.com/browser/browser/base/content/test/social_chat.html";
|
||||||
let port = Social.provider.getWorkerPort();
|
let port = Social.provider.getWorkerPort();
|
||||||
|
@ -67,6 +67,7 @@ var tests = {
|
|||||||
cs = iframe.contentWindow.getComputedStyle(iframe.contentDocument.body);
|
cs = iframe.contentWindow.getComputedStyle(iframe.contentDocument.body);
|
||||||
is(cs.width, "500px", "should now be 500px wide");
|
is(cs.width, "500px", "should now be 500px wide");
|
||||||
panel.hidePopup();
|
panel.hidePopup();
|
||||||
|
port.close();
|
||||||
next();
|
next();
|
||||||
}, false);
|
}, false);
|
||||||
SocialFlyout.dispatchPanelEvent("socialTest-MakeWider");
|
SocialFlyout.dispatchPanelEvent("socialTest-MakeWider");
|
||||||
@ -74,6 +75,31 @@ var tests = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
port.postMessage({topic: "test-init"});
|
port.postMessage({topic: "test-init"});
|
||||||
}
|
},
|
||||||
}
|
|
||||||
|
|
||||||
|
testCloseSelf: function(next) {
|
||||||
|
let panel = document.getElementById("social-flyout-panel");
|
||||||
|
let port = Social.provider.getWorkerPort();
|
||||||
|
ok(port, "provider has a port");
|
||||||
|
port.onmessage = function (e) {
|
||||||
|
let topic = e.data.topic;
|
||||||
|
switch (topic) {
|
||||||
|
case "test-init-done":
|
||||||
|
port.postMessage({topic: "test-flyout-open"});
|
||||||
|
break;
|
||||||
|
case "got-flyout-visibility":
|
||||||
|
let iframe = panel.firstChild;
|
||||||
|
iframe.contentDocument.addEventListener("SocialTest-DoneCloseSelf", function _doneHandler() {
|
||||||
|
iframe.contentDocument.removeEventListener("SocialTest-DoneCloseSelf", _doneHandler, false);
|
||||||
|
is(panel.state, "closed", "flyout should have closed itself");
|
||||||
|
next();
|
||||||
|
}, false);
|
||||||
|
is(panel.state, "open", "flyout should be open");
|
||||||
|
port.close(); // so we don't get the -visibility message as it hides...
|
||||||
|
SocialFlyout.dispatchPanelEvent("socialTest-CloseSelf");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
port.postMessage({topic: "test-init"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
var port = navigator.mozSocial.getWorker().port;
|
var port = navigator.mozSocial.getWorker().port;
|
||||||
port.postMessage({topic: "chatbox-visibility", result: "hidden"});
|
port.postMessage({topic: "chatbox-visibility", result: "hidden"});
|
||||||
}, false);
|
}, false);
|
||||||
|
window.addEventListener("socialTest-CloseSelf", function(e) {
|
||||||
|
window.close();
|
||||||
|
}, false);
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="pingWorker();">
|
<body onload="pingWorker();">
|
||||||
|
@ -21,6 +21,12 @@
|
|||||||
evt.initCustomEvent("SocialTest-DoneMakeWider", true, true, {});
|
evt.initCustomEvent("SocialTest-DoneMakeWider", true, true, {});
|
||||||
document.documentElement.dispatchEvent(evt);
|
document.documentElement.dispatchEvent(evt);
|
||||||
}, false);
|
}, false);
|
||||||
|
window.addEventListener("socialTest-CloseSelf", function(e) {
|
||||||
|
window.close();
|
||||||
|
var evt = document.createEvent("CustomEvent");
|
||||||
|
evt.initCustomEvent("SocialTest-DoneCloseSelf", true, true, {});
|
||||||
|
document.documentElement.dispatchEvent(evt);
|
||||||
|
}, false);
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body style="max-width: 250px;" onload="pingWorker();">
|
<body style="max-width: 250px;" onload="pingWorker();">
|
||||||
|
@ -174,6 +174,30 @@ function attachToWindow(provider, targetWindow) {
|
|||||||
// set a timer which will fire after the unload events have all fired.
|
// set a timer which will fire after the unload events have all fired.
|
||||||
schedule(function () { port.close(); });
|
schedule(function () { port.close(); });
|
||||||
});
|
});
|
||||||
|
targetWindow.addEventListener("DOMWindowClose", function _mozSocialDOMWindowClose(evt) {
|
||||||
|
let elt = targetWindow.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIWebNavigation)
|
||||||
|
.QueryInterface(Ci.nsIDocShell)
|
||||||
|
.chromeEventHandler;
|
||||||
|
while (elt) {
|
||||||
|
if (elt.nodeName == "panel") {
|
||||||
|
elt.hidePopup();
|
||||||
|
break;
|
||||||
|
} else if (elt.nodeName == "chatbox") {
|
||||||
|
elt.close();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
elt = elt.parentNode;
|
||||||
|
}
|
||||||
|
// preventDefault stops the default window.close() function being called,
|
||||||
|
// which doesn't actually close anything but causes things to get into
|
||||||
|
// a bad state (an internal 'closed' flag is set and debug builds start
|
||||||
|
// asserting as the window is used.).
|
||||||
|
// None of the windows we inject this API into are suitable for this
|
||||||
|
// default close behaviour, so even if we took no action above, we avoid
|
||||||
|
// the default close from doing anything.
|
||||||
|
evt.preventDefault();
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function schedule(callback) {
|
function schedule(callback) {
|
||||||
|
Loading…
Reference in New Issue
Block a user