toolkit/mozapps/update/tests/unit_aus_update/remoteUpdateXML.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4  */
     6 var gNextRunFunc;
     7 var gExpectedCount;
     9 function run_test() {
    10   setupTestCommon();
    12   logTestInfo("testing remote update xml attributes");
    14   setUpdateURLOverride();
    15   setUpdateChannel("test_channel");
    16   // The mock XMLHttpRequest is MUCH faster
    17   overrideXHR(callHandleEvent);
    18   standardInit();
    19   do_execute_soon(run_test_pt01);
    20 }
    22 // Helper function for testing update counts returned from an update xml
    23 function run_test_helper_pt1(aMsg, aExpectedCount, aNextRunFunc) {
    24   gUpdates = null;
    25   gUpdateCount = null;
    26   gCheckFunc = check_test_helper_pt1;
    27   gNextRunFunc = aNextRunFunc;
    28   gExpectedCount = aExpectedCount;
    29   logTestInfo(aMsg, Components.stack.caller);
    30   gUpdateChecker.checkForUpdates(updateCheckListener, true);
    31 }
    33 function check_test_helper_pt1() {
    34   do_check_eq(gUpdateCount, gExpectedCount);
    35   gNextRunFunc();
    36 }
    38 // Callback function used by the custom XMLHttpRequest implementation to
    39 // call the nsIDOMEventListener's handleEvent method for onload.
    40 function callHandleEvent() {
    41   gXHR.status = 400;
    42   gXHR.responseText = gResponseBody;
    43   try {
    44     var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"].
    45                  createInstance(AUS_Ci.nsIDOMParser);
    46     gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml");
    47   } catch (e) {
    48     gXHR.responseXML = null;
    49   }
    50   var e = { target: gXHR };
    51   gXHR.onload(e);
    52 }
    54 // update xml not found
    55 function run_test_pt01() {
    56   run_test_helper_pt1("testing update xml not available",
    57                       null, run_test_pt02);
    58 }
    60 // one update available and the update's property values
    61 function run_test_pt02() {
    62   logTestInfo("testing one update available and the update's property values");
    63   gUpdates = null;
    64   gUpdateCount = null;
    65   gCheckFunc = check_test_pt02;
    66   var patches = getRemotePatchString("complete", "http://complete/", "SHA1",
    67                                      "98db9dad8e1d80eda7e1170d0187d6f53e477059",
    68                                      "9856459");
    69   patches += getRemotePatchString("partial", "http://partial/", "SHA1",
    70                                   "e6678ca40ae7582316acdeddf3c133c9c8577de4",
    71                                   "1316138");
    72   var updates = getRemoteUpdateString(patches, "minor", "Minor Test",
    73                                       "version 2.1a1pre", "2.1a1pre",
    74                                       "3.1a1pre", "20080811053724",
    75                                       "http://details/",
    76                                       "http://billboard/",
    77                                       "http://license/", "true",
    78                                       "true", "345600", "true", "4.1a1pre",
    79                                       "5.1a1pre",
    80                                       "custom1_attr=\"custom1 value\"",
    81                                       "custom2_attr=\"custom2 value\"");
    82   gResponseBody = getRemoteUpdatesXMLString(updates);
    83   gUpdateChecker.checkForUpdates(updateCheckListener, true);
    84 }
    86 function check_test_pt02() {
    87   // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244
    88   // and until this is fixed this will not test the value for detailsURL when it
    89   // isn't specified in the update xml.
    90 //  var defaultDetailsURL;
    91 //  try {
    92     // Try using a default details URL supplied by the distribution
    93     // if the update XML does not supply one.
    94 //    var formatter = AUS_Cc["@mozilla.org/toolkit/URLFormatterService;1"].
    95 //                    getService(AUS_Ci.nsIURLFormatter);
    96 //    defaultDetailsURL = formatter.formatURLPref(PREF_APP_UPDATE_URL_DETAILS);
    97 //  } catch (e) {
    98 //    defaultDetailsURL = "";
    99 //  }
   101   do_check_eq(gUpdateCount, 1);
   102   var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount).QueryInterface(AUS_Ci.nsIPropertyBag);
   103   do_check_eq(bestUpdate.type, "minor");
   104   do_check_eq(bestUpdate.name, "Minor Test");
   105   do_check_eq(bestUpdate.displayVersion, "version 2.1a1pre");
   106   do_check_eq(bestUpdate.appVersion, "2.1a1pre");
   107   do_check_eq(bestUpdate.platformVersion, "3.1a1pre");
   108   do_check_eq(bestUpdate.buildID, "20080811053724");
   109   do_check_eq(bestUpdate.detailsURL, "http://details/");
   110   do_check_eq(bestUpdate.billboardURL, "http://billboard/");
   111   do_check_eq(bestUpdate.licenseURL, "http://license/");
   112   do_check_true(bestUpdate.showPrompt);
   113   do_check_true(bestUpdate.showNeverForVersion);
   114   do_check_eq(bestUpdate.promptWaitTime, "345600");
   115   do_check_eq(bestUpdate.serviceURL, URL_HOST + "/update.xml?force=1");
   116   do_check_eq(bestUpdate.channel, "test_channel");
   117   do_check_false(bestUpdate.isCompleteUpdate);
   118   do_check_false(bestUpdate.isSecurityUpdate);
   119   // Check that installDate is within 10 seconds of the current date.
   120   do_check_true((Date.now() - bestUpdate.installDate) < 10000);
   121   do_check_eq(bestUpdate.statusText, null);
   122   // nsIUpdate:state returns an empty string when no action has been performed
   123   // on an available update
   124   do_check_eq(bestUpdate.state, "");
   125   do_check_eq(bestUpdate.errorCode, 0);
   126   do_check_eq(bestUpdate.patchCount, 2);
   127   //XXX TODO - test nsIUpdate:serialize
   129   do_check_eq(bestUpdate.getProperty("custom1_attr"), "custom1 value");
   130   do_check_eq(bestUpdate.getProperty("custom2_attr"), "custom2 value");
   132   var patch = bestUpdate.getPatchAt(0);
   133   do_check_eq(patch.type, "complete");
   134   do_check_eq(patch.URL, "http://complete/");
   135   do_check_eq(patch.hashFunction, "SHA1");
   136   do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059");
   137   do_check_eq(patch.size, 9856459);
   138   // The value for patch.state can be the string 'null' as a valid value. This
   139   // is confusing if it returns null which is an invalid value since the test
   140   // failure output will show a failure for null == null. To lessen the
   141   // confusion first check that the typeof for patch.state is string.
   142   do_check_eq(typeof(patch.state), "string");
   143   do_check_eq(patch.state, STATE_NONE);
   144   do_check_false(patch.selected);
   145   //XXX TODO - test nsIUpdatePatch:serialize
   147   patch = bestUpdate.getPatchAt(1);
   148   do_check_eq(patch.type, "partial");
   149   do_check_eq(patch.URL, "http://partial/");
   150   do_check_eq(patch.hashFunction, "SHA1");
   151   do_check_eq(patch.hashValue, "e6678ca40ae7582316acdeddf3c133c9c8577de4");
   152   do_check_eq(patch.size, 1316138);
   153   do_check_eq(patch.state, STATE_NONE);
   154   do_check_false(patch.selected);
   155   //XXX TODO - test nsIUpdatePatch:serialize
   157   run_test_pt03();
   158 }
   160 // one update available and the update's property default values
   161 function run_test_pt03() {
   162   logTestInfo("testing one update available and the update's property values " +
   163               "with the format prior to bug 530872");
   164   gUpdates = null;
   165   gUpdateCount = null;
   166   gCheckFunc = check_test_pt03;
   167   var patches = getRemotePatchString("complete", "http://complete/", "SHA1",
   168                                      "98db9dad8e1d80eda7e1170d0187d6f53e477059",
   169                                      "9856459");
   170   var updates = getRemoteUpdateString(patches, "major", "Major Test",
   171                                       null, null,
   172                                       "5.1a1pre", "20080811053724",
   173                                       "http://details/",
   174                                       null, null, null, null, "691200",
   175                                       null, "version 4.1a1pre", "4.1a1pre");
   176   gResponseBody = getRemoteUpdatesXMLString(updates);
   177   gUpdateChecker.checkForUpdates(updateCheckListener, true);
   178 }
   180 function check_test_pt03() {
   181   do_check_eq(gUpdateCount, 1);
   182   var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
   183   do_check_eq(bestUpdate.type, "major");
   184   do_check_eq(bestUpdate.name, "Major Test");
   185   do_check_eq(bestUpdate.displayVersion, "version 4.1a1pre");
   186   do_check_eq(bestUpdate.appVersion, "4.1a1pre");
   187   do_check_eq(bestUpdate.platformVersion, "5.1a1pre");
   188   do_check_eq(bestUpdate.buildID, "20080811053724");
   189   do_check_eq(bestUpdate.detailsURL, "http://details/");
   190   do_check_eq(bestUpdate.billboardURL, "http://details/");
   191   do_check_eq(bestUpdate.licenseURL, null);
   192   do_check_true(bestUpdate.showPrompt);
   193   do_check_true(bestUpdate.showNeverForVersion);
   194   do_check_eq(bestUpdate.promptWaitTime, "691200");
   195   do_check_eq(bestUpdate.serviceURL, URL_HOST + "/update.xml?force=1");
   196   do_check_eq(bestUpdate.channel, "test_channel");
   197   do_check_false(bestUpdate.isCompleteUpdate);
   198   do_check_false(bestUpdate.isSecurityUpdate);
   199   // Check that installDate is within 10 seconds of the current date.
   200   do_check_true((Date.now() - bestUpdate.installDate) < 10000);
   201   do_check_eq(bestUpdate.statusText, null);
   202   // nsIUpdate:state returns an empty string when no action has been performed
   203   // on an available update
   204   do_check_eq(bestUpdate.state, "");
   205   do_check_eq(bestUpdate.errorCode, 0);
   206   do_check_eq(bestUpdate.patchCount, 1);
   207   //XXX TODO - test nsIUpdate:serialize
   209   var patch = bestUpdate.getPatchAt(0);
   210   do_check_eq(patch.type, "complete");
   211   do_check_eq(patch.URL, "http://complete/");
   212   do_check_eq(patch.hashFunction, "SHA1");
   213   do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059");
   214   do_check_eq(patch.size, 9856459);
   215   // The value for patch.state can be the string 'null' as a valid value. This
   216   // is confusing if it returns null which is an invalid value since the test
   217   // failure output will show a failure for null == null. To lessen the
   218   // confusion first check that the typeof for patch.state is string.
   219   do_check_eq(typeof(patch.state), "string");
   220   do_check_eq(patch.state, STATE_NONE);
   221   do_check_false(patch.selected);
   222   //XXX TODO - test nsIUpdatePatch:serialize
   224   run_test_pt04();
   225 }
   227 // Empty update xml
   228 function run_test_pt04() {
   229   gResponseBody = "\n";
   230   run_test_helper_pt1("testing empty update xml",
   231                       null, run_test_pt05);
   232 }
   234 // no updates available
   235 function run_test_pt05() {
   236   gResponseBody = getRemoteUpdatesXMLString("");
   237   run_test_helper_pt1("testing no updates available",
   238                       0, run_test_pt06);
   239 }
   241 // one update available with two patches
   242 function run_test_pt06() {
   243   var patches = getRemotePatchString("complete");
   244   patches += getRemotePatchString("partial");
   245   var updates = getRemoteUpdateString(patches);
   246   gResponseBody = getRemoteUpdatesXMLString(updates);
   247   run_test_helper_pt1("testing one update available",
   248                       1, run_test_pt07);
   249 }
   251 // three updates available each with two patches
   252 function run_test_pt07() {
   253   var patches = getRemotePatchString("complete");
   254   patches += getRemotePatchString("partial");
   255   var updates = getRemoteUpdateString(patches);
   256   updates += getRemoteUpdateString(patches);
   257   updates += getRemoteUpdateString(patches);
   258   gResponseBody = getRemoteUpdatesXMLString(updates);
   259   run_test_helper_pt1("testing three updates available",
   260                       3, run_test_pt08);
   261 }
   263 // one update with complete and partial patches with size 0 specified in the
   264 // update xml
   265 function run_test_pt08() {
   266   var patches = getRemotePatchString("complete", null, null, null, "0");
   267   patches += getRemotePatchString("partial", null, null, null, "0");
   268   var updates = getRemoteUpdateString(patches);
   269   gResponseBody = getRemoteUpdatesXMLString(updates);
   270   run_test_helper_pt1("testing one update with complete and partial " +
   271                       "patches with size 0", 0, run_test_pt09);
   272 }
   274 // one update with complete patch with size 0 specified in the update xml
   275 function run_test_pt09() {
   276   var patches = getRemotePatchString("complete", null, null, null, "0");
   277   var updates = getRemoteUpdateString(patches);
   278   gResponseBody = getRemoteUpdatesXMLString(updates);
   279   run_test_helper_pt1("testing one update with complete patch with size 0",
   280                       0, run_test_pt10);
   281 }
   283 // one update with partial patch with size 0 specified in the update xml
   284 function run_test_pt10() {
   285   var patches = getRemotePatchString("partial", null, null, null, "0");
   286   var updates = getRemoteUpdateString(patches);
   287   gResponseBody = getRemoteUpdatesXMLString(updates);
   288   run_test_helper_pt1("testing one update with partial patch with size 0",
   289                       0, run_test_pt11);
   290 }
   292 // check that updates for older versions of the application aren't selected
   293 function run_test_pt11() {
   294   var patches = getRemotePatchString("complete");
   295   patches += getRemotePatchString("partial");
   296   var updates = getRemoteUpdateString(patches, "minor", null, null, "1.0pre");
   297   updates += getRemoteUpdateString(patches, "minor", null, null, "1.0a");
   298   gResponseBody = getRemoteUpdatesXMLString(updates);
   299   run_test_helper_pt1("testing two updates older than the current version",
   300                       2, check_test_pt11);
   301 }
   303 function check_test_pt11() {
   304   var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
   305   do_check_eq(bestUpdate, null);
   306   run_test_pt12();
   307 }
   309 // check that updates for the current version of the application are selected
   310 function run_test_pt12() {
   311   var patches = getRemotePatchString("complete");
   312   patches += getRemotePatchString("partial");
   313   var updates = getRemoteUpdateString(patches, "minor", null, "version 1.0");
   314   gResponseBody = getRemoteUpdatesXMLString(updates);
   315   run_test_helper_pt1("testing one update equal to the current version",
   316                       1, check_test_pt12);
   317 }
   319 function check_test_pt12() {
   320   var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount);
   321   do_check_neq(bestUpdate, null);
   322   do_check_eq(bestUpdate.displayVersion, "version 1.0");
   324   doTestFinish();
   325 }

mercurial