Bug 1253604 share breakage after canceling share on fb, r=markh

This commit is contained in:
Shane Caraveo 2016-04-25 17:50:01 -07:00
parent 3e9bda71d8
commit 6104fb3f97
6 changed files with 132 additions and 47 deletions

View File

@ -489,7 +489,6 @@ SocialShare = {
iframe.setAttribute("class", "social-share-frame");
iframe.setAttribute("context", "contentAreaContextMenu");
iframe.setAttribute("tooltip", "aHTMLTooltip");
iframe.setAttribute("disablehistory", "true");
iframe.setAttribute("disableglobalhistory", "true");
iframe.setAttribute("flex", "1");
iframe.setAttribute("message", "true");
@ -575,6 +574,7 @@ SocialShare = {
onHidden: function() {
(this._currentAnchor || this.anchor).removeAttribute("open");
this._currentAnchor = null;
this.iframe.docShellIsActive = false;
this.iframe.removeEventListener("click", this._onclick, true);
this.iframe.setAttribute("src", "data:text/plain;charset=utf8,");
// make sure that the frame is unloaded after it is hidden
@ -680,6 +680,9 @@ SocialShare = {
// window.opener, some share endpoints rely on w.opener to know they
// should close the window when done.
iframe.contentWindow.opener = iframe.contentWindow;
// disable beforeunload dialogs
let mm = iframe.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.messageManager;
mm.sendAsyncMessage("Social:DisableDialogs", {});
SocialShare._dynamicResizer.start(iframe.parentNode, iframe, size);

View File

@ -65,6 +65,7 @@ const SocialErrorListener = {
addMessageListener("Social:ListenForEvents", this);
addMessageListener("Social:SetDocumentTitle", this);
addMessageListener("Social:SetErrorURL", this);
addMessageListener("Social:DisableDialogs", this);
addMessageListener("Social:WaitForDocumentVisible", this);
addMessageListener("WaitForDOMContentLoaded", this);
let webProgress = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
@ -175,6 +176,11 @@ const SocialErrorListener = {
sendAsyncMessage("Social:DocumentVisible");
});
break;
case "Social:DisableDialogs":
let windowUtils = content.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowUtils);
windowUtils.disableDialogs();
break;
case "WaitForDOMContentLoaded":
if (gDOMContentLoaded) {
sendAsyncMessage("DOMContentLoaded");

View File

@ -30,7 +30,6 @@ support-files =
[browser_addons.js]
[browser_blocklist.js]
[browser_share.js]
skip-if = true # bug 1115131
[browser_social_activation.js]
[browser_social_chatwindow.js]
[browser_social_chatwindow_resize.js]

View File

@ -21,18 +21,6 @@ function sendActivationEvent(subframe) {
EventUtils.synthesizeMouseAtCenter(button, {}, doc.defaultView);
}
function promiseShareFrameEvent(iframe, eventName) {
let deferred = Promise.defer();
iframe.addEventListener(eventName, function load(event) {
info("page load is " + iframe.contentDocument.location.href);
if (iframe.contentDocument.location.href != "data:text/plain;charset=utf8,") {
iframe.removeEventListener(eventName, load, true);
deferred.resolve(event);
}
}, true);
return deferred.promise;
}
function test() {
waitForExplicitFinish();
Services.prefs.setCharPref("social.shareDirectory", activationPage);
@ -41,6 +29,16 @@ function test() {
addEventListener("OpenGraphData", function (aEvent) {
sendAsyncMessage("sharedata", aEvent.detail);
}, true, true);
/* bug 1042991, ensure history is available by calling history.back on close */
addMessageListener("closeself", function(e) {
content.history.back();
content.close();
}, true);
/* if text is entered into field, onbeforeunload will cause a modal dialog
unless dialogs have been disabled for the iframe. */
content.onbeforeunload = function(e) {
return 'FAIL.';
};
}.toString() + ")();";
let mm = getGroupMessageManager("social");
mm.loadFrameScript(frameScript, true);
@ -188,28 +186,48 @@ var tests = {
let testIndex = 0;
let testData = corpus[testIndex++];
// initialize the button into the navbar
CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
// ensure correct state
SocialUI.onCustomizeEnd(window);
let mm = getGroupMessageManager("social");
mm.addMessageListener("sharedata", function handler(msg) {
gBrowser.removeTab(testTab);
hasoptions(testData.options, JSON.parse(msg.data));
testData = corpus[testIndex++];
if (testData) {
executeSoon(runOneTest);
} else {
mm.removeMessageListener("sharedata", handler);
SocialService.disableProvider(manifest.origin, next);
}
BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },"share panel closed").then(() => {
if (testData) {
runOneTest();
} else {
mm.removeMessageListener("sharedata", handler);
SocialService.disableProvider(manifest.origin, next);
}
});
SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
});
function runOneTest() {
addTab(testData.url, function(tab) {
testTab = tab;
let shareButton = SocialShare.shareButton;
// verify the attribute for proper css
ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
// button should be visible
is(shareButton.hidden, false, "share button is visible");
SocialShare.sharePage(manifest.origin);
});
}
executeSoon(runOneTest);
},
testShareMicroformats: function(next) {
// initialize the button into the navbar
CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
// ensure correct state
SocialUI.onCustomizeEnd(window);
SocialService.addProvider(manifest, function(provider) {
let target, testTab;
@ -261,14 +279,25 @@ var tests = {
let mm = getGroupMessageManager("social");
mm.addMessageListener("sharedata", function handler(msg) {
is(msg.data, expecting, "microformats data ok");
gBrowser.removeTab(testTab);
mm.removeMessageListener("sharedata", handler);
SocialService.disableProvider(manifest.origin, next);
BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },
"share panel closed").then(() => {
gBrowser.removeTab(testTab);
mm.removeMessageListener("sharedata", handler);
SocialService.disableProvider(manifest.origin, next);
});
SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
});
let url = "https://example.com/browser/browser/base/content/test/social/microformats.html"
addTab(url, function(tab) {
testTab = tab;
let shareButton = SocialShare.shareButton;
// verify the attribute for proper css
ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
// button should be visible
is(shareButton.hidden, false, "share button is visible");
let doc = tab.linkedBrowser.contentDocument;
target = doc.getElementById("simple-hcard");
SocialShare.sharePage(manifest.origin, null, target);
@ -284,31 +313,83 @@ var tests = {
SocialShare._createFrame();
let iframe = SocialShare.iframe;
promiseShareFrameEvent(iframe, "load").then(() => {
// initialize the button into the navbar
CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
// ensure correct state
SocialUI.onCustomizeEnd(window);
ensureEventFired(iframe, "load").then(() => {
let subframe = iframe.contentDocument.getElementById("activation-frame");
waitForCondition(() => {
// sometimes the iframe is ready before the panel is open, we need to
// wait for both conditions
return SocialShare.panel.state == "open"
&& subframe.contentDocument
&& subframe.contentDocument.readyState == "complete";
}, () => {
ensureFrameLoaded(subframe, activationPage).then(() => {
is(subframe.contentDocument.location.href, activationPage, "activation page loaded");
promiseObserverNotified("social:provider-enabled").then(() => {
let mm = getGroupMessageManager("social");
mm.addMessageListener("sharedata", function handler(msg) {
ok(true, "share completed");
gBrowser.removeTab(testTab);
mm.removeMessageListener("sharedata", handler);
SocialService.uninstallProvider(manifest.origin, next);
BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },
"share panel closed").then(() => {
ensureBrowserTabClosed(testTab).then(() => {
mm.removeMessageListener("sharedata", handler);
SocialService.uninstallProvider(manifest.origin, next);
});
});
SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
});
});
sendActivationEvent(subframe);
}, "share panel did not open and load share page");
});
});
addTab(activationPage, function(tab) {
let shareButton = SocialShare.shareButton;
// verify the attribute for proper css
ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
// button should be visible
is(shareButton.hidden, false, "share button is visible");
testTab = tab;
SocialShare.sharePage();
});
},
testSharePanelDialog: function(next) {
let testTab;
// initialize the button into the navbar
CustomizableUI.addWidgetToArea("social-share-button", CustomizableUI.AREA_NAVBAR);
// ensure correct state
SocialUI.onCustomizeEnd(window);
SocialShare._createFrame();
SocialService.addProvider(manifest, () => {
addTab(activationPage, (tab) => {
ensureEventFired(SocialShare.iframe, "load").then(() => {
// send keys to the input field. An unexpected failure will happen
// if the onbeforeunload handler is fired.
EventUtils.sendKey("f");
EventUtils.sendKey("a");
EventUtils.sendKey("i");
EventUtils.sendKey("l");
SocialShare.panel.addEventListener("popuphidden", function hidden(evt) {
SocialShare.panel.removeEventListener("popuphidden", hidden);
let topwin = Services.wm.getMostRecentWindow(null);
is(topwin, window, "no dialog is open");
ensureBrowserTabClosed(testTab).then(() => {
SocialService.disableProvider(manifest.origin, next);
});
});
SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
});
let shareButton = SocialShare.shareButton;
// verify the attribute for proper css
ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
// button should be visible
is(shareButton.hidden, false, "share button is visible");
testTab = tab;
SocialShare.sharePage();
});
});
}
}

View File

@ -415,16 +415,19 @@ function loadIntoTab(tab, url, callback) {
function ensureBrowserTabClosed(tab) {
let promise = ensureEventFired(gBrowser.tabContainer, "TabClose");
gBrowser.removeTab(tab, {skipPermitUnload: true});
gBrowser.removeTab(tab);
return promise;
}
function ensureFrameLoaded(frame) {
function ensureFrameLoaded(frame, uri) {
let deferred = Promise.defer();
if (frame.contentDocument && frame.contentDocument.readyState == "complete") {
if (frame.contentDocument && frame.contentDocument.readyState == "complete" &&
(!uri || frame.contentDocument.location.href == uri)) {
deferred.resolve();
} else {
frame.addEventListener("load", function handler() {
if (uri && frame.contentDocument.location.href != uri)
return;
frame.removeEventListener("load", handler, true);
deferred.resolve()
}, true);

View File

@ -1,16 +1,9 @@
<html>
<head>
<meta charset="utf-8">
<script>
addEventListener("OpenGraphData", function(e) {
// frame scripts handle test data
// share windows self-close
history.back(); // bug 1042991, ensure history is available
window.close();
})
</script>
</head>
<body>
<body onload="document.getElementById('testclose').focus()">
<p>This is a test social share window.</p>
<input id="testclose"/>
</body>
</html>