summaryrefslogtreecommitdiffstats
path: root/dom/apps/tests/unit/test_moziapplication.js
blob: dbcf2372a3752630c0fe3b55142e865c05a64c51 (plain)
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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

var {classes: Cc, interfaces: Ci, utils: Cu} = Components;

Cu.import("resource:///modules/AppsUtils.jsm");

add_test(() => {
  let app = {
    name: "TestApp",
    csp: "aCsp",
    installOrigin: "http://installorigin.com",
    origin: "http://www.example.com",
    installTime: Date.now(),
    manifestURL: "http://www.example.com/manifest.webapp",
    appStatus: Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED,
    removable: false,
    id: 123,
    localId: 123,
    basePath: "/",
    progress: 1.0,
    installState: "installed",
    downloadAvailable: false,
    downloading: false,
    lastUpdateCheck: Date.now(),
    updateTime: Date.now(),
    etag: "aEtag",
    packageEtag: "aPackageEtag",
    manifestHash: "aManifestHash",
    packageHash: "aPackageHash",
    staged: false,
    installerAppId: 345,
    installerIsBrowser: false,
    storeId: "aStoreId",
    storeVersion: 1,
    role: "aRole",
    kind: "aKind",
    enabled: true,
    sideloaded: false
  };

  let mozapp = new mozIApplication(app);

  Object.keys(app).forEach((key) => {
    if (key == "principal") {
      return;
    }
    Assert.equal(app[key], mozapp[key],
                 "app[" + key + "] should be equal to mozapp[" + key + "]");
  });

  Assert.ok(mozapp.principal, "app principal should exist");
  let expectedPrincipalOrigin = app.origin + "^appId=" + app.localId;
  Assert.equal(mozapp.principal.origin, expectedPrincipalOrigin,
               "app principal origin ok");
  Assert.equal(mozapp.principal.appId, app.localId, "app principal appId ok");
  Assert.equal(mozapp.principal.isInIsolatedMozBrowserElement, false,
               "app principal isInIsolatedMozBrowserElement ok");
  run_next_test();
});

function run_test() {
  run_next_test();
}