1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/social/browser_social_status.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; 1.9 + 1.10 +let manifest = { // builtin provider 1.11 + name: "provider example.com", 1.12 + origin: "https://example.com", 1.13 + sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", 1.14 + workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", 1.15 + iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" 1.16 +}; 1.17 +let manifest2 = { // used for testing install 1.18 + name: "provider test1", 1.19 + origin: "https://test1.example.com", 1.20 + workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", 1.21 + statusURL: "https://test1.example.com/browser/browser/base/content/test/social/social_panel.html", 1.22 + iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png", 1.23 + version: 1 1.24 +}; 1.25 +let manifest3 = { // used for testing install 1.26 + name: "provider test2", 1.27 + origin: "https://test2.example.com", 1.28 + sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html", 1.29 + iconURL: "https://test2.example.com/browser/browser/base/content/test/general/moz.png", 1.30 + version: 1 1.31 +}; 1.32 + 1.33 + 1.34 +function openWindowAndWaitForInit(callback) { 1.35 + let topic = "browser-delayed-startup-finished"; 1.36 + let w = OpenBrowserWindow(); 1.37 + Services.obs.addObserver(function providerSet(subject, topic, data) { 1.38 + Services.obs.removeObserver(providerSet, topic); 1.39 + executeSoon(() => callback(w)); 1.40 + }, topic, false); 1.41 +} 1.42 + 1.43 +function test() { 1.44 + waitForExplicitFinish(); 1.45 + 1.46 + runSocialTestWithProvider(manifest, function (finishcb) { 1.47 + runSocialTests(tests, undefined, undefined, function () { 1.48 + Services.prefs.clearUserPref("social.remote-install.enabled"); 1.49 + // just in case the tests failed, clear these here as well 1.50 + Services.prefs.clearUserPref("social.whitelist"); 1.51 + ok(CustomizableUI.inDefaultState, "Should be in the default state when we finish"); 1.52 + CustomizableUI.reset(); 1.53 + finishcb(); 1.54 + }); 1.55 + }); 1.56 +} 1.57 + 1.58 +var tests = { 1.59 + testNoButtonOnEnable: function(next) { 1.60 + // we expect the addon install dialog to appear, we need to accept the 1.61 + // install from the dialog. 1.62 + let panel = document.getElementById("servicesInstall-notification"); 1.63 + PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { 1.64 + PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); 1.65 + info("servicesInstall-notification panel opened"); 1.66 + panel.button.click(); 1.67 + }) 1.68 + 1.69 + let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html" 1.70 + addTab(activationURL, function(tab) { 1.71 + let doc = tab.linkedBrowser.contentDocument; 1.72 + Social.installProvider(doc, manifest3, function(addonManifest) { 1.73 + // enable the provider so we know the button would have appeared 1.74 + SocialService.addBuiltinProvider(manifest3.origin, function(provider) { 1.75 + is(provider.origin, manifest3.origin, "provider is installed"); 1.76 + let id = SocialStatus._toolbarHelper.idFromOrigin(provider.origin); 1.77 + let widget = CustomizableUI.getWidget(id); 1.78 + ok(!widget || !widget.forWindow(window).node, "no button added to widget set"); 1.79 + Social.uninstallProvider(manifest3.origin, function() { 1.80 + gBrowser.removeTab(tab); 1.81 + next(); 1.82 + }); 1.83 + }); 1.84 + }); 1.85 + }); 1.86 + }, 1.87 + testButtonOnEnable: function(next) { 1.88 + let panel = document.getElementById("servicesInstall-notification"); 1.89 + PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { 1.90 + PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); 1.91 + info("servicesInstall-notification panel opened"); 1.92 + panel.button.click(); 1.93 + }); 1.94 + 1.95 + // enable the provider now 1.96 + let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" 1.97 + addTab(activationURL, function(tab) { 1.98 + let doc = tab.linkedBrowser.contentDocument; 1.99 + Social.installProvider(doc, manifest2, function(addonManifest) { 1.100 + SocialService.addBuiltinProvider(manifest2.origin, function(provider) { 1.101 + is(provider.origin, manifest2.origin, "provider is installed"); 1.102 + let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); 1.103 + let widget = CustomizableUI.getWidget(id).forWindow(window); 1.104 + ok(widget.node, "button added to widget set"); 1.105 + checkSocialUI(window); 1.106 + gBrowser.removeTab(tab); 1.107 + next(); 1.108 + }); 1.109 + }); 1.110 + }); 1.111 + }, 1.112 + testStatusPanel: function(next) { 1.113 + let icon = { 1.114 + name: "testIcon", 1.115 + iconURL: "chrome://browser/skin/Info.png", 1.116 + counter: 1 1.117 + }; 1.118 + // click on panel to open and wait for visibility 1.119 + let provider = Social._getProviderFromOrigin(manifest2.origin); 1.120 + let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); 1.121 + let widget = CustomizableUI.getWidget(id); 1.122 + let btn = widget.forWindow(window).node; 1.123 + ok(btn, "got a status button"); 1.124 + let port = provider.getWorkerPort(); 1.125 + 1.126 + port.onmessage = function (e) { 1.127 + let topic = e.data.topic; 1.128 + switch (topic) { 1.129 + case "test-init-done": 1.130 + ok(true, "test-init-done received"); 1.131 + ok(provider.profile.userName, "profile was set by test worker"); 1.132 + btn.click(); 1.133 + break; 1.134 + case "got-social-panel-visibility": 1.135 + ok(true, "got the panel message " + e.data.result); 1.136 + if (e.data.result == "shown") { 1.137 + let panel = document.getElementById("social-notification-panel"); 1.138 + panel.hidePopup(); 1.139 + } else { 1.140 + port.postMessage({topic: "test-ambient-notification", data: icon}); 1.141 + port.close(); 1.142 + waitForCondition(function() { return btn.getAttribute("badge"); }, 1.143 + function() { 1.144 + is(btn.style.listStyleImage, "url(\"" + icon.iconURL + "\")", "notification icon updated"); 1.145 + next(); 1.146 + }, "button updated by notification"); 1.147 + } 1.148 + break; 1.149 + } 1.150 + }; 1.151 + port.postMessage({topic: "test-init"}); 1.152 + }, 1.153 + testButtonOnDisable: function(next) { 1.154 + // enable the provider now 1.155 + let provider = Social._getProviderFromOrigin(manifest2.origin); 1.156 + ok(provider, "provider is installed"); 1.157 + SocialService.removeProvider(manifest2.origin, function() { 1.158 + let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); 1.159 + waitForCondition(function() { return !document.getElementById(id) }, 1.160 + function() { 1.161 + Social.uninstallProvider(manifest2.origin, next); 1.162 + }, "button does not exist after disabling the provider"); 1.163 + }); 1.164 + } 1.165 +}