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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/downloads/tests/chrome/test_clear_button_disabled.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,149 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<!-- This Source Code Form is subject to the terms of the Mozilla Public
     1.6 +   - License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 +   - file, You can obtain one at http://mozilla.org/MPL/2.0/.  -->
     1.8 +<!--
     1.9 + * This tests 437422.  This test basically intends to checks if the clear list
    1.10 + * button is disabled when:
    1.11 + * 1.  an invalid search string has been entered into the search box.
    1.12 + * 2.  active downloads are present in the dm ui
    1.13 + * 3.  we have both case (1) and (2)
    1.14 +-->
    1.15 +
    1.16 +<window title="Download Manager Test"
    1.17 +        onload="runTest();"
    1.18 +        xmlns:html="http://www.w3.org/1999/xhtml"
    1.19 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.20 +
    1.21 +  <script type="application/javascript"
    1.22 +          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    1.23 +  <script type="application/javascript"
    1.24 +          src="utils.js"/>
    1.25 +
    1.26 +  <script type="application/javascript">
    1.27 +
    1.28 +  <![CDATA[
    1.29 +
    1.30 +let ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    1.31 +let dmFile = Cc["@mozilla.org/file/directory_service;1"].
    1.32 +             getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
    1.33 +dmFile.append("dm-ui-test.file");
    1.34 +dmFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    1.35 +let gTestPath = ios.newFileURI(dmFile).spec;
    1.36 +
    1.37 +const DoneDownloadData = [
    1.38 +  { name: "Dead",
    1.39 +    source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    1.40 +    target: gTestPath,
    1.41 +    startTime: 1180493839859230,
    1.42 +    endTime: 1180493839859239,
    1.43 +    state: Ci.nsIDownloadManager.DOWNLOAD_CANCELED,
    1.44 +    currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
    1.45 +];
    1.46 +
    1.47 +const ActiveDownloadData = [
    1.48 +  { name: "Patch",
    1.49 +    source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
    1.50 +    target: gTestPath,
    1.51 +    startTime: 1180493839859230,
    1.52 +    endTime: 1180493839859239,
    1.53 +    state: Ci.nsIDownloadManager.DOWNLOAD_DOWNLOADING,
    1.54 +    currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0 }
    1.55 +];
    1.56 +
    1.57 +function runTest()
    1.58 +{
    1.59 +  var dmui = getDMUI();
    1.60 +  if (!dmui) {
    1.61 +    todo(false, "skip test for toolkit download manager UI");
    1.62 +    return;
    1.63 +  }
    1.64 +
    1.65 +  setCleanState();
    1.66 +  populateDM(DoneDownloadData);
    1.67 +
    1.68 +  let obs = Cc["@mozilla.org/observer-service;1"].
    1.69 +            getService(Ci.nsIObserverService);
    1.70 +  const DLMGR_UI_DONE = "download-manager-ui-done";
    1.71 +
    1.72 +  let testPhase = 0;
    1.73 +  let testObs = {
    1.74 +    observe: function(aSubject, aTopic, aData) {
    1.75 +      let win = aSubject.QueryInterface(Ci.nsIDOMWindow);
    1.76 +      win.focus();
    1.77 +      let doc = win.document;
    1.78 +      let searchbox = doc.getElementById("searchbox");
    1.79 +      let clearButton = doc.getElementById("clearListButton");
    1.80 +
    1.81 +      switch (testPhase++) {
    1.82 +        case 0:
    1.83 +          // Ensure that the clear list button is enabled at first
    1.84 +          ok(!clearButton.disabled,
    1.85 +             "The clear list button is  not disabled initially.");
    1.86 +
    1.87 +          // Now, insert an nonsensical search string - nothing should show up,
    1.88 +          // and the button should be disabled in the next test phase
    1.89 +          searchbox.value = "Nonsensical";
    1.90 +          searchbox.doCommand();
    1.91 +
    1.92 +          break;
    1.93 +        case 1:
    1.94 +          ok(clearButton.disabled,
    1.95 +             "The clear list button is disabled with a nonsensical search " +
    1.96 +             "term entered");
    1.97 +
    1.98 +          // Clear the search box
    1.99 +          searchbox.value = "";
   1.100 +          searchbox.doCommand();
   1.101 +          break;
   1.102 +
   1.103 +        case 2:
   1.104 +          // Populate the download manager with an active download now, and
   1.105 +          // rebuild the list
   1.106 +          let dm = Cc["@mozilla.org/download-manager;1"].
   1.107 +                   getService(Ci.nsIDownloadManager);
   1.108 +          populateDM(ActiveDownloadData);
   1.109 +          dm.cleanUp();
   1.110 +
   1.111 +          break;
   1.112 +        case 3:
   1.113 +          ok(clearButton.disabled,
   1.114 +             "The clear list button is disabled when we only have an active " +
   1.115 +             "download");
   1.116 +
   1.117 +          // Now, insert an nonsensical search string - only the active download
   1.118 +          // should show up, and the button should be disabled in the next test
   1.119 +          // phase
   1.120 +          searchbox.value = "Nonsensical";
   1.121 +          searchbox.doCommand();
   1.122 +          break;
   1.123 +        case 4:
   1.124 +          ok(clearButton.disabled,
   1.125 +             "The clear list button is disabled with a nonsensical search " +
   1.126 +             "term entered and one active download");
   1.127 +
   1.128 +          obs.removeObserver(testObs, DLMGR_UI_DONE);
   1.129 +          setCleanState();
   1.130 +          SimpleTest.finish();
   1.131 +
   1.132 +          break;
   1.133 +      }
   1.134 +    }
   1.135 +  };
   1.136 +
   1.137 +  obs.addObserver(testObs, DLMGR_UI_DONE, false);
   1.138 +
   1.139 +  dmui.show();
   1.140 +
   1.141 +  SimpleTest.waitForExplicitFinish();
   1.142 +}
   1.143 +
   1.144 +  ]]>
   1.145 +  </script>
   1.146 +
   1.147 +  <body xmlns="http://www.w3.org/1999/xhtml">
   1.148 +    <p id="display"></p>
   1.149 +    <div id="content" style="display: none"></div>
   1.150 +    <pre id="test"></pre>
   1.151 +  </body>
   1.152 +</window>

mercurial