DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (dcc6d7a0dc00)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
<!DOCTYPE html>
<html>
<head>
  <title>System messages registration tests</title>
  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
  <script type="application/javascript"
          src="chrome://mochikit/content/chrome-harness.js"></script>
  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1162281}">Mozilla Bug {1162281}</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script class="testbody" type="application/javascript;version=1.7">

const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;

Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");

// We need to keep the same CID as the one used on activities tests.
// Check https://bugzilla.mozilla.org/show_bug.cgi?id=1176712#c13
const SYS_MSG_GLUE_CID = Components.ID("{b0b6b9af-bc4e-4200-bffe-fb7691065ec9}");

XPCOMUtils.defineLazyGetter(this, "messenger", () => {
   return Cc["@mozilla.org/system-message-internal;1"]
   .getService(Ci.nsISystemMessagesInternal);
});

let gRootUrl = "http://test/chrome/dom/messages/test/";
let validAppUrl = gRootUrl + "manifest.webapp";
let invalidAppUrl = gRootUrl + "invalid_manifest.webapp";
let validApp;
let initialAppsCount;
let index = 0;

SimpleTest.waitForExplicitFinish();

function go() {
  SpecialPowers.pushPermissions(
    [{ "type": "webapps-manage", "allow": 1, "context": document },
     { "type": "browser", "allow": 1, "context": document },
     { "type": "embed-apps", "allow": 1, "context": document }],
    function() {
      SpecialPowers.pushPrefEnv(
        {'set': [["dom.mozBrowserFramesEnabled", true],
                 ["dom.sysmsg.enabled", true]]},
        next) });
}

function finish() {
  unregisterComponent(SystemMessageGlue);
  SimpleTest.finish();
}

function next() {
  info("Step " + index);
  if (index >= steps.length) {
    ok(false, "Shouldn't get here!");
    return;
  }
  try {
    let i = index++;
    steps[i]();
  } catch(ex) {
    ok(false, "Caught exception", ex);
  }
}

function cbError(aEvent) {
  ok(false, "Error callback invoked " +
            aEvent.target.error.name + " " + aEvent.target.error.message);
  finish();
}

function uninstall(aApp) {
  info("Uninstalling " + (aApp ? aApp.manifestURL : "NO APP!!"));
}

function registerComponent(aObject, aDescription, aContract) {
  info("Registering " + SYS_MSG_GLUE_CID);

  let componentManager =
    Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
  componentManager.registerFactory(SYS_MSG_GLUE_CID, aDescription, aContract, aObject);
}

function unregisterComponent(aObject) {
  info("Unregistering " + SYS_MSG_GLUE_CID);
  let componentManager =
    Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
  componentManager.unregisterFactory(SYS_MSG_GLUE_CID, aObject);
}

let SystemMessageGlue = {
  // nsISupports implementation.
  QueryInterface: function(iid) {
    if (iid.equals(Ci.nsISupports) ||
        iid.equals(Ci.nsIFactory) ||
        iid.equals(Ci.nsISystemMessageGlue)) {
      return this;
    }

    throw Cr.NS_ERROR_NO_INTERFACE;
  },

  // nsIFactory implementation.
  createInstance: function(outer, iid) {
    return this.QueryInterface(iid);
  },

  _lastManifestURL: null,

  // nsISystemMessageGlue implementation.
  openApp(pageURL, manifestURL, type, target, showApp, onlyShowApp, extra) {
    this._lastManifestURL = manifestURL;
  }
};

registerComponent(SystemMessageGlue,
                  "System Message Glue",
                  "@mozilla.org/dom/messages/system-message-glue;1");

function testBroadcastMessage(aMessage, aExpectedManifestURL, aMsg) {
  SystemMessageGlue._lastManifestURL = null;
  messenger.broadcastMessage(aMessage, {}, {})
  .then(() => {
    is(SystemMessageGlue._lastManifestURL, aExpectedManifestURL, aMsg);
    next();
  })
  .catch(cbError);
}

/**
 * TESTS
 */
let steps = [() => {
  Services.obs.notifyObservers(null, "webapps-registry-ready", null);
  SpecialPowers.setAllAppsLaunchable(true);
  SpecialPowers.autoConfirmAppInstall(next);
}, () => {
  SpecialPowers.autoConfirmAppUninstall(next);
}, () => {
  // Check how many apps we are starting with.
  let request = navigator.mozApps.mgmt.getAll();
  request.onerror = cbError;
  request.onsuccess = () => {
    initialAppsCount = request.result.length;
    info("Starting with " + initialAppsCount + " apps installed.");
    next();
  };
}, () => {
  // We still have not installed any app handling dummy-system-message.
  testBroadcastMessage("dummy-system-message", null,
                       "no system message should be sent");
}, () => {
  testBroadcastMessage("dummy-system-message2", null,
                       "no system message should be sent");
}, () => {
  navigator.mozApps.mgmt.oninstall = ()  => {
    validApp = request.result;
    next();
  };
  let request = navigator.mozApps.install(validAppUrl, { });
  request.error = cbError;
  request.onsuccess = () => {
    validApp = request.result;
  };
}, () => {
  // Installing the test app should register the system message.
  testBroadcastMessage("dummy-system-message", validAppUrl,
                       "system message should be sent");
}, () => {
  // Installing the test app should register the system message.
  testBroadcastMessage("dummy-system-message2", validAppUrl,
                       "system message should be sent");
}, () => {
  navigator.mozApps.mgmt.onuninstall = ()  => {
    validApp = null;
    next();
  };
  let request = navigator.mozApps.mgmt.uninstall(validApp);
  request.onerror = cbError;
}, () => {
  // Uninstalling the app should unregister the system messages.
  testBroadcastMessage("dummy-system-message", null,
                       "no system message should be sent");
}, () => {
  // Uninstalling the app should unregister the system messages.
  testBroadcastMessage("dummy-system-message2", null,
                       "no system message should be sent");
}, () => {
  navigator.mozApps.mgmt.oninstall = ()  => {
    validApp = request.result;
    next();
  };
  let request = navigator.mozApps.install(invalidAppUrl, { });
  request.onerror = () => {
    ok(true, "should not install invalid app");
    next();
  };
  request.onsuccess = () => {
    ok(false, "should not install invalid app");
    finish();
  };
}, () => {
  testBroadcastMessage("dummy-system-message", null,
                       "no system message should be sent");
}, () => {
  testBroadcastMessage("dummy-system-message2", null,
                       "no system message should be sent");
}, () => {
   // Check how many apps we are finishing with.
  let request = navigator.mozApps.mgmt.getAll();
  request.onerror = cbError;
  request.onsuccess = () => {
    info("Finishing with " + request.result.length + " apps installed.");
    is(initialAppsCount, request.result.length, "All apps are uninstalled");
    next();
  };
}, finish];

addLoadEvent(go);

</script>
</pre>
</body>
</html>