1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/social/browser_social_multiworker.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,69 @@ 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 +function test() { 1.9 + waitForExplicitFinish(); 1.10 + 1.11 + runSocialTestWithProvider(gProviders, function (finishcb) { 1.12 + runSocialTests(tests, undefined, undefined, function() { 1.13 + finishcb(); 1.14 + }); 1.15 + }); 1.16 +} 1.17 + 1.18 +let gProviders = [ 1.19 + { 1.20 + name: "provider 1", 1.21 + origin: "https://example.com", 1.22 + sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html?provider1", 1.23 + workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", 1.24 + iconURL: "chrome://branding/content/icon48.png" 1.25 + }, 1.26 + { 1.27 + name: "provider 2", 1.28 + origin: "https://test1.example.com", 1.29 + sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?provider2", 1.30 + workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", 1.31 + iconURL: "chrome://branding/content/icon48.png" 1.32 + } 1.33 +]; 1.34 + 1.35 +var tests = { 1.36 + testWorkersAlive: function(next) { 1.37 + // verify we can get a message from all providers that are enabled 1.38 + let messageReceived = 0; 1.39 + function oneWorkerTest(provider) { 1.40 + let port = provider.getWorkerPort(); 1.41 + port.onmessage = function (e) { 1.42 + let topic = e.data.topic; 1.43 + switch (topic) { 1.44 + case "test-init-done": 1.45 + ok(true, "got message from provider " + provider.name); 1.46 + port.close(); 1.47 + messageReceived++; 1.48 + break; 1.49 + } 1.50 + }; 1.51 + port.postMessage({topic: "test-init"}); 1.52 + } 1.53 + 1.54 + for (let p of Social.providers) { 1.55 + oneWorkerTest(p); 1.56 + } 1.57 + 1.58 + waitForCondition(function() messageReceived == Social.providers.length, 1.59 + next, "received messages from all workers"); 1.60 + }, 1.61 + 1.62 + testMultipleWorkerEnabling: function(next) { 1.63 + // test that all workers are enabled when we allow multiple workers 1.64 + for (let p of Social.providers) { 1.65 + ok(p.enabled, "provider enabled"); 1.66 + let port = p.getWorkerPort(); 1.67 + ok(port, "worker enabled"); 1.68 + port.close(); 1.69 + } 1.70 + next(); 1.71 + } 1.72 +}