toolkit/mozapps/downloads/tests/chrome/test_clear_button_disabled.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <?xml version="1.0"?>
     2 <!-- This Source Code Form is subject to the terms of the Mozilla Public
     3    - License, v. 2.0. If a copy of the MPL was not distributed with this
     4    - file, You can obtain one at http://mozilla.org/MPL/2.0/.  -->
     5 <!--
     6  * This tests 437422.  This test basically intends to checks if the clear list
     7  * button is disabled when:
     8  * 1.  an invalid search string has been entered into the search box.
     9  * 2.  active downloads are present in the dm ui
    10  * 3.  we have both case (1) and (2)
    11 -->
    13 <window title="Download Manager Test"
    14         onload="runTest();"
    15         xmlns:html="http://www.w3.org/1999/xhtml"
    16         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    18   <script type="application/javascript"
    19           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    20   <script type="application/javascript"
    21           src="utils.js"/>
    23   <script type="application/javascript">
    25   <![CDATA[
    27 let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    28 let dmFile = Cc["@mozilla.org/file/directory_service;1"].
    29              getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
    30 dmFile.append("dm-ui-test.file");
    31 dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    32 let gTestPath = ios.newFileURI(dmFile).spec;
    34 const DoneDownloadData = [
    35   { name: "Dead",
    36     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    37     target: gTestPath,
    38     startTime: 1180493839859230,
    39     endTime: 1180493839859239,
    40     state: Ci.nsIDownloadManager.DOWNLOAD_CANCELED,
    41     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
    42 ];
    44 const ActiveDownloadData = [
    45   { name: "Patch",
    46     source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    47     target: gTestPath,
    48     startTime: 1180493839859230,
    49     endTime: 1180493839859239,
    50     state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
    51     currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
    52 ];
    54 function runTest()
    55 {
    56   var dmui = getDMUI();
    57   if (!dmui) {
    58     todo(false, "skip test for toolkit download manager UI");
    59     return;
    60   }
    62   setCleanState();
    63   populateDM(DoneDownloadData);
    65   let obs = Cc["@mozilla.org/observer-service;1"].
    66             getService(Ci.nsIObserverService);
    67   const DLMGR_UI_DONE = "download-manager-ui-done";
    69   let testPhase = 0;
    70   let testObs = {
    71     observe: function(aSubject, aTopic, aData) {
    72       let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    73       win.focus();
    74       let doc = win.document;
    75       let searchbox = doc.getElementById("searchbox");
    76       let clearButton = doc.getElementById("clearListButton");
    78       switch (testPhase++) {
    79         case 0:
    80           // Ensure that the clear list button is enabled at first
    81           ok(!clearButton.disabled,
    82              "The clear list button is  not disabled initially.");
    84           // Now, insert an nonsensical search string - nothing should show up,
    85           // and the button should be disabled in the next test phase
    86           searchbox.value = "Nonsensical";
    87           searchbox.doCommand();
    89           break;
    90         case 1:
    91           ok(clearButton.disabled,
    92              "The clear list button is disabled with a nonsensical search " +
    93              "term entered");
    95           // Clear the search box
    96           searchbox.value = "";
    97           searchbox.doCommand();
    98           break;
   100         case 2:
   101           // Populate the download manager with an active download now, and
   102           // rebuild the list
   103           let dm = Cc["@mozilla.org/download-manager;1"].
   104                    getService(Ci.nsIDownloadManager);
   105           populateDM(ActiveDownloadData);
   106           dm.cleanUp();
   108           break;
   109         case 3:
   110           ok(clearButton.disabled,
   111              "The clear list button is disabled when we only have an active " +
   112              "download");
   114           // Now, insert an nonsensical search string - only the active download
   115           // should show up, and the button should be disabled in the next test
   116           // phase
   117           searchbox.value = "Nonsensical";
   118           searchbox.doCommand();
   119           break;
   120         case 4:
   121           ok(clearButton.disabled,
   122              "The clear list button is disabled with a nonsensical search " +
   123              "term entered and one active download");
   125           obs.removeObserver(testObs, DLMGR_UI_DONE);
   126           setCleanState();
   127           SimpleTest.finish();
   129           break;
   130       }
   131     }
   132   };
   134   obs.addObserver(testObs, DLMGR_UI_DONE, false);
   136   dmui.show();
   138   SimpleTest.waitForExplicitFinish();
   139 }
   141   ]]>
   142   </script>
   144   <body xmlns="http://www.w3.org/1999/xhtml">
   145     <p id="display"></p>
   146     <div id="content" style="display: none"></div>
   147     <pre id="test"></pre>
   148   </body>
   149 </window>

mercurial