toolkit/components/social/test/browser/worker_social.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/social/test/browser/worker_social.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     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 +// apiPort is our port to WorkerAPI
     1.9 +let apiPort;
    1.10 +// testerPort is whatever port a test calls us on
    1.11 +let testerPort;
    1.12 +
    1.13 +onconnect = function(e) {
    1.14 +  // assume this is a test connecting, but if we get
    1.15 +  // social.initialize, we know it is our WorkerAPI
    1.16 +  // instance connecting and we'll set apiPort
    1.17 +  let port = e.ports[0];
    1.18 +  port.onmessage = function onMessage(event) {
    1.19 +    let {topic, data} = event.data;
    1.20 +    switch (topic) {
    1.21 +      case "social.initialize":
    1.22 +        apiPort = port;
    1.23 +        break;
    1.24 +      case "test-initialization":
    1.25 +        testerPort = port;
    1.26 +        port.postMessage({topic: "test-initialization-complete"});
    1.27 +        break;
    1.28 +      case "test-profile":
    1.29 +        apiPort.postMessage({topic: "social.user-profile", data: data});
    1.30 +        break;
    1.31 +      case "test-ambient":
    1.32 +        apiPort.postMessage({topic: "social.ambient-notification", data: data});
    1.33 +        break;
    1.34 +      case "test.cookies-get":
    1.35 +        apiPort.postMessage({topic: "social.cookies-get"});
    1.36 +        break;
    1.37 +      case "social.cookies-get-response":
    1.38 +        testerPort.postMessage({topic: "test.cookies-get-response", data: data});
    1.39 +        break;
    1.40 +      case "test-reload-init":
    1.41 +        apiPort.postMessage({topic: 'social.reload-worker'});
    1.42 +        break;
    1.43 +      case "test-notification-create":
    1.44 +        apiPort.postMessage({topic: 'social.notification-create',
    1.45 +                             data: data});
    1.46 +        testerPort.postMessage({topic: 'did-notification-create'});
    1.47 +        break;
    1.48 +      case "test-indexeddb-create":
    1.49 +        var request = indexedDB.open("workerdb", 1);
    1.50 +        request.onerror = function(event) {
    1.51 +          port.postMessage({topic: 'social.indexeddb-result', data: { result: "error" }});
    1.52 +        };
    1.53 +        request.onsuccess = function(event) {
    1.54 +          // Do something with request.result!
    1.55 +          var db = request.result;
    1.56 +          db.close();
    1.57 +          port.postMessage({topic: 'social.indexeddb-result', data: { result: "ok" }});
    1.58 +        };
    1.59 +        break;
    1.60 +    }
    1.61 +  }
    1.62 +}

mercurial