browser/base/content/test/social/browser_social_multiworker.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 function test() {
     6   waitForExplicitFinish();
     8   runSocialTestWithProvider(gProviders, function (finishcb) {
     9     runSocialTests(tests, undefined, undefined, function() {
    10       finishcb();
    11     });
    12   });
    13 }
    15 let gProviders = [
    16   {
    17     name: "provider 1",
    18     origin: "https://example.com",
    19     sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html?provider1",
    20     workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
    21     iconURL: "chrome://branding/content/icon48.png"
    22   },
    23   {
    24     name: "provider 2",
    25     origin: "https://test1.example.com",
    26     sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?provider2",
    27     workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js",
    28     iconURL: "chrome://branding/content/icon48.png"
    29   }
    30 ];
    32 var tests = {
    33   testWorkersAlive: function(next) {
    34     // verify we can get a message from all providers that are enabled
    35     let messageReceived = 0;
    36     function oneWorkerTest(provider) {
    37       let port = provider.getWorkerPort();
    38       port.onmessage = function (e) {
    39         let topic = e.data.topic;
    40         switch (topic) {
    41           case "test-init-done":
    42             ok(true, "got message from provider " + provider.name);
    43             port.close();
    44             messageReceived++;
    45             break;
    46         }
    47       };
    48       port.postMessage({topic: "test-init"});
    49     }
    51     for (let p of Social.providers) {
    52       oneWorkerTest(p);
    53     }
    55     waitForCondition(function() messageReceived == Social.providers.length,
    56                      next, "received messages from all workers");
    57   },
    59    testMultipleWorkerEnabling: function(next) {
    60      // test that all workers are enabled when we allow multiple workers
    61      for (let p of Social.providers) {
    62        ok(p.enabled, "provider enabled");
    63        let port = p.getWorkerPort();
    64        ok(port, "worker enabled");
    65        port.close();
    66      }
    67      next();
    68    }
    69 }

mercurial