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: let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; 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: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: SocialService.addProvider(manifest, function() { michael@0: // the test will remove the provider michael@0: doTest(); michael@0: }); michael@0: } michael@0: michael@0: function doTest() { michael@0: ok(SocialSidebar.canShow, "social sidebar should be able to be shown"); michael@0: ok(!SocialSidebar.opened, "social sidebar should not be open by default"); michael@0: SocialSidebar.show(); michael@0: michael@0: let command = document.getElementById("Social:ToggleSidebar"); michael@0: let sidebar = document.getElementById("social-sidebar-box"); michael@0: let browser = sidebar.lastChild; michael@0: michael@0: function checkShown(shouldBeShown) { michael@0: is(command.getAttribute("checked"), shouldBeShown ? "true" : "false", michael@0: "toggle command should be " + (shouldBeShown ? "checked" : "unchecked")); michael@0: is(sidebar.hidden, !shouldBeShown, michael@0: "sidebar should be " + (shouldBeShown ? "visible" : "hidden")); michael@0: if (shouldBeShown) { michael@0: is(browser.getAttribute('src'), SocialSidebar.provider.sidebarURL, "sidebar url should be set"); michael@0: // We don't currently check docShellIsActive as this is only set michael@0: // after load event fires, and the tests below explicitly wait for this michael@0: // anyway. michael@0: } michael@0: else { michael@0: ok(!browser.docShellIsActive, "sidebar should have an inactive docshell"); michael@0: // sidebar will only be immediately unloaded (and thus set to michael@0: // about:blank) when canShow is false. michael@0: if (SocialSidebar.canShow) { michael@0: // should not have unloaded so will still be the provider URL. michael@0: is(browser.getAttribute('src'), SocialSidebar.provider.sidebarURL, "sidebar url should be set"); michael@0: } else { michael@0: // should have been an immediate unload. michael@0: is(browser.getAttribute('src'), "about:blank", "sidebar url should be blank"); michael@0: } michael@0: } michael@0: } michael@0: michael@0: // First check the the sidebar is initially visible, and loaded michael@0: ok(!command.hidden, "toggle command should be visible"); michael@0: checkShown(true); michael@0: michael@0: browser.addEventListener("socialFrameHide", function sidebarhide() { michael@0: browser.removeEventListener("socialFrameHide", sidebarhide); michael@0: michael@0: checkShown(false); michael@0: michael@0: browser.addEventListener("socialFrameShow", function sidebarshow() { michael@0: browser.removeEventListener("socialFrameShow", sidebarshow); michael@0: michael@0: checkShown(true); michael@0: michael@0: // disable social. michael@0: SocialService.removeProvider(SocialSidebar.provider.origin, function() { michael@0: checkShown(false); michael@0: is(Social.providers.length, 0, "no providers left"); michael@0: defaultFinishChecks(); michael@0: // Finish the test michael@0: executeSoon(finish); michael@0: }); michael@0: }); michael@0: michael@0: // Toggle it back on michael@0: info("Toggling sidebar back on"); michael@0: SocialSidebar.toggleSidebar(); michael@0: }); michael@0: michael@0: // use port messaging to ensure that the sidebar is both loaded and michael@0: // ready before we run other tests michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: port.postMessage({topic: "test-init"}); 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: ok(true, "sidebar is loaded and ready"); michael@0: SocialSidebar.toggleSidebar(); michael@0: } michael@0: }; michael@0: }