CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / xpinstall / tests / browser_cancel.js
blob54d633332231a5d57712948802f97fd9a920c637
1 // Load in the test harness
2 var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
3 .getService(Components.interfaces.mozIJSSubScriptLoader);
5 var rootDir = getRootDirectory(window.location.href);
6 scriptLoader.loadSubScript(rootDir + "harness.js", this);
8 // ----------------------------------------------------------------------------
9 // Tests that cancelling an in progress download works.
10 var gManager = null;
12 function test() {
13 waitForExplicitFinish();
14 gManager = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
15 .createInstance(Components.interfaces.nsIXPInstallManager);
16 gManager.initManagerFromChrome([ TESTROOT + "unsigned.xpi" ],
17 1, listener);
20 function finish_test() {
21 finish();
24 var listener = {
25 onStateChange: function(index, state, value) {
26 is(index, 0, "There is only one download");
27 if (state == Components.interfaces.nsIXPIProgressDialog.INSTALL_DONE)
28 is(value, -210, "Install should have been cancelled");
29 else if (state == Components.interfaces.nsIXPIProgressDialog.DIALOG_CLOSE)
30 finish_test();
33 onProgress: function(index, value, maxValue) {
34 is(index, 0, "There is only one download");
35 gManager.QueryInterface(Components.interfaces.nsIObserver);
36 gManager.observe(null, "xpinstall-progress", "cancel");
39 QueryInterface: function(iid) {
40 if (iid.equals(Components.interfaces.nsIXPIProgressDialog) ||
41 iid.equals(Components.interfaces.nsISupports))
42 return this;
44 throw Components.results.NS_ERROR_NO_INTERFACE;
47 // ----------------------------------------------------------------------------