Adding general application update service tests from Bug 446527 without the Makefiles since the tree is not green - NPOB for now. r=dtownsend, r=bsmedberg

This commit is contained in:
Robert Strong 2008-08-16 13:27:09 -07:00
parent b9dd045b06
commit acf4fab526
25 changed files with 833 additions and 0 deletions

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<updates>
<update name="XPCShell Test" type="minor" version="1.1a1pre" platformVersion="2.1a1pre" extensionVersion="3.1a1pre" buildID="20080811053724" licenseURL="http://dummylicense/" detailsURL="http://dummydetails/">
<patch type="complete" URL="http://complete/" hashFunction="SHA1" hashValue="98db9dad8e1d80eda7e1170d0187d6f53e477059" size="9856459"/>
<patch type="partial" URL="http://partial/" hashFunction="SHA1" hashValue="e6678ca40ae7582316acdeddf3c133c9c8577de4" size="1316138"/>
</update>
</updates>

View File

@ -0,0 +1 @@

View File

@ -0,0 +1,3 @@
<?xml version="1.0"?>
<updates>
</updates>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<updates>
<update name="XPCShell Test" type="minor" version="1.1a1pre" platformVersion="2.1a1pre" extensionVersion="3.1a1pre" buildID="20080811053724" licenseURL="http://dummylicense/" detailsURL="http://dummydetails/">
<patch type="complete" URL="http://complete/" hashFunction="SHA1" hashValue="98db9dad8e1d80eda7e1170d0187d6f53e477059" size="9856459"/>
<patch type="partial" URL="http://partial/" hashFunction="SHA1" hashValue="e6678ca40ae7582316acdeddf3c133c9c8577de4" size="1316138"/>
</update>
</updates>

View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<updates>
<update type="minor" version="1.1a1pre" extensionVersion="2.1a1pre" buildID="20080811053724">
<patch type="complete" URL="http://complete/" hashFunction="sha1" hashValue="98db9dad8e1d80eda7e1170d0187d6f53e477059" size="9856459"/>
<patch type="partial" URL="http://partial/" hashFunction="SHA1" hashValue="e6678ca40ae7582316acdeddf3c133c9c8577de4" size="1316138"/>
</update>
<update type="minor" version="1.1a2pre" extensionVersion="2.1a2pre" buildID="20080811053724">
<patch type="complete" URL="http://complete/" hashFunction="sha1" hashValue="98db9dad8e1d80eda7e1170d0187d6f53e477059" size="9856459"/>
<patch type="partial" URL="http://partial/" hashFunction="SHA1" hashValue="e6678ca40ae7582316acdeddf3c133c9c8577de4" size="1316138"/>
</update>
<update type="minor" version="1.1a3pre" extensionVersion="2.1a3pre" buildID="20080811053724">
<patch type="complete" URL="http://complete/" hashFunction="sha1" hashValue="98db9dad8e1d80eda7e1170d0187d6f53e477059" size="9856459"/>
<patch type="partial" URL="http://partial/" hashFunction="SHA1" hashValue="e6678ca40ae7582316acdeddf3c133c9c8577de4" size="1316138"/>
</update>
</updates>

View File

@ -0,0 +1,7 @@
<?xml version="1.0"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="complete" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA1" hashValue="63A739284A1A73ECB515176B1A9D85B987E789CE" size="0"/>
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA1" hashValue="63A739284A1A73ECB515176B1A9D85B987E789CE" size="0"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="complete" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA1" hashValue="63A739284A1A73ECB515176B1A9D85B987E789CE" size="0"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA1" hashValue="63A739284A1A73ECB515176B1A9D85B987E789CE" size="0"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="MD5" hashValue="6232cd43a1c77e30191c53a329a3f99d" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA512" hashValue="1d2307e309587ddd04299423b34762639ce6af3ee17cfdaa8fdd4e66b5a61bfb6555b6e40a82604908d6d68d3e42f318f82e22b6f5e1118b4222e3417a2fa2d1" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/bogus.mar" hashFunction="SHA1" hashValue="63A739284A1A73ECB515176B1A9D85B987E789CE" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="MD5" hashValue="6232cd43a1c77e30191c53a329a3f99e" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA1" hashValue="63A739284A1A73ECB515176B1A9D85B987E789CE" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA1" hashValue="63A739284A1A73ECB515176B1A9D85B987E789CD" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA256" hashValue="a8d9189f3978afd90dc7cd72e887ef22474c178e8314f23df2f779c881b872e2" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA256" hashValue="a8d9189f3978afd90dc7cd72e887ef22474c178e8314f23df2f779c881b872e1" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA384" hashValue="802c64f6caa6c356f7a5f8d9a008c08c54fe915c3ec7cf9e215c3bccc9e195c78b2669840d7b1d46ff3c1dfa751d72e1" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA384" hashValue="802c64f6caa6c356f7a5f8d9a008c08c54fe915c3ec7cf9e215c3bccc9e195c78b2669840d7b1d46ff3c1dfa751d72e2" size="775"/>
</update>
</updates>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<updates>
<update type="major" version="4.0" extensionVersion="4.0" buildID="20080811053724" licenseURL="http://dummylicense" detailsURL="http://dummydetails/">
<patch type="partial" URL="http://localhost:4444/data/empty.mar" hashFunction="SHA512" hashValue="1d2307e309587ddd04299423b34762639ce6af3ee17cfdaa8fdd4e66b5a61bfb6555b6e40a82604908d6d68d3e42f318f82e22b6f5e1118b4222e3417a2fa2d0" size="775"/>
</update>
</updates>

Binary file not shown.

View File

@ -0,0 +1,167 @@
/* ***** 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 the Application Update Service.
*
* The Initial Developer of the Original Code is
* Robert Strong <robert.bugzilla@gmail.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2008
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 *****
*/
// const Cc, Ci, and Cr are defined in netwerk/test/httpserver/httpd.js so we
// need to define unique ones.
const AUS_Cc = Components.classes;
const AUS_Ci = Components.interfaces;
const AUS_Cr = Components.results;
var gAUS = null;
var gUpdateChecker = null;
var gPrefs = null;
var gTestserver = null;
/* Initializes the most commonly used global vars used by tests */
function startAUS() {
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1.0", "2.0");
gPrefs = AUS_Cc["@mozilla.org/preferences;1"]
.getService(AUS_Ci.nsIPrefBranch);
// Enable Update logging (see below)
gPrefs.setBoolPref("app.update.log.all", true);
// Lessens the noise in the logs when using Update Service logging (see below)
gPrefs.setBoolPref("app.update.enabled", false);
gPrefs.setBoolPref("extensions.blocklist.enabled", false);
gPrefs.setBoolPref("extensions.update.enabled", false);
gPrefs.setBoolPref("browser.search.update", false);
gPrefs.setBoolPref("browser.microsummary.updateGenerators", false);
gAUS = AUS_Cc["@mozilla.org/updates/update-service;1"]
.getService(AUS_Ci.nsIApplicationUpdateService);
gUpdateChecker = AUS_Cc["@mozilla.org/updates/update-checker;1"]
.createInstance(AUS_Ci.nsIUpdateChecker);
// Uncomment the following two lines to log Update Service logging to the
// test logs.
/*
var os = AUS_Cc["@mozilla.org/observer-service;1"]
.getService(AUS_Ci.nsIObserverService);
os.notifyObservers(null, "profile-after-change", null);
*/
}
/**
* Removes the updates directory and the active-update.xml file if they exist.
* This prevents some tests from failing due to files being left behind when
* the tests are interrupted.
*/
function remove_dirs_and_files () {
var fileLocator = AUS_Cc["@mozilla.org/file/directory_service;1"]
.getService(AUS_Ci.nsIProperties);
var dir = fileLocator.get("XCurProcD", AUS_Ci.nsIFile);
var file = dir.clone();
file.append("active-update.xml");
if (file.exists())
file.remove(false);
dir.append("updates");
if (dir.exists())
dir.remove(true);
}
/**
* Helper for starting the http server used by the tests
* @param aRelativeDirName
* The directory name to register relative to
* toolkit/mozapps/update/test/unit/
*/
function start_httpserver(aRelativeDirName) {
do_import_script("netwerk/test/httpserver/httpd.js");
gTestserver = new nsHttpServer();
gTestserver.registerDirectory("/data/", do_get_file("toolkit/mozapps/update/test/unit/" + aRelativeDirName));
gTestserver.start(4444);
}
/* Helper for stopping the http server used by the tests */
function stop_httpserver() {
gTestserver.stop();
}
/**
* Creates an nsIXULAppInfo
* @param id
* The ID of the test application
* @param name
* A name for the test application
* @param version
* The version of the application
* @param platformVersion
* The gecko version of the application
*/
function createAppInfo(id, name, version, platformVersion)
{
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
var XULAppInfo = {
vendor: "Mozilla",
name: name,
ID: id,
version: version,
appBuildID: "2007010101",
platformVersion: platformVersion,
platformBuildID: "2007010101",
inSafeMode: false,
logConsoleErrors: true,
OS: "XPCShell",
XPCOMABI: "noarch-spidermonkey",
QueryInterface: function QueryInterface(iid) {
if (iid.equals(AUS_Ci.nsIXULAppInfo) ||
iid.equals(AUS_Ci.nsIXULRuntime) ||
iid.equals(AUS_Ci.nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
var XULAppInfoFactory = {
createInstance: function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return XULAppInfo.QueryInterface(iid);
}
};
var registrar = Components.manager.QueryInterface(AUS_Ci.nsIComponentRegistrar);
registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
XULAPPINFO_CONTRACTID, XULAppInfoFactory);
}
remove_dirs_and_files();

View File

@ -0,0 +1,43 @@
/* ***** 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 the Application Update Service.
*
* The Initial Developer of the Original Code is
* Robert Strong <robert.bugzilla@gmail.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2008
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 *****
*/
gUpdateChecker = null;
gAUS = null;
gPrefs = null;
gTestserver = null;
remove_dirs_and_files();

View File

@ -0,0 +1,46 @@
/* ***** 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 the Application Update Service.
*
* The Initial Developer of the Original Code is
* Robert Strong <robert.bugzilla@gmail.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2008
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 *****
*/
/* General Update Service Tests */
function run_test() {
startAUS();
// Check if the update dir can be written to
dump("Testing: nsIApplicationUpdateService:canUpdate\n");
do_check_true(gAUS.canUpdate);
}

View File

@ -0,0 +1,235 @@
/* ***** 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 the Application Update Service.
*
* The Initial Developer of the Original Code is
* Robert Strong <robert.bugzilla@gmail.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2008
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 *****
*/
/* General Update Check Tests */
const DIR_DATA = "data"
const URL_PREFIX = "http://localhost:4444/" + DIR_DATA + "/";
const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override";
var gUpdates;
var gUpdateCount;
var gStatus;
var gCheckFunc;
var gNextRunFunc;
var gExpectedCount;
function run_test() {
do_test_pending();
startAUS();
start_httpserver(DIR_DATA);
do_timeout(0, "run_test_pt1()");
}
function end_test() {
stop_httpserver();
do_test_finished();
}
// Helper function for testing update counts returned from an update xml
function run_test_helper_pt1(aUpdateXML, aMsg, aExpectedCount, aNextRunFunc) {
gUpdates = null;
gUpdateCount = null;
gStatus = null;
gCheckFunc = check_test_helper_pt1;
gNextRunFunc = aNextRunFunc;
gExpectedCount = aExpectedCount;
var url = URL_PREFIX + aUpdateXML;
dump("Testing: " + aMsg + " - " + url + "\n");
gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
function check_test_helper_pt1() {
do_check_eq(gUpdateCount, gExpectedCount);
gNextRunFunc();
}
// one update available and the update's property values
function run_test_pt1() {
gUpdates = null;
gUpdateCount = null;
gStatus = null;
gCheckFunc = check_test_pt1;
var url = URL_PREFIX + "aus-0020_general-1.xml";
dump("Testing: one update available and the update's property values - " +
url + "\n");
gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
var defaults = gPrefs.QueryInterface(AUS_Ci.nsIPrefService)
.getDefaultBranch(null);
defaults.setCharPref("app.update.channel", "bogus_channel");
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
function check_test_pt1() {
do_check_eq(gUpdateCount, 1);
var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
do_check_eq(bestUpdate.type, "minor");
do_check_eq(bestUpdate.name, "XPCShell Test");
do_check_eq(bestUpdate.version, "1.1a1pre");
do_check_eq(bestUpdate.platformVersion, "2.1a1pre");
do_check_eq(bestUpdate.extensionVersion, "3.1a1pre");
do_check_eq(bestUpdate.buildID, "20080811053724");
do_check_eq(bestUpdate.detailsURL, "http://dummydetails/");
do_check_eq(bestUpdate.licenseURL, "http://dummylicense/");
do_check_eq(bestUpdate.serviceURL, URL_PREFIX + "aus-0020_general-1.xml?force=1");
do_check_eq(bestUpdate.channel, "bogus_channel");
do_check_false(bestUpdate.isCompleteUpdate);
do_check_false(bestUpdate.isSecurityUpdate);
do_check_eq(bestUpdate.installDate, 0);
do_check_eq(bestUpdate.statusText, null);
// nsIUpdate:state returns an empty string when no action has been performed
// on an available update
do_check_eq(bestUpdate.state, "");
do_check_eq(bestUpdate.errorCode, 0);
do_check_eq(bestUpdate.patchCount, 2);
//XXX TODO - test nsIUpdate:serialize
var type = "complete";
var patch = bestUpdate.getPatchAt(0);
do_check_eq(patch.type, type);
do_check_eq(patch.URL, "http://" + type + "/");
do_check_eq(patch.hashFunction, "SHA1");
do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059");
do_check_eq(patch.size, 9856459);
// nsIUpdatePatch:state returns the string "null" when no action has been
// performed on an available update
do_check_eq(patch.state, "null");
do_check_false(patch.selected);
//XXX TODO - test nsIUpdatePatch:serialize
type = "partial";
patch = bestUpdate.getPatchAt(1);
do_check_eq(patch.type, type);
do_check_eq(patch.URL, "http://" + type + "/");
do_check_eq(patch.hashFunction, "SHA1");
do_check_eq(patch.hashValue, "e6678ca40ae7582316acdeddf3c133c9c8577de4");
do_check_eq(patch.size, 1316138);
// nsIUpdatePatch:state returns the string "null" when no action has been
// performed on an available update
do_check_eq(patch.state, "null");
do_check_false(patch.selected);
//XXX TODO - test nsIUpdatePatch:serialize
run_test_pt2();
}
// Empty update xml
function run_test_pt2() {
run_test_helper_pt1("aus-0020_general-2.xml",
"empty update xml",
null, run_test_pt3);
}
// update xml not found
function run_test_pt3() {
run_test_helper_pt1("aus-0020_general-3.xml",
"update xml not available",
null, run_test_pt4);
}
// no updates available
function run_test_pt4() {
run_test_helper_pt1("aus-0020_general-4.xml",
"no updates available",
0, run_test_pt5);
}
// one update available with two patches
function run_test_pt5() {
run_test_helper_pt1("aus-0020_general-5.xml",
"one update available",
1, run_test_pt6);
}
// three updates available each with two patches
function run_test_pt6() {
run_test_helper_pt1("aus-0020_general-6.xml",
"three updates available",
3, run_test_pt7);
}
// one update with complete and partial patches with size 0 specified in the
// update xml
function run_test_pt7() {
run_test_helper_pt1("aus-0020_general-7.xml",
"one update with complete and partial patches with size 0",
0, run_test_pt8);
}
// one update with complete patch with size 0 specified in the update xml
function run_test_pt8() {
run_test_helper_pt1("aus-0020_general-8.xml",
"one update with complete patch with size 0",
0, run_test_pt9);
}
// one update with partial patch with size 0 specified in the update xml
function run_test_pt9() {
run_test_helper_pt1("aus-0020_general-9.xml",
"one update with partial patch with size 0",
0, end_test);
}
// Update check listener
const updateCheckListener = {
onProgress: function(request, position, totalSize) {
},
onCheckComplete: function(request, updates, updateCount) {
gUpdateCount = updateCount;
gUpdates = updates;
dump("onCheckComplete url = " + request.channel.originalURI.spec + "\n\n");
// Use a timeout to allow the XHR to complete
do_timeout(0, "gCheckFunc()");
},
onError: function(request, update) {
dump("onError url = " + request.channel.originalURI.spec + "\n\n");
// Use a timeout to allow the XHR to complete
do_timeout(0, "gCheckFunc()");
},
QueryInterface: function(aIID) {
if (!aIID.equals(AUS_Ci.nsIUpdateCheckListener) &&
!aIID.equals(AUS_Ci.nsISupports))
throw AUS_Cr.NS_ERROR_NO_INTERFACE;
return this;
}
};

View File

@ -0,0 +1,224 @@
/* ***** 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 the Application Update Service.
*
* The Initial Developer of the Original Code is
* Robert Strong <robert.bugzilla@gmail.com>.
*
* Portions created by the Initial Developer are Copyright (C) 2008
* the Mozilla Foundation <http://www.mozilla.org/>. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 *****
*/
/* General MAR File Download Tests */
const DIR_DATA = "data"
const URL_PREFIX = "http://localhost:4444/" + DIR_DATA + "/";
const PREF_APP_UPDATE_URL_OVERRIDE = "app.update.url.override";
var gUpdates;
var gUpdateCount;
var gStatus;
var gCheckFunc;
var gNextRunFunc;
var gExpectedResult;
function run_test() {
do_test_pending();
startAUS();
start_httpserver(DIR_DATA);
do_timeout(0, "run_test_pt1()");
}
function end_test() {
stop_httpserver();
do_test_finished();
}
// Helper function for testing mar downloads that have the correct size
// specified in the update xml.
function run_test_helper_pt1(aUpdateXML, aMsg, aResult, aNextRunFunc) {
gUpdates = null;
gUpdateCount = null;
gStatus = null;
gCheckFunc = check_test_helper_pt1_1;
gNextRunFunc = aNextRunFunc;
gExpectedResult = aResult;
var url = URL_PREFIX + aUpdateXML;
dump("Testing: " + aMsg + " - " + url + "\n");
gPrefs.setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
gUpdateChecker.checkForUpdates(updateCheckListener, true);
}
function check_test_helper_pt1_1() {
do_check_eq(gUpdateCount, 1);
gCheckFunc = check_test_helper_pt1_2;
var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
var state = gAUS.downloadUpdate(bestUpdate, false);
if (state == "null" || state == "failed")
do_throw("nsIApplicationUpdateService:downloadUpdate returned " + state);
gAUS.addDownloadListener(downloadListener);
}
function check_test_helper_pt1_2() {
do_check_eq(gStatus, gExpectedResult);
gAUS.removeDownloadListener(downloadListener);
gNextRunFunc();
}
// mar download with a valid MD5 hash
function run_test_pt1() {
run_test_helper_pt1("aus-0030_general-1.xml",
"mar download with a valid MD5 hash",
AUS_Cr.NS_OK, run_test_pt2);
}
// mar download with an invalid MD5 hash
function run_test_pt2() {
run_test_helper_pt1("aus-0030_general-2.xml",
"mar download with an invalid MD5 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt3);
}
// mar download with a valid SHA1 hash
function run_test_pt3() {
run_test_helper_pt1("aus-0030_general-3.xml",
"mar download with a valid SHA1 hash",
AUS_Cr.NS_OK, run_test_pt4);
}
// mar download with an invalid SHA1 hash
function run_test_pt4() {
run_test_helper_pt1("aus-0030_general-4.xml",
"mar download with an invalid SHA1 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt5);
}
// mar download with a valid SHA256 hash
function run_test_pt5() {
run_test_helper_pt1("aus-0030_general-5.xml",
"mar download with a valid SHA256 hash",
AUS_Cr.NS_OK, run_test_pt6);
}
// mar download with an invalid SHA256 hash
function run_test_pt6() {
run_test_helper_pt1("aus-0030_general-6.xml",
"mar download with an invalid SHA256 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt7);
}
// mar download with a valid SHA384 hash
function run_test_pt7() {
run_test_helper_pt1("aus-0030_general-7.xml",
"mar download with a valid SHA384 hash",
AUS_Cr.NS_OK, run_test_pt8);
}
// mar download with an invalid SHA384 hash
function run_test_pt8() {
run_test_helper_pt1("aus-0030_general-8.xml",
"mar download with an invalid SHA384 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt9);
}
// mar download with a valid SHA512 hash
function run_test_pt9() {
run_test_helper_pt1("aus-0030_general-9.xml",
"mar download with a valid SHA512 hash",
AUS_Cr.NS_OK, run_test_pt10);
}
// mar download with an invalid SHA384 hash
function run_test_pt10() {
run_test_helper_pt1("aus-0030_general-10.xml",
"mar download with an invalid SHA512 hash",
AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt11);
}
// mar download with the mar not found
function run_test_pt11() {
run_test_helper_pt1("aus-0030_general-11.xml",
"mar download with the mar not found",
AUS_Cr.NS_ERROR_UNEXPECTED, end_test);
}
// Update check listener
const updateCheckListener = {
onProgress: function(request, position, totalSize) {
},
onCheckComplete: function(request, updates, updateCount) {
gUpdateCount = updateCount;
gUpdates = updates;
dump("onCheckComplete url = " + request.channel.originalURI.spec + "\n\n");
// Use a timeout to allow the XHR to complete
do_timeout(0, "gCheckFunc()");
},
onError: function(request, update) {
dump("onError url = " + request.channel.originalURI.spec + "\n\n");
// Use a timeout to allow the XHR to complete
do_timeout(0, "gCheckFunc()");
},
QueryInterface: function(aIID) {
if (!aIID.equals(AUS_Ci.nsIUpdateCheckListener) &&
!aIID.equals(AUS_Ci.nsISupports))
throw AUS_Cr.NS_ERROR_NO_INTERFACE;
return this;
}
};
/* Update download listener - nsIRequestObserver */
const downloadListener = {
onStartRequest: function(request, context) {
},
onProgress: function(request, context, progress, maxProgress) {
},
onStatus: function(request, context, status, statusText) {
},
onStopRequest: function(request, context, status) {
gStatus = status;
// Use a timeout to allow the request to complete
do_timeout(0, "gCheckFunc()");
},
QueryInterface: function(iid) {
if (!iid.equals(AUS_Ci.nsIRequestObserver) &&
!iid.equals(AUS_Ci.nsIProgressEventSink) &&
!iid.equals(AUS_Ci.nsISupports))
throw Components.results.NS_ERROR_NO_INTERFACE;
return this;
}
};