browser_sanitize-download-history.js
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is mozilla.org Test Code.
15  *
16  * The Initial Developer of the Original Code is
17  * Mozilla Corporation.
18  * Portions created by the Initial Developer are Copyright (C) 2008
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Shawn Wilsher <me@shawnwilsher.com> (Original Author)
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37 
38 
39 function test()
40 {
43 
44  function test_checkedAndDisabledAtStart(aWin)
45  {
46  let doc = aWin.document;
47  let downloads = doc.getElementById("downloads-checkbox");
48  let history = doc.getElementById("history-checkbox");
49 
50  ok(history.checked, "history checkbox is checked");
51  ok(downloads.disabled, "downloads checkbox is disabled");
52  ok(downloads.checked, "downloads checkbox is checked");
53  }
54 
55  function test_checkedAndDisabledOnHistoryToggle(aWin)
56  {
57  let doc = aWin.document;
58  let downloads = doc.getElementById("downloads-checkbox");
59  let history = doc.getElementById("history-checkbox");
60 
61  EventUtils.synthesizeMouse(history, 0, 0, {}, aWin);
62  ok(!history.checked, "history checkbox is not checked");
63  ok(downloads.disabled, "downloads checkbox is disabled");
64  ok(downloads.checked, "downloads checkbox is checked");
65  }
66 
67  function test_checkedAfterAddingDownload(aWin)
68  {
69  let doc = aWin.document;
70  let downloads = doc.getElementById("downloads-checkbox");
71  let history = doc.getElementById("history-checkbox");
72 
73  // Add download to DB
74  let ios = Cc["@mozilla.org/network/io-service;1"].
75  getService(Ci.nsIIOService);
76  let file = Cc["@mozilla.org/file/directory_service;1"].
77  getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
78  file.append("satitize-dm-test.file");
79  file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
80  let testPath = ios.newFileURI(file).spec;
81  let data = {
82  name: "381603.patch",
83  source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520",
84  target: testPath,
85  startTime: 1180493839859230,
86  endTime: 1180493839859239,
87  state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED,
88  currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0
89  };
90  let db = Cc["@mozilla.org/download-manager;1"].
91  getService(Ci.nsIDownloadManager).DBConnection;
92  let rawStmt = db.createStatement(
93  "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " +
94  "state, currBytes, maxBytes, preferredAction, autoResume) " +
95  "VALUES (:name, :source, :target, :startTime, :endTime, :state, " +
96  ":currBytes, :maxBytes, :preferredAction, :autoResume)");
97  let stmt = Cc["@mozilla.org/storage/statement-wrapper;1"].
98  createInstance(Ci.mozIStorageStatementWrapper);
99  stmt.initialize(rawStmt);
100  try {
101  for (let prop in data)
102  stmt.params[prop] = data[prop];
103  stmt.execute();
104  }
105  finally {
106  stmt.statement.finalize();
107  }
108 
109  // Toggle history to get everything to update
110  EventUtils.synthesizeMouse(history, 0, 0, {}, aWin);
111  EventUtils.synthesizeMouse(history, 0, 0, {}, aWin);
112 
113  ok(!history.checked, "history checkbox is not checked");
114  ok(!downloads.disabled, "downloads checkbox is not disabled");
115  ok(downloads.checked, "downloads checkbox is checked");
116  }
117 
118  function test_checkedAndDisabledWithHistoryChecked(aWin)
119  {
120  let doc = aWin.document;
121  let downloads = doc.getElementById("downloads-checkbox");
122  let history = doc.getElementById("history-checkbox");
123 
124  EventUtils.synthesizeMouse(history, 0, 0, {}, aWin);
125  ok(history.checked, "history checkbox is checked");
126  ok(downloads.disabled, "downloads checkbox is disabled");
127  ok(downloads.checked, "downloads checkbox is checked");
128  }
129 
130  let tests = [
131  test_checkedAndDisabledAtStart,
132  test_checkedAndDisabledOnHistoryToggle,
133  test_checkedAfterAddingDownload,
134  test_checkedAndDisabledWithHistoryChecked,
135  ];
136 
139 
140  let dm = Cc["@mozilla.org/download-manager;1"].
141  getService(Ci.nsIDownloadManager);
142  let db = dm.DBConnection;
143 
144  // Empty any old downloads
145  db.executeSimpleSQL("DELETE FROM moz_downloads");
146 
147  // Close the UI if necessary
148  let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
149  getService(Ci.nsIWindowWatcher);
150  let win = ww.getWindowByName("Sanatize", null);
151  if (win && (win instanceof Ci.nsIDOMWindowInternal)) win.close();
152 
153  // Start the test when the sanitize window loads
154  ww.registerNotification({
155  observe: function(aSubject, aTopic, aData) {
156  ww.unregisterNotification(this);
157  aSubject.QueryInterface(Ci.nsIDOMEventTarget).
158  addEventListener("DOMContentLoaded", doTest, false);
159  }
160  });
161 
162  // Let the methods that run onload finish before we test
163  let doTest = function() setTimeout(function() {
164  let win = ww.getWindowByName("Sanitize", null)
165  .QueryInterface(Ci.nsIDOMWindowInternal);
166 
167  for (let i = 0; i < tests.length; i++)
168  tests[i](win);
169 
170  win.close();
171  finish();
172  }, 0);
173 
174  // Show the UI
175  ww.openWindow(window,
176  "chrome://browser/content/sanitize.xul",
177  "Sanitize",
178  "chrome,titlebar,centerscreen",
179  null);
180 
182 }
const Cc
var history
function doc() browser.contentDocument
handlersMenuPopup addEventListener("command", this, false)
sidebarFactory createInstance
Definition: nsSidebar.js:351
getService(Ci.sbIFaceplateManager)
let window
waitForExplicitFinish()
aWindow setTimeout(function(){_this.restoreHistory(aWindow, aTabs, aTabData, aIdMap);}, 0)
return null
Definition: FeedWriter.js:1143
function doTest(array)
const Ci
var ios
Definition: head_feeds.js:5
observe data
Definition: FeedWriter.js:1329
_getSelectedPageStyle s i
_updateTextAndScrollDataForFrame aData
var file
sbDeviceFirmwareAutoCheckForUpdate prototype observe