mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 474763: Add automated tests for xpinstall. r=bsmedberg
This commit is contained in:
parent
c659094670
commit
00547d3739
@ -50,4 +50,8 @@ include $(DEPTH)/config/autoconf.mk
|
||||
MODULE = xpinstall
|
||||
DIRS = public src
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
99
xpinstall/tests/Makefile.in
Normal file
99
xpinstall/tests/Makefile.in
Normal file
@ -0,0 +1,99 @@
|
||||
# ***** BEGIN LICENSE BLOCK *****
|
||||
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public License Version
|
||||
# 1.1 (the "License"); you may not use this file except in compliance with
|
||||
# the License. You may obtain a copy of the License at
|
||||
# http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
# for the specific language governing rights and limitations under the
|
||||
# License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Mozilla Foundation.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2008
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the terms of
|
||||
# either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
# in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
# of those above. If you wish to allow use of your version of this file only
|
||||
# under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
# use your version of this file under the terms of the MPL, indicate your
|
||||
# decision by deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this file under
|
||||
# the terms of any one of the MPL, the GPL or the LGPL.
|
||||
#
|
||||
# ***** END LICENSE BLOCK *****
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
relativesrcdir = xpinstall/tests
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_BROWSER_FILES = harness.js \
|
||||
browser_unsigned_url.js \
|
||||
browser_unsigned_trigger.js \
|
||||
browser_whitelist.js \
|
||||
browser_whitelist2.js \
|
||||
browser_whitelist3.js \
|
||||
browser_whitelist4.js \
|
||||
browser_whitelist5.js \
|
||||
browser_whitelist6.js \
|
||||
browser_hash.js \
|
||||
browser_badhash.js \
|
||||
browser_badhashtype.js \
|
||||
browser_signed_url.js \
|
||||
browser_signed_trigger.js \
|
||||
browser_signed_untrusted.js \
|
||||
browser_signed_tampered.js \
|
||||
browser_signed_multiple.js \
|
||||
browser_empty.js \
|
||||
browser_corrupt.js \
|
||||
browser_cookies.js \
|
||||
browser_cookies2.js \
|
||||
browser_cookies3.js \
|
||||
browser_cookies4.js \
|
||||
browser_enabled.js \
|
||||
browser_enabled2.js \
|
||||
browser_enabled3.js \
|
||||
browser_softwareupdate.js \
|
||||
browser_installchrome.js \
|
||||
browser_opendialog.js \
|
||||
browser_localfile.js \
|
||||
browser_localfile2.js \
|
||||
browser_auth.js \
|
||||
browser_auth2.js \
|
||||
browser_auth3.js \
|
||||
browser_offline.js \
|
||||
browser_chrome.js \
|
||||
browser_cancel.js \
|
||||
unsigned.xpi \
|
||||
signed.xpi \
|
||||
signed2.xpi \
|
||||
signed-untrusted.xpi \
|
||||
signed-tampered.xpi \
|
||||
empty.xpi \
|
||||
corrupt.xpi \
|
||||
enabled.html \
|
||||
installtrigger.html \
|
||||
startsoftwareupdate.html \
|
||||
installchrome.html \
|
||||
authRedirect.sjs \
|
||||
cookieRedirect.sjs \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_BROWSER_FILES)
|
||||
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
|
21
xpinstall/tests/authRedirect.sjs
Normal file
21
xpinstall/tests/authRedirect.sjs
Normal file
@ -0,0 +1,21 @@
|
||||
// Simple script redirects to the query part of the uri if the browser
|
||||
// authenticates with username "testuser" password "testpass"
|
||||
|
||||
function handleRequest(request, response) {
|
||||
if (request.hasHeader("Authorization")) {
|
||||
if (request.getHeader("Authorization") == "Basic dGVzdHVzZXI6dGVzdHBhc3M=") {
|
||||
response.setStatusLine(request.httpVersion, 302, "Found");
|
||||
response.setHeader("Location", request.queryString);
|
||||
response.write("See " + request.queryString);
|
||||
}
|
||||
else {
|
||||
response.setStatusLine(request.httpVersion, 403, "Forbidden");
|
||||
response.write("Invalid credentials");
|
||||
}
|
||||
}
|
||||
else {
|
||||
response.setStatusLine(request.httpVersion, 401, "Authentication required");
|
||||
response.setHeader("WWW-Authenticate", "basic realm=\"XPInstall\"", false);
|
||||
response.write("Unauthenticed request");
|
||||
}
|
||||
}
|
50
xpinstall/tests/browser_auth.js
Normal file
50
xpinstall/tests/browser_auth.js
Normal file
@ -0,0 +1,50 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install succeeds when authentication is required
|
||||
// This verifies bug 312473
|
||||
function test() {
|
||||
Harness.authenticationCallback = get_auth_info;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function get_auth_info() {
|
||||
return [ "testuser", "testpass" ];
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
|
||||
.getService(Components.interfaces.nsIHttpAuthManager);
|
||||
authMgr.clearAll();
|
||||
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
47
xpinstall/tests/browser_auth2.js
Normal file
47
xpinstall/tests/browser_auth2.js
Normal file
@ -0,0 +1,47 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install fails when authentication is required and bad
|
||||
// credentials are given
|
||||
// This verifies bug 312473
|
||||
function test() {
|
||||
Harness.authenticationCallback = get_auth_info;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function get_auth_info() {
|
||||
return [ "baduser", "badpass" ];
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -228, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
|
||||
.getService(Components.interfaces.nsIHttpAuthManager);
|
||||
authMgr.clearAll();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
47
xpinstall/tests/browser_auth3.js
Normal file
47
xpinstall/tests/browser_auth3.js
Normal file
@ -0,0 +1,47 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install fails when authentication is required and it is
|
||||
// canceled
|
||||
// This verifies bug 312473
|
||||
function test() {
|
||||
Harness.authenticationCallback = get_auth_info;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": TESTROOT + "authRedirect.sjs?" + TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function get_auth_info() {
|
||||
return null;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -228, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1']
|
||||
.getService(Components.interfaces.nsIHttpAuthManager);
|
||||
authMgr.clearAll();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
41
xpinstall/tests/browser_badhash.js
Normal file
41
xpinstall/tests/browser_badhash.js
Normal file
@ -0,0 +1,41 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install fails when an invalid hash is included
|
||||
// This verifies bug 302284
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": {
|
||||
URL: TESTROOT + "unsigned.xpi",
|
||||
Hash: "sha1:643b08418599ddbd1ea8a511c90696578fb844b9",
|
||||
toString: function() { return this.URL; }
|
||||
}
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -261, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
41
xpinstall/tests/browser_badhashtype.js
Normal file
41
xpinstall/tests/browser_badhashtype.js
Normal file
@ -0,0 +1,41 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install fails when an unknown hash type is included
|
||||
// This verifies bug 302284
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": {
|
||||
URL: TESTROOT + "unsigned.xpi",
|
||||
Hash: "foo:3d0dc22e1f394e159b08aaf5f0f97de4d5c65f4f",
|
||||
toString: function() { return this.URL; }
|
||||
}
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -261, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
45
xpinstall/tests/browser_cancel.js
Normal file
45
xpinstall/tests/browser_cancel.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests that cancelling an in progress download works.
|
||||
var gManager = null;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
gManager = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
|
||||
.createInstance(Components.interfaces.nsIXPInstallManager);
|
||||
gManager.initManagerFromChrome([ TESTROOT + "unsigned.xpi" ],
|
||||
1, listener);
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
finish();
|
||||
}
|
||||
|
||||
var listener = {
|
||||
onStateChange: function(index, state, value) {
|
||||
is(index, 0, "There is only one download");
|
||||
if (state == Components.interfaces.nsIXPIProgressDialog.INSTALL_DONE)
|
||||
is(value, -210, "Install should have been cancelled");
|
||||
else if (state == Components.interfaces.nsIXPIProgressDialog.DIALOG_CLOSE)
|
||||
finish_test();
|
||||
},
|
||||
|
||||
onProgress: function(index, value, maxValue) {
|
||||
is(index, 0, "There is only one download");
|
||||
gManager.QueryInterface(Components.interfaces.nsIObserver);
|
||||
gManager.observe(null, "xpinstall-progress", "cancel");
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIXPIProgressDialog) ||
|
||||
iid.equals(Components.interfaces.nsISupports))
|
||||
return this;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
// ----------------------------------------------------------------------------
|
45
xpinstall/tests/browser_chrome.js
Normal file
45
xpinstall/tests/browser_chrome.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests that starting a download from chrome works and bypasses the whitelist
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
var xpimgr = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
|
||||
.createInstance(Components.interfaces.nsIXPInstallManager);
|
||||
xpimgr.initManagerFromChrome([ TESTROOT + "unsigned.xpi" ],
|
||||
1, listener);
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
var listener = {
|
||||
onStateChange: function(index, state, value) {
|
||||
is(index, 0, "There is only one download");
|
||||
if (state == Components.interfaces.nsIXPIProgressDialog.INSTALL_DONE)
|
||||
is(value, 0, "Install should have succeeded");
|
||||
else if (state == Components.interfaces.nsIXPIProgressDialog.DIALOG_CLOSE)
|
||||
finish_test();
|
||||
},
|
||||
|
||||
onProgress: function(index, value, maxValue) {
|
||||
is(index, 0, "There is only one download");
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIXPIProgressDialog) ||
|
||||
iid.equals(Components.interfaces.nsISupports))
|
||||
return this;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
// ----------------------------------------------------------------------------
|
38
xpinstall/tests/browser_cookies.js
Normal file
38
xpinstall/tests/browser_cookies.js
Normal file
@ -0,0 +1,38 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test that an install that requires cookies to be sent fails when no cookies
|
||||
// are set
|
||||
// This verifies bug 462739
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Cookie check": TESTROOT + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -228, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
51
xpinstall/tests/browser_cookies2.js
Normal file
51
xpinstall/tests/browser_cookies2.js
Normal file
@ -0,0 +1,51 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test that an install that requires cookies to be sent succeeds when cookies
|
||||
// are set
|
||||
// This verifies bug 462739
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Components.interfaces.nsICookieManager2);
|
||||
cm.add("example.com", "/browser/xpinstall/tests", "xpinstall", "true", false,
|
||||
false, true, (Date.now() / 1000) + 60);
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Cookie check": TESTROOT + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Components.interfaces.nsICookieManager2);
|
||||
cm.remove("example.com", "xpinstall", "/browser/xpinstall/tests", false);
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
59
xpinstall/tests/browser_cookies3.js
Normal file
59
xpinstall/tests/browser_cookies3.js
Normal file
@ -0,0 +1,59 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test that an install that requires cookies to be sent succeeds when cookies
|
||||
// are set and third party cookies are disabled.
|
||||
// This verifies bug 462739
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Components.interfaces.nsICookieManager2);
|
||||
cm.add("example.com", "/browser/xpinstall/tests", "xpinstall", "true", false,
|
||||
false, true, (Date.now() / 1000) + 60);
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.setIntPref("network.cookie.cookieBehavior", 1);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Cookie check": TESTROOT + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Components.interfaces.nsICookieManager2);
|
||||
cm.remove("example.com", "xpinstall", "/browser/xpinstall/tests", false);
|
||||
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.clearUserPref("network.cookie.cookieBehavior");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
56
xpinstall/tests/browser_cookies4.js
Normal file
56
xpinstall/tests/browser_cookies4.js
Normal file
@ -0,0 +1,56 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test that an install that requires cookies to be sent fails when cookies
|
||||
// are set and third party cookies are disabled and the request is to a third
|
||||
// party.
|
||||
// This verifies bug 462739
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Components.interfaces.nsICookieManager2);
|
||||
cm.add("example.com", "/browser/xpinstall/tests", "xpinstall", "true", false,
|
||||
false, true, (Date.now() / 1000) + 60);
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.setIntPref("network.cookie.cookieBehavior", 1);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Cookie check": TESTROOT2 + "cookieRedirect.sjs?" + TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -228, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var cm = Components.classes["@mozilla.org/cookiemanager;1"]
|
||||
.getService(Components.interfaces.nsICookieManager2);
|
||||
cm.remove("example.com", "xpinstall", "/browser/xpinstall/tests", false);
|
||||
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.clearUserPref("network.cookie.cookieBehavior");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
39
xpinstall/tests/browser_corrupt.js
Normal file
39
xpinstall/tests/browser_corrupt.js
Normal file
@ -0,0 +1,39 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install fails when the xpi is corrupt.
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Corrupt XPI": TESTROOT + "corrupt.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -207, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
var doc = gBrowser.contentDocument;
|
||||
is(doc.getElementById("status").textContent, "-207", "Callback should have seen the failure");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
36
xpinstall/tests/browser_empty.js
Normal file
36
xpinstall/tests/browser_empty.js
Normal file
@ -0,0 +1,36 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install fails when there is no install script present.
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Empty XPI": TESTROOT + "empty.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -204, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
25
xpinstall/tests/browser_enabled.js
Normal file
25
xpinstall/tests/browser_enabled.js
Normal file
@ -0,0 +1,25 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an InstallTrigger.enabled is working
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function() {
|
||||
// Allow the in-page load handler to run first
|
||||
executeSoon(page_loaded);
|
||||
}, true);
|
||||
gBrowser.loadURI(TESTROOT + "enabled.html");
|
||||
}
|
||||
|
||||
function page_loaded() {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, false);
|
||||
var doc = gBrowser.contentDocument;
|
||||
is(doc.getElementById("enabled").textContent, "true", "installTrigger should have been enabled");
|
||||
gBrowser.removeCurrentTab();
|
||||
finish();
|
||||
}
|
33
xpinstall/tests/browser_enabled2.js
Normal file
33
xpinstall/tests/browser_enabled2.js
Normal file
@ -0,0 +1,33 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an InstallTrigger.enabled is working
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.setBoolPref("xpinstall.enabled", false);
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function() {
|
||||
// Allow the in-page load handler to run first
|
||||
executeSoon(page_loaded);
|
||||
}, true);
|
||||
gBrowser.loadURI(TESTROOT + "enabled.html");
|
||||
}
|
||||
|
||||
function page_loaded() {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, false);
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.clearUserPref("xpinstall.enabled");
|
||||
|
||||
var doc = gBrowser.contentDocument;
|
||||
is(doc.getElementById("enabled").textContent, "false", "installTrigger should have not been enabled");
|
||||
gBrowser.removeCurrentTab();
|
||||
finish();
|
||||
}
|
37
xpinstall/tests/browser_enabled3.js
Normal file
37
xpinstall/tests/browser_enabled3.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an InstallTrigger.install call fails when xpinstall is disabled
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.setBoolPref("xpinstall.enabled", false);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function() {
|
||||
// Allow the in-page load handler to run first
|
||||
executeSoon(page_loaded);
|
||||
}, true);
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function page_loaded() {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, false);
|
||||
var prefs = Components.classes["@mozilla.org/preferences;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
prefs.clearUserPref("xpinstall.enabled");
|
||||
|
||||
var doc = gBrowser.contentDocument;
|
||||
is(doc.getElementById("return").textContent, "false", "installTrigger should have not been enabled");
|
||||
gBrowser.removeCurrentTab();
|
||||
finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
45
xpinstall/tests/browser_hash.js
Normal file
45
xpinstall/tests/browser_hash.js
Normal file
@ -0,0 +1,45 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install succeeds when a valid hash is included
|
||||
// This verifies bug 302284
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": {
|
||||
URL: TESTROOT + "unsigned.xpi",
|
||||
Hash: "sha1:3d0dc22e1f394e159b08aaf5f0f97de4d5c65f4f",
|
||||
toString: function() { return this.URL; }
|
||||
}
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
37
xpinstall/tests/browser_installchrome.js
Normal file
37
xpinstall/tests/browser_installchrome.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests that calling InstallTrigger.installChrome works
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installchrome.html? " + encodeURIComponent(TESTROOT + "unsigned.xpi"));
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
33
xpinstall/tests/browser_localfile.js
Normal file
33
xpinstall/tests/browser_localfile.js
Normal file
@ -0,0 +1,33 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an local file works when loading the url
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
||||
.getService(Components.interfaces.nsIChromeRegistry);
|
||||
var path = cr.convertChromeURL(makeURI(CHROMEROOT + "unsigned.xpi")).spec;
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(path);
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
35
xpinstall/tests/browser_localfile2.js
Normal file
35
xpinstall/tests/browser_localfile2.js
Normal file
@ -0,0 +1,35 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install fails if the url is a local file when requested from
|
||||
// web content
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
|
||||
.getService(Components.interfaces.nsIChromeRegistry);
|
||||
var path = cr.convertChromeURL(makeURI(CHROMEROOT + "unsigned.xpi")).spec;
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": path
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.selectedBrowser.addEventListener("load", function() {
|
||||
// Allow the in-page load handler to run first
|
||||
executeSoon(page_loaded);
|
||||
}, true);
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function page_loaded() {
|
||||
gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, false);
|
||||
|
||||
var doc = gBrowser.contentDocument;
|
||||
is(doc.getElementById("return").textContent, "exception", "installTrigger should have failed");
|
||||
gBrowser.removeCurrentTab();
|
||||
finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
47
xpinstall/tests/browser_navigateaway.js
Normal file
47
xpinstall/tests/browser_navigateaway.js
Normal file
@ -0,0 +1,47 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests that navigating away from the initiating page during the install
|
||||
// doesn't break the install.
|
||||
// This verifies bug 473060
|
||||
function test() {
|
||||
Harness.downloadProgressCallback = download_progress;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
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("about:blank");
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
46
xpinstall/tests/browser_navigateaway2.js
Normal file
46
xpinstall/tests/browser_navigateaway2.js
Normal file
@ -0,0 +1,46 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests that closing the initiating page during the install doesn't break the
|
||||
// install.
|
||||
// This verifies bugs 473060 and 475347
|
||||
function test() {
|
||||
Harness.downloadProgressCallback = download_progress;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
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.removeCurrentTab();
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
43
xpinstall/tests/browser_offline.js
Normal file
43
xpinstall/tests/browser_offline.js
Normal file
@ -0,0 +1,43 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests that going offline cancels an in progress download.
|
||||
function test() {
|
||||
Harness.downloadProgressCallback = download_progress;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
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) {
|
||||
BrowserOffline.toggleOfflineStatus();
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -210, "Install should be cancelled");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
BrowserOffline.toggleOfflineStatus();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
42
xpinstall/tests/browser_opendialog.js
Normal file
42
xpinstall/tests/browser_opendialog.js
Normal file
@ -0,0 +1,42 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Test whether an install succeeds when the progress dialog is already open.
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
BrowserOpenAddonsMgr();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
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 check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
58
xpinstall/tests/browser_signed_multiple.js
Normal file
58
xpinstall/tests/browser_signed_multiple.js
Normal file
@ -0,0 +1,58 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing two signed add-ons in the same trigger works.
|
||||
// This verifies bug 453545
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Signed XPI": TESTROOT + "signed.xpi",
|
||||
"Signed XPI 2": TESTROOT + "signed2.xpi",
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
items = window.document.getElementById("itemList").childNodes;
|
||||
is(items.length, 2, "Should be 2 items listed in the confirmation dialog");
|
||||
is(items[0].name, "Signed XPI", "Should have seen the name from the trigger list");
|
||||
is(items[0].url, TESTROOT + "signed.xpi", "Should have listed the correct url for the item");
|
||||
is(items[0].cert, "(Mozilla Testing)", "Should have seen the signer");
|
||||
is(items[0].signed, "true", "Should have listed the item as signed");
|
||||
is(items[1].name, "Signed XPI 2", "Should have seen the name from the trigger list");
|
||||
is(items[1].url, TESTROOT + "signed2.xpi", "Should have listed the correct url for the item");
|
||||
is(items[1].cert, "(Mozilla Testing)", "Should have seen the signer");
|
||||
is(items[1].signed, "true", "Should have listed the item as signed");
|
||||
return true;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Installs should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("signed-xpi@tests.mozilla.org");
|
||||
em.cancelInstallItem("signed-xpi2@tests.mozilla.org");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
47
xpinstall/tests/browser_signed_tampered.js
Normal file
47
xpinstall/tests/browser_signed_tampered.js
Normal file
@ -0,0 +1,47 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing a signed add-on that has been tampered with after signing.
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Tampered Signed XPI": TESTROOT + "signed-tampered.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
items = window.document.getElementById("itemList").childNodes;
|
||||
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
|
||||
is(items[0].name, "Tampered Signed XPI", "Should have seen the name from the trigger list");
|
||||
is(items[0].url, TESTROOT + "signed-tampered.xpi", "Should have listed the correct url for the item");
|
||||
is(items[0].cert, "(Mozilla Testing)", "Should have seen the signer");
|
||||
is(items[0].signed, "true", "Should have listed the item as signed");
|
||||
return true;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -260, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
52
xpinstall/tests/browser_signed_trigger.js
Normal file
52
xpinstall/tests/browser_signed_trigger.js
Normal file
@ -0,0 +1,52 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an signed add-on through an InstallTrigger call in web
|
||||
// content.
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Signed XPI": TESTROOT + "signed.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
items = window.document.getElementById("itemList").childNodes;
|
||||
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
|
||||
is(items[0].name, "Signed XPI", "Should have seen the name from the trigger list");
|
||||
is(items[0].url, TESTROOT + "signed.xpi", "Should have listed the correct url for the item");
|
||||
is(items[0].cert, "(Mozilla Testing)", "Should have seen the signer");
|
||||
is(items[0].signed, "true", "Should have listed the item as signed");
|
||||
return true;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("signed-xpi@tests.mozilla.org");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
48
xpinstall/tests/browser_signed_untrusted.js
Normal file
48
xpinstall/tests/browser_signed_untrusted.js
Normal file
@ -0,0 +1,48 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an add-on signed by an untrusted certificate through an
|
||||
// InstallTrigger call in web content.
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Untrusted Signed XPI": TESTROOT + "signed-untrusted.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
items = window.document.getElementById("itemList").childNodes;
|
||||
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
|
||||
is(items[0].name, "Untrusted Signed XPI", "Should have seen the name from the trigger list");
|
||||
is(items[0].url, TESTROOT + "signed-untrusted.xpi", "Should have listed the correct url for the item");
|
||||
is(items[0].cert, "(Unknown Organisation)", "Should have seen the supposed signer");
|
||||
is(items[0].signed, "true", "Should have listed the item as signed");
|
||||
return true;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, -260, "Install should fail");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
40
xpinstall/tests/browser_signed_url.js
Normal file
40
xpinstall/tests/browser_signed_url.js
Normal file
@ -0,0 +1,40 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an signed add-on by navigating directly to the url
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "signed.xpi");
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
items = window.document.getElementById("itemList").childNodes;
|
||||
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
|
||||
is(items[0].name, "signed.xpi", "Should have had the filename for the item name");
|
||||
is(items[0].url, TESTROOT + "signed.xpi", "Should have listed the correct url for the item");
|
||||
is(items[0].cert, "(Mozilla Testing)", "Should have seen the signer");
|
||||
is(items[0].signed, "true", "Should have listed the item as signed");
|
||||
return true;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("signed-xpi@tests.mozilla.org");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
37
xpinstall/tests/browser_softwareupdate.js
Normal file
37
xpinstall/tests/browser_softwareupdate.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests that calling InstallTrigger.startSoftwareUpdate works
|
||||
function test() {
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "startsoftwareupdate.html? " + encodeURIComponent(TESTROOT + "unsigned.xpi"));
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
60
xpinstall/tests/browser_unsigned_trigger.js
Normal file
60
xpinstall/tests/browser_unsigned_trigger.js
Normal file
@ -0,0 +1,60 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an unsigned add-on through an InstallTrigger call in web
|
||||
// content.
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": {
|
||||
URL: TESTROOT + "unsigned.xpi",
|
||||
IconURL: TESTROOT + "icon.png",
|
||||
toString: function() { return this.URL; }
|
||||
}
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
items = window.document.getElementById("itemList").childNodes;
|
||||
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
|
||||
is(items[0].name, "Unsigned XPI", "Should have seen the name from the trigger list");
|
||||
is(items[0].url, TESTROOT + "unsigned.xpi", "Should have listed the correct url for the item");
|
||||
is(items[0].icon, TESTROOT + "icon.png", "Should have listed the correct icon for the item");
|
||||
is(items[0].signed, "false", "Should have listed the item as unsigned");
|
||||
return true;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
var doc = gBrowser.contentDocument;
|
||||
is(doc.getElementById("return").textContent, "true", "installTrigger should have claimed success");
|
||||
is(doc.getElementById("status").textContent, "0", "Callback should have seen a success");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
40
xpinstall/tests/browser_unsigned_url.js
Normal file
40
xpinstall/tests/browser_unsigned_url.js
Normal file
@ -0,0 +1,40 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an unsigned add-on by navigating directly to the url
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "unsigned.xpi");
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
items = window.document.getElementById("itemList").childNodes;
|
||||
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
|
||||
is(items[0].name, "unsigned.xpi", "Should have had the filename for the item name");
|
||||
is(items[0].url, TESTROOT + "unsigned.xpi", "Should have listed the correct url for the item");
|
||||
is(items[0].icon, "", "Should have listed no icon for the item");
|
||||
is(items[0].signed, "false", "Should have listed the item as unsigned");
|
||||
return true;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
49
xpinstall/tests/browser_whitelist.js
Normal file
49
xpinstall/tests/browser_whitelist.js
Normal file
@ -0,0 +1,49 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an unsigned add-on through an InstallTrigger call in web
|
||||
// content. This should be blocked by the whitelist check.
|
||||
// This verifies bug 252830
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installBlockedCallback = allow_blocked;
|
||||
Harness.installEndedCallback = check_xpi_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": TESTROOT + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function allow_blocked() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
items = window.document.getElementById("itemList").childNodes;
|
||||
is(items.length, 1, "Should only be 1 item listed in the confirmation dialog");
|
||||
is(items[0].name, "Unsigned XPI", "Should have seen the name from the trigger list");
|
||||
is(items[0].url, TESTROOT + "unsigned.xpi", "Should have listed the correct url for the item");
|
||||
is(items[0].signed, "false", "Should have listed the item as unsigned");
|
||||
return true;
|
||||
}
|
||||
|
||||
function check_xpi_install(addon, status) {
|
||||
is(status, 0, "Install should succeed");
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.cancelInstallItem("unsigned-xpi@tests.mozilla.org");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
38
xpinstall/tests/browser_whitelist2.js
Normal file
38
xpinstall/tests/browser_whitelist2.js
Normal file
@ -0,0 +1,38 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an unsigned add-on through an InstallTrigger call in web
|
||||
// content. This should be blocked by the whitelist check because the source
|
||||
// is not whitelisted, even though the target is.
|
||||
function test() {
|
||||
Harness.installBlockedCallback = allow_blocked;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.org/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": TESTROOT2 + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
|
||||
}
|
||||
|
||||
function allow_blocked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.org", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
37
xpinstall/tests/browser_whitelist3.js
Normal file
37
xpinstall/tests/browser_whitelist3.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an unsigned add-on through a navigation. Should not be
|
||||
// blocked since the referer is whitelisted.
|
||||
function test() {
|
||||
Harness.installConfirmCallback = confirm_install;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.org/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": TESTROOT2 + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "unsigned.xpi", makeURI(TESTROOT2 + "test.html"));
|
||||
}
|
||||
|
||||
function confirm_install(window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.org", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
37
xpinstall/tests/browser_whitelist4.js
Normal file
37
xpinstall/tests/browser_whitelist4.js
Normal file
@ -0,0 +1,37 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an unsigned add-on through a navigation. Should be
|
||||
// blocked since the referer is not whitelisted even though the target is.
|
||||
function test() {
|
||||
Harness.installBlockedCallback = allow_blocked;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
|
||||
|
||||
var triggers = encodeURIComponent(JSON.stringify({
|
||||
"Unsigned XPI": TESTROOT2 + "unsigned.xpi"
|
||||
}));
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "unsigned.xpi", makeURI(TESTROOT2 + "test.html"));
|
||||
}
|
||||
|
||||
function allow_blocked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
var pm = Components.classes["@mozilla.org/permissionmanager;1"]
|
||||
.getService(Components.interfaces.nsIPermissionManager);
|
||||
pm.remove("example.com", "install");
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
27
xpinstall/tests/browser_whitelist5.js
Normal file
27
xpinstall/tests/browser_whitelist5.js
Normal file
@ -0,0 +1,27 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an unsigned add-on through a startSoftwareUpdate call in web
|
||||
// content. This should be blocked by the whitelist check.
|
||||
// This verifies bug 252830
|
||||
function test() {
|
||||
Harness.installBlockedCallback = allow_blocked;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "startsoftwareupdate.html? " + encodeURIComponent(TESTROOT + "unsigned.xpi"));
|
||||
}
|
||||
|
||||
function allow_blocked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
27
xpinstall/tests/browser_whitelist6.js
Normal file
27
xpinstall/tests/browser_whitelist6.js
Normal file
@ -0,0 +1,27 @@
|
||||
// Load in the test harness
|
||||
var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
|
||||
.getService(Components.interfaces.mozIJSSubScriptLoader);
|
||||
scriptLoader.loadSubScript("chrome://mochikit/content/browser/xpinstall/tests/harness.js", this);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tests installing an unsigned add-on through an installChrome call in web
|
||||
// content. This should be blocked by the whitelist check.
|
||||
// This verifies bug 252830
|
||||
function test() {
|
||||
Harness.installBlockedCallback = allow_blocked;
|
||||
Harness.installsCompletedCallback = finish_test;
|
||||
Harness.setup();
|
||||
|
||||
gBrowser.selectedTab = gBrowser.addTab();
|
||||
gBrowser.loadURI(TESTROOT + "installchrome.html? " + encodeURIComponent(TESTROOT + "unsigned.xpi"));
|
||||
}
|
||||
|
||||
function allow_blocked() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function finish_test() {
|
||||
gBrowser.removeCurrentTab();
|
||||
Harness.finish();
|
||||
}
|
||||
// ----------------------------------------------------------------------------
|
24
xpinstall/tests/cookieRedirect.sjs
Normal file
24
xpinstall/tests/cookieRedirect.sjs
Normal file
@ -0,0 +1,24 @@
|
||||
// Simple script redirects to the query part of the uri if the cookie "xpinstall"
|
||||
// has the value "true", otherwise gives a 500 error.
|
||||
|
||||
function handleRequest(request, response)
|
||||
{
|
||||
let cookie = null;
|
||||
if (request.hasHeader("Cookie")) {
|
||||
let cookies = request.getHeader("Cookie").split(";");
|
||||
for (let i = 0; i < cookies.length; i++) {
|
||||
if (cookies[i].substring(0, 10) == "xpinstall=")
|
||||
cookie = cookies[i].substring(10);
|
||||
}
|
||||
}
|
||||
|
||||
if (cookie == "true") {
|
||||
response.setStatusLine(request.httpVersion, 302, "Found");
|
||||
response.setHeader("Location", request.queryString);
|
||||
response.write("See " + request.queryString);
|
||||
}
|
||||
else {
|
||||
response.setStatusLine(request.httpVersion, 500, "Internal Server Error");
|
||||
response.write("Invalid request");
|
||||
}
|
||||
}
|
1
xpinstall/tests/corrupt.xpi
Normal file
1
xpinstall/tests/corrupt.xpi
Normal file
@ -0,0 +1 @@
|
||||
This is a corrupt zip file
|
BIN
xpinstall/tests/empty.xpi
Normal file
BIN
xpinstall/tests/empty.xpi
Normal file
Binary file not shown.
20
xpinstall/tests/enabled.html
Normal file
20
xpinstall/tests/enabled.html
Normal file
@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html>
|
||||
|
||||
<!-- This page will test if InstallTrigger seems to be enabled -->
|
||||
|
||||
<head>
|
||||
<title>InstallTrigger tests</title>
|
||||
<script type="text/javascript">
|
||||
function init() {
|
||||
document.getElementById("enabled").textContent = InstallTrigger.enabled() ? "true" : "false";
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="init()">
|
||||
<p>InstallTrigger tests</p>
|
||||
<p id="enabled"></p>
|
||||
</body>
|
||||
</html>
|
257
xpinstall/tests/harness.js
Normal file
257
xpinstall/tests/harness.js
Normal file
@ -0,0 +1,257 @@
|
||||
const TESTROOT = "http://example.com/browser/xpinstall/tests/";
|
||||
const TESTROOT2 = "http://example.org/browser/xpinstall/tests/";
|
||||
const CHROMEROOT = "chrome://mochikit/content/browser/xpinstall/tests/"
|
||||
const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
|
||||
const PROMPT_URL = "chrome://global/content/commonDialog.xul";
|
||||
const ADDONS_URL = "chrome://mozapps/content/extensions/extensions.xul";
|
||||
|
||||
/**
|
||||
* This is a test harness designed to handle responding to UI during the process
|
||||
* of installing an XPI. A test can set callbacks to hear about specific parts
|
||||
* of the sequence.
|
||||
* Before use setup must be called and finish must be called afterwards.
|
||||
*/
|
||||
var Harness = {
|
||||
// If set then the install is expected to be blocked by the whitelist. The
|
||||
// callback should return true to continue with the install anyway.
|
||||
installBlockedCallback: null,
|
||||
// If set will be called in the event of authentication being needed to get
|
||||
// the xpi. Should return a 2 element array of username and password, or
|
||||
// null to not authenticate.
|
||||
authenticationCallback: null,
|
||||
// If set this will be called to allow checking the contents of the xpinstall
|
||||
// confirmation dialog. The callback should return true to continue the install.
|
||||
installConfirmCallback: null,
|
||||
// If set will be called when downloading of an item has begun.
|
||||
downloadStartedCallback: null,
|
||||
// If set will be called during the download of an item.
|
||||
downloadProgressCallback: null,
|
||||
// If set will be called when downloading of an item has ended.
|
||||
downloadEndedCallback: null,
|
||||
// If set will be called when installation by the extension manager of an xpi
|
||||
// item starts
|
||||
installStartedCallback: null,
|
||||
// If set will be called when each xpi item to be installed completes
|
||||
// installation.
|
||||
installEndedCallback: null,
|
||||
// If set will be called when all triggered items are installed or the install
|
||||
// is canceled.
|
||||
installsCompletedCallback: null,
|
||||
|
||||
listenerIndex: null,
|
||||
|
||||
// Setup and tear down functions
|
||||
setup: function() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
os.addObserver(this, "xpinstall-install-blocked", false);
|
||||
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
wm.addListener(this);
|
||||
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
this.listenerIndex = em.addInstallListener(this);
|
||||
},
|
||||
|
||||
finish: function() {
|
||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
os.removeObserver(this, "xpinstall-install-blocked");
|
||||
|
||||
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
||||
.getService(Components.interfaces.nsIWindowMediator);
|
||||
wm.removeListener(this);
|
||||
var win = wm.getMostRecentWindow("Extension:Manager");
|
||||
if (win)
|
||||
win.close();
|
||||
|
||||
var em = Components.classes["@mozilla.org/extensions/manager;1"]
|
||||
.getService(Components.interfaces.nsIExtensionManager);
|
||||
em.removeInstallListenerAt(this.listenerIndex);
|
||||
finish();
|
||||
},
|
||||
|
||||
endTest: function() {
|
||||
// Defer the final notification to allow things like the InstallTrigger
|
||||
// callback to complete
|
||||
executeSoon(this.installsCompletedCallback);
|
||||
|
||||
this.installBlockedCallback = null;
|
||||
this.authenticationCallback = null;
|
||||
this.installConfirmCallback = null;
|
||||
this.downloadStartedCallback = null;
|
||||
this.downloadProgressCallback = null;
|
||||
this.downloadEndedCallback = null;
|
||||
this.installStartedCallback = null;
|
||||
this.installEndedCallback = null;
|
||||
this.installsCompletedCallback = null;
|
||||
},
|
||||
|
||||
// Window open handling
|
||||
windowLoad: function(window) {
|
||||
// Allow any other load handlers to execute
|
||||
var self = this;
|
||||
executeSoon(function() { self.windowReady(window); } );
|
||||
},
|
||||
|
||||
windowReady: function(window) {
|
||||
if (window.document.location.href == XPINSTALL_URL) {
|
||||
if (this.installBlockedCallback)
|
||||
ok(false, "Should have been blocked by the whitelist");
|
||||
|
||||
// If there is a confirm callback then its return status determines whether
|
||||
// to install the items or not. If not the test is over.
|
||||
if (this.installConfirmCallback && !this.installConfirmCallback(window)) {
|
||||
window.document.documentElement.cancelDialog();
|
||||
this.endTest();
|
||||
}
|
||||
else {
|
||||
// Initially the accept button is disabled on a countdown timer
|
||||
var button = window.document.documentElement.getButton("accept");
|
||||
button.disabled = false;
|
||||
window.document.documentElement.acceptDialog();
|
||||
}
|
||||
}
|
||||
else if (window.document.location.href == PROMPT_URL) {
|
||||
switch (window.gCommonDialogParam.GetInt(3)) {
|
||||
case 0: if (window.opener.document.location.href == ADDONS_URL) {
|
||||
// A prompt opened by the add-ons manager is liable to be an
|
||||
// xpinstall error, just close it, we'll see the error in
|
||||
// onInstallEnded anyway.
|
||||
window.document.documentElement.acceptDialog();
|
||||
}
|
||||
break;
|
||||
case 2: if (window.gCommonDialogParam.GetInt(4) != 1) {
|
||||
// This is a login dialog, hopefully an authentication prompt
|
||||
// for the xpi.
|
||||
if (this.authenticationCallback) {
|
||||
var auth = this.authenticationCallback();
|
||||
if (auth && auth.length == 2) {
|
||||
window.document.getElementById("loginTextbox").value = auth[0];
|
||||
window.document.getElementById("password1Textbox").value = auth[1];
|
||||
window.document.documentElement.acceptDialog();
|
||||
}
|
||||
else {
|
||||
window.document.documentElement.cancelDialog();
|
||||
}
|
||||
}
|
||||
else {
|
||||
window.document.documentElement.cancelDialog();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Install blocked handling
|
||||
|
||||
installBlocked: function() {
|
||||
// The browser should have a notification box animating now
|
||||
var notificationBox = gBrowser.getNotificationBox(gBrowser.selectedBrowser);
|
||||
var self = this;
|
||||
this.waitForNotification(notificationBox, function() { self.notificationComplete() });
|
||||
},
|
||||
|
||||
// This delays until a notification has finished animating it. It's a bit of a
|
||||
// hack due to the timeout use but should be safe.
|
||||
waitForNotification: function(notificationBox, callback) {
|
||||
if (!notificationBox._timer) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
setTimeout(arguments.callee, 50, notificationBox, callback);
|
||||
},
|
||||
|
||||
notificationComplete: function() {
|
||||
ok(!!this.installBlockedCallback, "Shouldn't have been blocked by the whitelist");
|
||||
var notification = gBrowser.getNotificationBox(gBrowser.selectedBrowser)
|
||||
.getNotificationWithValue("xpinstall");
|
||||
if (this.installBlockedCallback && this.installBlockedCallback()) {
|
||||
this.installBlockedCallback = null;
|
||||
notification.firstChild.click();
|
||||
}
|
||||
else {
|
||||
notification.close();
|
||||
this.endTest();
|
||||
}
|
||||
},
|
||||
|
||||
// nsIWindowMediatorListener
|
||||
|
||||
onWindowTitleChange: function(window, title) {
|
||||
},
|
||||
|
||||
onOpenWindow: function(window) {
|
||||
var domwindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
|
||||
.getInterface(Components.interfaces.nsIDOMWindowInternal);
|
||||
var self = this;
|
||||
domwindow.addEventListener("load", function() {
|
||||
self.windowLoad(domwindow);
|
||||
}, false);
|
||||
},
|
||||
|
||||
onCloseWindow: function(window) {
|
||||
},
|
||||
|
||||
// nsIAddonInstallListener
|
||||
|
||||
onDownloadStarted: function(addon) {
|
||||
if (this.downloadStartedCallback)
|
||||
this.downloadStartedCallback(addon);
|
||||
},
|
||||
|
||||
onDownloadProgress: function(addon, value, maxValue) {
|
||||
if (this.downloadProgressCallback)
|
||||
this.downloadProgressCallback(addon, value, maxValue);
|
||||
},
|
||||
|
||||
onDownloadEnded: function(addon) {
|
||||
if (this.downloadEndedCallback)
|
||||
this.downloadEndedCallback(addon);
|
||||
},
|
||||
|
||||
onInstallStarted: function(addon) {
|
||||
if (this.installStartedCallback)
|
||||
this.installStartedCallback(addon);
|
||||
},
|
||||
|
||||
onCompatibilityCheckStarted: function(addon) {
|
||||
},
|
||||
|
||||
onCompatibilityCheckEnded: function(addon, status) {
|
||||
},
|
||||
|
||||
onInstallEnded: function(addon, status) {
|
||||
if (this.installEndedCallback)
|
||||
this.installEndedCallback(addon, status);
|
||||
},
|
||||
|
||||
onInstallsCompleted: function() {
|
||||
this.endTest();
|
||||
},
|
||||
|
||||
// nsIObserver
|
||||
|
||||
observe: function(subject, topic, data) {
|
||||
// Make sure the main UI has received the event too and so has started
|
||||
// displaying the notification.
|
||||
var self = this;
|
||||
executeSoon(function() { self.installBlocked() });
|
||||
},
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIObserver) ||
|
||||
iid.equals(Components.interfaces.nsIAddonInstallListener) ||
|
||||
iid.equals(Components.interfaces.nsIWindowMediatorListener) ||
|
||||
iid.equals(Components.interfaces.nsISupports))
|
||||
return this;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
}
|
21
xpinstall/tests/installchrome.html
Normal file
21
xpinstall/tests/installchrome.html
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html>
|
||||
|
||||
<!-- This page will accept a url as the uri query and pass it to InstallTrigger.installChrome -->
|
||||
|
||||
<head>
|
||||
<title>InstallTrigger tests</title>
|
||||
<script type="text/javascript">
|
||||
function startInstall() {
|
||||
InstallTrigger.installChrome(InstallTrigger.SKIN,
|
||||
decodeURIComponent(document.location.search.substring(1)),
|
||||
"test");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="startInstall()">
|
||||
<p>InstallTrigger tests</p>
|
||||
</body>
|
||||
</html>
|
32
xpinstall/tests/installtrigger.html
Normal file
32
xpinstall/tests/installtrigger.html
Normal file
@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html>
|
||||
|
||||
<!-- This page will accept some json as the uri query and pass it to InstallTrigger.install -->
|
||||
|
||||
<head>
|
||||
<title>InstallTrigger tests</title>
|
||||
<script type="text/javascript">
|
||||
function installCallback(url, status) {
|
||||
document.getElementById("status").textContent = status;
|
||||
}
|
||||
|
||||
function startInstall() {
|
||||
var text = decodeURIComponent(document.location.search.substring(1));
|
||||
var triggers = JSON.parse(text);
|
||||
try {
|
||||
document.getElementById("return").textContent = InstallTrigger.install(triggers, installCallback);
|
||||
}
|
||||
catch (e) {
|
||||
document.getElementById("return").textContent = "exception";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="startInstall()">
|
||||
<p>InstallTrigger tests</p>
|
||||
<p id="return"></p>
|
||||
<p id="status"></p>
|
||||
</body>
|
||||
</html>
|
BIN
xpinstall/tests/signed-tampered.xpi
Normal file
BIN
xpinstall/tests/signed-tampered.xpi
Normal file
Binary file not shown.
BIN
xpinstall/tests/signed-untrusted.xpi
Normal file
BIN
xpinstall/tests/signed-untrusted.xpi
Normal file
Binary file not shown.
BIN
xpinstall/tests/signed.xpi
Normal file
BIN
xpinstall/tests/signed.xpi
Normal file
Binary file not shown.
BIN
xpinstall/tests/signed2.xpi
Normal file
BIN
xpinstall/tests/signed2.xpi
Normal file
Binary file not shown.
19
xpinstall/tests/startsoftwareupdate.html
Normal file
19
xpinstall/tests/startsoftwareupdate.html
Normal file
@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html>
|
||||
|
||||
<!-- This page will accept a url as the uri query and pass it to InstallTrigger.startSoftwareUpdate -->
|
||||
|
||||
<head>
|
||||
<title>InstallTrigger tests</title>
|
||||
<script type="text/javascript">
|
||||
function startInstall() {
|
||||
InstallTrigger.startSoftwareUpdate(decodeURIComponent(document.location.search.substring(1)));
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body onload="startInstall()">
|
||||
<p>InstallTrigger tests</p>
|
||||
</body>
|
||||
</html>
|
BIN
xpinstall/tests/unsigned.xpi
Normal file
BIN
xpinstall/tests/unsigned.xpi
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user