summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpinstall/browser_navigateaway3.js
blob: 7f55a65feab12c8017a5e0ea16941d83b09f4830 (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
65
66
67
68
69
70
71
72
73
74
75
// ----------------------------------------------------------------------------
// Tests that navigating to a new origin cancels ongoing installs.

// Block the modal install UI from showing.
let InstallPrompt = {
  confirm: function(aBrowser, aUri, aInstalls, aCount) {
  },

  QueryInterface: XPCOMUtils.generateQI([Ci.amIWebInstallPrompt]),

  classID: Components.ID("{405f3c55-241f-40df-97f1-a6e60e250ec5}"),

  factory: {
    registrar: Components.manager.QueryInterface(Ci.nsIComponentRegistrar),

    register: function() {
      this.registrar.registerFactory(InstallPrompt.classID, "InstallPrompt",
                                     "@mozilla.org/addons/web-install-prompt;1",
                                     this);
    },

    unregister: function() {
      this.registrar.unregisterFactory(InstallPrompt.classID, this);
    },

    // nsIFactory
    createInstance: function(aOuter, aIID) {
      if (aOuter) {
        throw Components.Exception("Class does not allow aggregation",
                                   Components.results.NS_ERROR_NO_AGGREGATION);
      }
      return InstallPrompt.QueryInterface(aIID);
    },

    QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory])
  }
};

function test() {
  InstallPrompt.factory.register();
  registerCleanupFunction(() => {
    InstallPrompt.factory.unregister();
  });

  Harness.downloadProgressCallback = download_progress;
  Harness.installEndedCallback = install_ended;
  Harness.installsCompletedCallback = finish_test;
  Harness.setup();

  var pm = Services.perms;
  pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);

  var triggers = encodeURIComponent(JSON.stringify({
    "Unsigned XPI": TESTROOT + "unsigned.xpi"
  }));
  gBrowser.selectedTab = gBrowser.addTab();
  gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
}

function download_progress(addon, value, maxValue) {
  gBrowser.loadURI(TESTROOT2 + "enabled.html");
}

function install_ended(install, addon) {
  ok(false, "Should not have seen installs complete");
}

function finish_test(count) {
  is(count, 0, "No add-ons should have been successfully installed");

  Services.perms.remove("http://example.com", "install");

  gBrowser.removeCurrentTab();
  Harness.finish();
}