michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let manifest = { // normal provider michael@0: name: "provider 1", michael@0: origin: "https://example.com", michael@0: sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", michael@0: workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", michael@0: iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" michael@0: }; michael@0: runSocialTestWithProvider(manifest, function (finishcb) { michael@0: SocialSidebar.show(); michael@0: runSocialTests(tests, undefined, undefined, finishcb); michael@0: }); michael@0: } michael@0: michael@0: var tests = { michael@0: testOpenCloseFlyout: function(next) { michael@0: let panel = document.getElementById("social-flyout-panel"); michael@0: panel.addEventListener("popupshowing", function onShowing() { michael@0: panel.removeEventListener("popupshowing", onShowing); michael@0: is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing"); michael@0: }); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "got-sidebar-message": michael@0: port.postMessage({topic: "test-flyout-open"}); michael@0: break; michael@0: case "got-flyout-visibility": michael@0: if (e.data.result == "hidden") { michael@0: ok(true, "flyout visibility is 'hidden'"); michael@0: is(panel.state, "closed", "panel really is closed"); michael@0: port.close(); michael@0: next(); michael@0: } else if (e.data.result == "shown") { michael@0: ok(true, "flyout visibility is 'shown"); michael@0: port.postMessage({topic: "test-flyout-close"}); michael@0: } michael@0: break; michael@0: case "got-flyout-message": michael@0: ok(e.data.result == "ok", "got flyout message"); michael@0: break; michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init"}); michael@0: }, michael@0: michael@0: testResizeFlyout: function(next) { michael@0: let panel = document.getElementById("social-flyout-panel"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "test-init-done": michael@0: port.postMessage({topic: "test-flyout-open"}); michael@0: break; michael@0: case "got-flyout-visibility": michael@0: if (e.data.result != "shown") michael@0: return; michael@0: // The width of the flyout should be 400px initially michael@0: let iframe = panel.firstChild; michael@0: let body = iframe.contentDocument.body; michael@0: let cs = iframe.contentWindow.getComputedStyle(body); michael@0: michael@0: is(cs.width, "400px", "should be 400px wide"); michael@0: is(iframe.boxObject.width, 400, "iframe should now be 400px wide"); michael@0: is(cs.height, "400px", "should be 400px high"); michael@0: is(iframe.boxObject.height, 400, "iframe should now be 400px high"); michael@0: michael@0: iframe.contentWindow.addEventListener("resize", function _doneHandler() { michael@0: iframe.contentWindow.removeEventListener("resize", _doneHandler, false); michael@0: cs = iframe.contentWindow.getComputedStyle(body); michael@0: michael@0: is(cs.width, "500px", "should now be 500px wide"); michael@0: is(iframe.boxObject.width, 500, "iframe should now be 500px wide"); michael@0: is(cs.height, "500px", "should now be 500px high"); michael@0: is(iframe.boxObject.height, 500, "iframe should now be 500px high"); michael@0: panel.hidePopup(); michael@0: port.close(); michael@0: next(); michael@0: }, false); michael@0: SocialFlyout.dispatchPanelEvent("socialTest-MakeWider"); michael@0: break; michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init"}); michael@0: }, michael@0: michael@0: testCloseSelf: function(next) { michael@0: // window.close is affected by the pref dom.allow_scripts_to_close_windows, michael@0: // which defaults to false, but is set to true by the test harness. michael@0: // so temporarily set it back. michael@0: const ALLOW_SCRIPTS_TO_CLOSE_PREF = "dom.allow_scripts_to_close_windows"; michael@0: // note clearUserPref doesn't do what we expect, as the test harness itself michael@0: // changes the pref value - so clearUserPref resets it to false rather than michael@0: // the true setup by the test harness. michael@0: let oldAllowScriptsToClose = Services.prefs.getBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF); michael@0: Services.prefs.setBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF, false); michael@0: let panel = document.getElementById("social-flyout-panel"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "test-init-done": michael@0: port.postMessage({topic: "test-flyout-open"}); michael@0: break; michael@0: case "got-flyout-visibility": michael@0: if (e.data.result != "shown") michael@0: return; michael@0: let iframe = panel.firstChild; michael@0: iframe.contentDocument.addEventListener("SocialTest-DoneCloseSelf", function _doneHandler() { michael@0: iframe.contentDocument.removeEventListener("SocialTest-DoneCloseSelf", _doneHandler, false); michael@0: port.close(); michael@0: is(panel.state, "closed", "flyout should have closed itself"); michael@0: Services.prefs.setBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF, oldAllowScriptsToClose); michael@0: next(); michael@0: }, false); michael@0: is(panel.state, "open", "flyout should be open"); michael@0: SocialFlyout.dispatchPanelEvent("socialTest-CloseSelf"); michael@0: break; michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init"}); michael@0: }, michael@0: michael@0: testCloseOnLinkTraversal: function(next) { michael@0: michael@0: function onTabOpen(event) { michael@0: gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); michael@0: waitForCondition(function() { return panel.state == "closed" }, function() { michael@0: gBrowser.removeTab(event.target); michael@0: next(); michael@0: }, "panel should close after tab open"); michael@0: } michael@0: michael@0: let panel = document.getElementById("social-flyout-panel"); michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: port.onmessage = function (e) { michael@0: let topic = e.data.topic; michael@0: switch (topic) { michael@0: case "test-init-done": michael@0: port.postMessage({topic: "test-flyout-open"}); michael@0: break; michael@0: case "got-flyout-visibility": michael@0: if (e.data.result == "shown") { michael@0: // click on our test link michael@0: is(panel.state, "open", "flyout should be open"); michael@0: gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true); michael@0: let iframe = panel.firstChild; michael@0: iframe.contentDocument.getElementById('traversal').click(); michael@0: } michael@0: break; michael@0: } michael@0: } michael@0: port.postMessage({topic: "test-init"}); michael@0: } michael@0: }