dom/indexedDB/test/extensions/bootstrap.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/test/extensions/bootstrap.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/**
     1.5 + * Any copyright is dedicated to the Public Domain.
     1.6 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.7 + */
     1.8 +
     1.9 +const Ci = Components.interfaces;
    1.10 +const Cu = Components.utils;
    1.11 +
    1.12 +Cu.import("resource://gre/modules/Services.jsm");
    1.13 +Cu.import("resource://gre/modules/XPCOMUtils.jsm");
    1.14 +
    1.15 +function testForExpectedSymbols(stage, data) {
    1.16 +  const expectedSymbols = [ "IDBKeyRange", "indexedDB" ];
    1.17 +  for each (var symbol in expectedSymbols) {
    1.18 +    Services.prefs.setBoolPref("indexeddbtest.bootstrap." + stage + "." +
    1.19 +                               symbol, symbol in this);
    1.20 +  }
    1.21 +}
    1.22 +
    1.23 +function GlobalObjectsComponent() {
    1.24 +  this.wrappedJSObject = this;
    1.25 +}
    1.26 +
    1.27 +GlobalObjectsComponent.prototype =
    1.28 +{
    1.29 +  QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports]),
    1.30 +
    1.31 +  runTest: function() {
    1.32 +    const name = "Splendid Test";
    1.33 +
    1.34 +    let ok = this.ok;
    1.35 +    let finishTest = this.finishTest;
    1.36 +
    1.37 +    let keyRange = IDBKeyRange.only(42);
    1.38 +    ok(keyRange, "Got keyRange");
    1.39 +
    1.40 +    let request = indexedDB.open(name, 1);
    1.41 +    request.onerror = function(event) {
    1.42 +      ok(false, "indexedDB error, '" + event.target.error.name + "'");
    1.43 +      finishTest();
    1.44 +    }
    1.45 +    request.onsuccess = function(event) {
    1.46 +      let db = event.target.result;
    1.47 +      ok(db, "Got database");
    1.48 +      finishTest();
    1.49 +    }
    1.50 +  }
    1.51 +};
    1.52 +
    1.53 +var gFactory = {
    1.54 +  register: function() {
    1.55 +    var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
    1.56 +
    1.57 +    var classID = Components.ID("{d6f85dcb-537d-447e-b783-75d4b405622d}");
    1.58 +    var description = "IndexedDBTest";
    1.59 +    var contractID = "@mozilla.org/dom/indexeddb/GlobalObjectsComponent;1";
    1.60 +    var factory = XPCOMUtils._getFactory(GlobalObjectsComponent);
    1.61 +
    1.62 +    registrar.registerFactory(classID, description, contractID, factory);
    1.63 +
    1.64 +    this.unregister = function() {
    1.65 +      registrar.unregisterFactory(classID, factory);
    1.66 +      delete this.unregister;
    1.67 +    };
    1.68 +  }
    1.69 +};
    1.70 +
    1.71 +function install(data, reason) {
    1.72 +  testForExpectedSymbols("install");
    1.73 +}
    1.74 +
    1.75 +function startup(data, reason) {
    1.76 +  testForExpectedSymbols("startup");
    1.77 +  gFactory.register();
    1.78 +}
    1.79 +
    1.80 +function shutdown(data, reason) {
    1.81 +  testForExpectedSymbols("shutdown");
    1.82 +  gFactory.unregister();
    1.83 +}
    1.84 +
    1.85 +function uninstall(data, reason) {
    1.86 +  testForExpectedSymbols("uninstall");
    1.87 +}

mercurial