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 = { // builtin provider michael@0: name: "provider example.com", 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: let manifest2 = { // used for testing install michael@0: name: "provider test1", michael@0: origin: "https://test1.example.com", michael@0: workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", michael@0: statusURL: "https://test1.example.com/browser/browser/base/content/test/social/social_panel.html", michael@0: iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png", michael@0: version: 1 michael@0: }; michael@0: let manifest3 = { // used for testing install michael@0: name: "provider test2", michael@0: origin: "https://test2.example.com", michael@0: sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html", michael@0: iconURL: "https://test2.example.com/browser/browser/base/content/test/general/moz.png", michael@0: version: 1 michael@0: }; michael@0: michael@0: michael@0: function openWindowAndWaitForInit(callback) { michael@0: let topic = "browser-delayed-startup-finished"; michael@0: let w = OpenBrowserWindow(); michael@0: Services.obs.addObserver(function providerSet(subject, topic, data) { michael@0: Services.obs.removeObserver(providerSet, topic); michael@0: executeSoon(() => callback(w)); michael@0: }, topic, false); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: runSocialTestWithProvider(manifest, function (finishcb) { michael@0: runSocialTests(tests, undefined, undefined, function () { michael@0: Services.prefs.clearUserPref("social.remote-install.enabled"); michael@0: // just in case the tests failed, clear these here as well michael@0: Services.prefs.clearUserPref("social.whitelist"); michael@0: ok(CustomizableUI.inDefaultState, "Should be in the default state when we finish"); michael@0: CustomizableUI.reset(); michael@0: finishcb(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: var tests = { michael@0: testNoButtonOnEnable: function(next) { michael@0: // we expect the addon install dialog to appear, we need to accept the michael@0: // install from the dialog. michael@0: let panel = document.getElementById("servicesInstall-notification"); michael@0: PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { michael@0: PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); michael@0: info("servicesInstall-notification panel opened"); michael@0: panel.button.click(); michael@0: }) michael@0: michael@0: let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html" michael@0: addTab(activationURL, function(tab) { michael@0: let doc = tab.linkedBrowser.contentDocument; michael@0: Social.installProvider(doc, manifest3, function(addonManifest) { michael@0: // enable the provider so we know the button would have appeared michael@0: SocialService.addBuiltinProvider(manifest3.origin, function(provider) { michael@0: is(provider.origin, manifest3.origin, "provider is installed"); michael@0: let id = SocialStatus._toolbarHelper.idFromOrigin(provider.origin); michael@0: let widget = CustomizableUI.getWidget(id); michael@0: ok(!widget || !widget.forWindow(window).node, "no button added to widget set"); michael@0: Social.uninstallProvider(manifest3.origin, function() { michael@0: gBrowser.removeTab(tab); michael@0: next(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: }, michael@0: testButtonOnEnable: function(next) { michael@0: let panel = document.getElementById("servicesInstall-notification"); michael@0: PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { michael@0: PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); michael@0: info("servicesInstall-notification panel opened"); michael@0: panel.button.click(); michael@0: }); michael@0: michael@0: // enable the provider now michael@0: let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" michael@0: addTab(activationURL, function(tab) { michael@0: let doc = tab.linkedBrowser.contentDocument; michael@0: Social.installProvider(doc, manifest2, function(addonManifest) { michael@0: SocialService.addBuiltinProvider(manifest2.origin, function(provider) { michael@0: is(provider.origin, manifest2.origin, "provider is installed"); michael@0: let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); michael@0: let widget = CustomizableUI.getWidget(id).forWindow(window); michael@0: ok(widget.node, "button added to widget set"); michael@0: checkSocialUI(window); michael@0: gBrowser.removeTab(tab); michael@0: next(); michael@0: }); michael@0: }); michael@0: }); michael@0: }, michael@0: testStatusPanel: function(next) { michael@0: let icon = { michael@0: name: "testIcon", michael@0: iconURL: "chrome://browser/skin/Info.png", michael@0: counter: 1 michael@0: }; michael@0: // click on panel to open and wait for visibility michael@0: let provider = Social._getProviderFromOrigin(manifest2.origin); michael@0: let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); michael@0: let widget = CustomizableUI.getWidget(id); michael@0: let btn = widget.forWindow(window).node; michael@0: ok(btn, "got a status button"); michael@0: let port = provider.getWorkerPort(); michael@0: 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: ok(true, "test-init-done received"); michael@0: ok(provider.profile.userName, "profile was set by test worker"); michael@0: btn.click(); michael@0: break; michael@0: case "got-social-panel-visibility": michael@0: ok(true, "got the panel message " + e.data.result); michael@0: if (e.data.result == "shown") { michael@0: let panel = document.getElementById("social-notification-panel"); michael@0: panel.hidePopup(); michael@0: } else { michael@0: port.postMessage({topic: "test-ambient-notification", data: icon}); michael@0: port.close(); michael@0: waitForCondition(function() { return btn.getAttribute("badge"); }, michael@0: function() { michael@0: is(btn.style.listStyleImage, "url(\"" + icon.iconURL + "\")", "notification icon updated"); michael@0: next(); michael@0: }, "button updated by notification"); michael@0: } michael@0: break; michael@0: } michael@0: }; michael@0: port.postMessage({topic: "test-init"}); michael@0: }, michael@0: testButtonOnDisable: function(next) { michael@0: // enable the provider now michael@0: let provider = Social._getProviderFromOrigin(manifest2.origin); michael@0: ok(provider, "provider is installed"); michael@0: SocialService.removeProvider(manifest2.origin, function() { michael@0: let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); michael@0: waitForCondition(function() { return !document.getElementById(id) }, michael@0: function() { michael@0: Social.uninstallProvider(manifest2.origin, next); michael@0: }, "button does not exist after disabling the provider"); michael@0: }); michael@0: } michael@0: }