michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: var gNextRunFunc; michael@0: var gExpectedCount; michael@0: michael@0: function run_test() { michael@0: setupTestCommon(); michael@0: michael@0: logTestInfo("testing remote update xml attributes"); michael@0: michael@0: setUpdateURLOverride(); michael@0: setUpdateChannel("test_channel"); michael@0: // The mock XMLHttpRequest is MUCH faster michael@0: overrideXHR(callHandleEvent); michael@0: standardInit(); michael@0: do_execute_soon(run_test_pt01); michael@0: } michael@0: michael@0: // Helper function for testing update counts returned from an update xml michael@0: function run_test_helper_pt1(aMsg, aExpectedCount, aNextRunFunc) { michael@0: gUpdates = null; michael@0: gUpdateCount = null; michael@0: gCheckFunc = check_test_helper_pt1; michael@0: gNextRunFunc = aNextRunFunc; michael@0: gExpectedCount = aExpectedCount; michael@0: logTestInfo(aMsg, Components.stack.caller); michael@0: gUpdateChecker.checkForUpdates(updateCheckListener, true); michael@0: } michael@0: michael@0: function check_test_helper_pt1() { michael@0: do_check_eq(gUpdateCount, gExpectedCount); michael@0: gNextRunFunc(); michael@0: } michael@0: michael@0: // Callback function used by the custom XMLHttpRequest implementation to michael@0: // call the nsIDOMEventListener's handleEvent method for onload. michael@0: function callHandleEvent() { michael@0: gXHR.status = 400; michael@0: gXHR.responseText = gResponseBody; michael@0: try { michael@0: var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"]. michael@0: createInstance(AUS_Ci.nsIDOMParser); michael@0: gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); michael@0: } catch (e) { michael@0: gXHR.responseXML = null; michael@0: } michael@0: var e = { target: gXHR }; michael@0: gXHR.onload(e); michael@0: } michael@0: michael@0: // update xml not found michael@0: function run_test_pt01() { michael@0: run_test_helper_pt1("testing update xml not available", michael@0: null, run_test_pt02); michael@0: } michael@0: michael@0: // one update available and the update's property values michael@0: function run_test_pt02() { michael@0: logTestInfo("testing one update available and the update's property values"); michael@0: gUpdates = null; michael@0: gUpdateCount = null; michael@0: gCheckFunc = check_test_pt02; michael@0: var patches = getRemotePatchString("complete", "http://complete/", "SHA1", michael@0: "98db9dad8e1d80eda7e1170d0187d6f53e477059", michael@0: "9856459"); michael@0: patches += getRemotePatchString("partial", "http://partial/", "SHA1", michael@0: "e6678ca40ae7582316acdeddf3c133c9c8577de4", michael@0: "1316138"); michael@0: var updates = getRemoteUpdateString(patches, "minor", "Minor Test", michael@0: "version 2.1a1pre", "2.1a1pre", michael@0: "3.1a1pre", "20080811053724", michael@0: "http://details/", michael@0: "http://billboard/", michael@0: "http://license/", "true", michael@0: "true", "345600", "true", "4.1a1pre", michael@0: "5.1a1pre", michael@0: "custom1_attr=\"custom1 value\"", michael@0: "custom2_attr=\"custom2 value\""); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: gUpdateChecker.checkForUpdates(updateCheckListener, true); michael@0: } michael@0: michael@0: function check_test_pt02() { michael@0: // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244 michael@0: // and until this is fixed this will not test the value for detailsURL when it michael@0: // isn't specified in the update xml. michael@0: // var defaultDetailsURL; michael@0: // try { michael@0: // Try using a default details URL supplied by the distribution michael@0: // if the update XML does not supply one. michael@0: // var formatter = AUS_Cc["@mozilla.org/toolkit/URLFormatterService;1"]. michael@0: // getService(AUS_Ci.nsIURLFormatter); michael@0: // defaultDetailsURL = formatter.formatURLPref(PREF_APP_UPDATE_URL_DETAILS); michael@0: // } catch (e) { michael@0: // defaultDetailsURL = ""; michael@0: // } michael@0: michael@0: do_check_eq(gUpdateCount, 1); michael@0: var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount).QueryInterface(AUS_Ci.nsIPropertyBag); michael@0: do_check_eq(bestUpdate.type, "minor"); michael@0: do_check_eq(bestUpdate.name, "Minor Test"); michael@0: do_check_eq(bestUpdate.displayVersion, "version 2.1a1pre"); michael@0: do_check_eq(bestUpdate.appVersion, "2.1a1pre"); michael@0: do_check_eq(bestUpdate.platformVersion, "3.1a1pre"); michael@0: do_check_eq(bestUpdate.buildID, "20080811053724"); michael@0: do_check_eq(bestUpdate.detailsURL, "http://details/"); michael@0: do_check_eq(bestUpdate.billboardURL, "http://billboard/"); michael@0: do_check_eq(bestUpdate.licenseURL, "http://license/"); michael@0: do_check_true(bestUpdate.showPrompt); michael@0: do_check_true(bestUpdate.showNeverForVersion); michael@0: do_check_eq(bestUpdate.promptWaitTime, "345600"); michael@0: do_check_eq(bestUpdate.serviceURL, URL_HOST + "/update.xml?force=1"); michael@0: do_check_eq(bestUpdate.channel, "test_channel"); michael@0: do_check_false(bestUpdate.isCompleteUpdate); michael@0: do_check_false(bestUpdate.isSecurityUpdate); michael@0: // Check that installDate is within 10 seconds of the current date. michael@0: do_check_true((Date.now() - bestUpdate.installDate) < 10000); michael@0: do_check_eq(bestUpdate.statusText, null); michael@0: // nsIUpdate:state returns an empty string when no action has been performed michael@0: // on an available update michael@0: do_check_eq(bestUpdate.state, ""); michael@0: do_check_eq(bestUpdate.errorCode, 0); michael@0: do_check_eq(bestUpdate.patchCount, 2); michael@0: //XXX TODO - test nsIUpdate:serialize michael@0: michael@0: do_check_eq(bestUpdate.getProperty("custom1_attr"), "custom1 value"); michael@0: do_check_eq(bestUpdate.getProperty("custom2_attr"), "custom2 value"); michael@0: michael@0: var patch = bestUpdate.getPatchAt(0); michael@0: do_check_eq(patch.type, "complete"); michael@0: do_check_eq(patch.URL, "http://complete/"); michael@0: do_check_eq(patch.hashFunction, "SHA1"); michael@0: do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059"); michael@0: do_check_eq(patch.size, 9856459); michael@0: // The value for patch.state can be the string 'null' as a valid value. This michael@0: // is confusing if it returns null which is an invalid value since the test michael@0: // failure output will show a failure for null == null. To lessen the michael@0: // confusion first check that the typeof for patch.state is string. michael@0: do_check_eq(typeof(patch.state), "string"); michael@0: do_check_eq(patch.state, STATE_NONE); michael@0: do_check_false(patch.selected); michael@0: //XXX TODO - test nsIUpdatePatch:serialize michael@0: michael@0: patch = bestUpdate.getPatchAt(1); michael@0: do_check_eq(patch.type, "partial"); michael@0: do_check_eq(patch.URL, "http://partial/"); michael@0: do_check_eq(patch.hashFunction, "SHA1"); michael@0: do_check_eq(patch.hashValue, "e6678ca40ae7582316acdeddf3c133c9c8577de4"); michael@0: do_check_eq(patch.size, 1316138); michael@0: do_check_eq(patch.state, STATE_NONE); michael@0: do_check_false(patch.selected); michael@0: //XXX TODO - test nsIUpdatePatch:serialize michael@0: michael@0: run_test_pt03(); michael@0: } michael@0: michael@0: // one update available and the update's property default values michael@0: function run_test_pt03() { michael@0: logTestInfo("testing one update available and the update's property values " + michael@0: "with the format prior to bug 530872"); michael@0: gUpdates = null; michael@0: gUpdateCount = null; michael@0: gCheckFunc = check_test_pt03; michael@0: var patches = getRemotePatchString("complete", "http://complete/", "SHA1", michael@0: "98db9dad8e1d80eda7e1170d0187d6f53e477059", michael@0: "9856459"); michael@0: var updates = getRemoteUpdateString(patches, "major", "Major Test", michael@0: null, null, michael@0: "5.1a1pre", "20080811053724", michael@0: "http://details/", michael@0: null, null, null, null, "691200", michael@0: null, "version 4.1a1pre", "4.1a1pre"); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: gUpdateChecker.checkForUpdates(updateCheckListener, true); michael@0: } michael@0: michael@0: function check_test_pt03() { michael@0: do_check_eq(gUpdateCount, 1); michael@0: var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); michael@0: do_check_eq(bestUpdate.type, "major"); michael@0: do_check_eq(bestUpdate.name, "Major Test"); michael@0: do_check_eq(bestUpdate.displayVersion, "version 4.1a1pre"); michael@0: do_check_eq(bestUpdate.appVersion, "4.1a1pre"); michael@0: do_check_eq(bestUpdate.platformVersion, "5.1a1pre"); michael@0: do_check_eq(bestUpdate.buildID, "20080811053724"); michael@0: do_check_eq(bestUpdate.detailsURL, "http://details/"); michael@0: do_check_eq(bestUpdate.billboardURL, "http://details/"); michael@0: do_check_eq(bestUpdate.licenseURL, null); michael@0: do_check_true(bestUpdate.showPrompt); michael@0: do_check_true(bestUpdate.showNeverForVersion); michael@0: do_check_eq(bestUpdate.promptWaitTime, "691200"); michael@0: do_check_eq(bestUpdate.serviceURL, URL_HOST + "/update.xml?force=1"); michael@0: do_check_eq(bestUpdate.channel, "test_channel"); michael@0: do_check_false(bestUpdate.isCompleteUpdate); michael@0: do_check_false(bestUpdate.isSecurityUpdate); michael@0: // Check that installDate is within 10 seconds of the current date. michael@0: do_check_true((Date.now() - bestUpdate.installDate) < 10000); michael@0: do_check_eq(bestUpdate.statusText, null); michael@0: // nsIUpdate:state returns an empty string when no action has been performed michael@0: // on an available update michael@0: do_check_eq(bestUpdate.state, ""); michael@0: do_check_eq(bestUpdate.errorCode, 0); michael@0: do_check_eq(bestUpdate.patchCount, 1); michael@0: //XXX TODO - test nsIUpdate:serialize michael@0: michael@0: var patch = bestUpdate.getPatchAt(0); michael@0: do_check_eq(patch.type, "complete"); michael@0: do_check_eq(patch.URL, "http://complete/"); michael@0: do_check_eq(patch.hashFunction, "SHA1"); michael@0: do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059"); michael@0: do_check_eq(patch.size, 9856459); michael@0: // The value for patch.state can be the string 'null' as a valid value. This michael@0: // is confusing if it returns null which is an invalid value since the test michael@0: // failure output will show a failure for null == null. To lessen the michael@0: // confusion first check that the typeof for patch.state is string. michael@0: do_check_eq(typeof(patch.state), "string"); michael@0: do_check_eq(patch.state, STATE_NONE); michael@0: do_check_false(patch.selected); michael@0: //XXX TODO - test nsIUpdatePatch:serialize michael@0: michael@0: run_test_pt04(); michael@0: } michael@0: michael@0: // Empty update xml michael@0: function run_test_pt04() { michael@0: gResponseBody = "\n"; michael@0: run_test_helper_pt1("testing empty update xml", michael@0: null, run_test_pt05); michael@0: } michael@0: michael@0: // no updates available michael@0: function run_test_pt05() { michael@0: gResponseBody = getRemoteUpdatesXMLString(""); michael@0: run_test_helper_pt1("testing no updates available", michael@0: 0, run_test_pt06); michael@0: } michael@0: michael@0: // one update available with two patches michael@0: function run_test_pt06() { michael@0: var patches = getRemotePatchString("complete"); michael@0: patches += getRemotePatchString("partial"); michael@0: var updates = getRemoteUpdateString(patches); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: run_test_helper_pt1("testing one update available", michael@0: 1, run_test_pt07); michael@0: } michael@0: michael@0: // three updates available each with two patches michael@0: function run_test_pt07() { michael@0: var patches = getRemotePatchString("complete"); michael@0: patches += getRemotePatchString("partial"); michael@0: var updates = getRemoteUpdateString(patches); michael@0: updates += getRemoteUpdateString(patches); michael@0: updates += getRemoteUpdateString(patches); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: run_test_helper_pt1("testing three updates available", michael@0: 3, run_test_pt08); michael@0: } michael@0: michael@0: // one update with complete and partial patches with size 0 specified in the michael@0: // update xml michael@0: function run_test_pt08() { michael@0: var patches = getRemotePatchString("complete", null, null, null, "0"); michael@0: patches += getRemotePatchString("partial", null, null, null, "0"); michael@0: var updates = getRemoteUpdateString(patches); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: run_test_helper_pt1("testing one update with complete and partial " + michael@0: "patches with size 0", 0, run_test_pt09); michael@0: } michael@0: michael@0: // one update with complete patch with size 0 specified in the update xml michael@0: function run_test_pt09() { michael@0: var patches = getRemotePatchString("complete", null, null, null, "0"); michael@0: var updates = getRemoteUpdateString(patches); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: run_test_helper_pt1("testing one update with complete patch with size 0", michael@0: 0, run_test_pt10); michael@0: } michael@0: michael@0: // one update with partial patch with size 0 specified in the update xml michael@0: function run_test_pt10() { michael@0: var patches = getRemotePatchString("partial", null, null, null, "0"); michael@0: var updates = getRemoteUpdateString(patches); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: run_test_helper_pt1("testing one update with partial patch with size 0", michael@0: 0, run_test_pt11); michael@0: } michael@0: michael@0: // check that updates for older versions of the application aren't selected michael@0: function run_test_pt11() { michael@0: var patches = getRemotePatchString("complete"); michael@0: patches += getRemotePatchString("partial"); michael@0: var updates = getRemoteUpdateString(patches, "minor", null, null, "1.0pre"); michael@0: updates += getRemoteUpdateString(patches, "minor", null, null, "1.0a"); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: run_test_helper_pt1("testing two updates older than the current version", michael@0: 2, check_test_pt11); michael@0: } michael@0: michael@0: function check_test_pt11() { michael@0: var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); michael@0: do_check_eq(bestUpdate, null); michael@0: run_test_pt12(); michael@0: } michael@0: michael@0: // check that updates for the current version of the application are selected michael@0: function run_test_pt12() { michael@0: var patches = getRemotePatchString("complete"); michael@0: patches += getRemotePatchString("partial"); michael@0: var updates = getRemoteUpdateString(patches, "minor", null, "version 1.0"); michael@0: gResponseBody = getRemoteUpdatesXMLString(updates); michael@0: run_test_helper_pt1("testing one update equal to the current version", michael@0: 1, check_test_pt12); michael@0: } michael@0: michael@0: function check_test_pt12() { michael@0: var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); michael@0: do_check_neq(bestUpdate, null); michael@0: do_check_eq(bestUpdate.displayVersion, "version 1.0"); michael@0: michael@0: doTestFinish(); michael@0: }