|
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 |
|
5 |
|
6 function test() |
|
7 { |
|
8 ////////////////////////////////////////////////////////////////////////////// |
|
9 //// Tests (defined locally for scope's sake) |
|
10 |
|
11 function test_checkedAndDisabledAtStart(aWin) |
|
12 { |
|
13 let doc = aWin.document; |
|
14 let downloads = doc.getElementById("downloads-checkbox"); |
|
15 let history = doc.getElementById("history-checkbox"); |
|
16 |
|
17 ok(history.checked, "history checkbox is checked"); |
|
18 ok(downloads.disabled, "downloads checkbox is disabled"); |
|
19 ok(downloads.checked, "downloads checkbox is checked"); |
|
20 } |
|
21 |
|
22 function test_checkedAndDisabledOnHistoryToggle(aWin) |
|
23 { |
|
24 let doc = aWin.document; |
|
25 let downloads = doc.getElementById("downloads-checkbox"); |
|
26 let history = doc.getElementById("history-checkbox"); |
|
27 |
|
28 EventUtils.synthesizeMouse(history, 0, 0, {}, aWin); |
|
29 ok(!history.checked, "history checkbox is not checked"); |
|
30 ok(downloads.disabled, "downloads checkbox is disabled"); |
|
31 ok(downloads.checked, "downloads checkbox is checked"); |
|
32 } |
|
33 |
|
34 function test_checkedAfterAddingDownload(aWin) |
|
35 { |
|
36 let doc = aWin.document; |
|
37 let downloads = doc.getElementById("downloads-checkbox"); |
|
38 let history = doc.getElementById("history-checkbox"); |
|
39 |
|
40 // Add download to DB |
|
41 let file = Cc["@mozilla.org/file/directory_service;1"]. |
|
42 getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile); |
|
43 file.append("sanitize-dm-test.file"); |
|
44 file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
|
45 let testPath = Services.io.newFileURI(file).spec; |
|
46 let data = { |
|
47 name: "381603.patch", |
|
48 source: "https://bugzilla.mozilla.org/attachment.cgi?id=266520", |
|
49 target: testPath, |
|
50 startTime: 1180493839859230, |
|
51 endTime: 1180493839859239, |
|
52 state: Ci.nsIDownloadManager.DOWNLOAD_FINISHED, |
|
53 currBytes: 0, maxBytes: -1, preferredAction: 0, autoResume: 0, |
|
54 guid: "a1bcD23eF4g5" |
|
55 }; |
|
56 let db = Cc["@mozilla.org/download-manager;1"]. |
|
57 getService(Ci.nsIDownloadManager).DBConnection; |
|
58 let stmt = db.createStatement( |
|
59 "INSERT INTO moz_downloads (name, source, target, startTime, endTime, " + |
|
60 "state, currBytes, maxBytes, preferredAction, autoResume, guid) " + |
|
61 "VALUES (:name, :source, :target, :startTime, :endTime, :state, " + |
|
62 ":currBytes, :maxBytes, :preferredAction, :autoResume, :guid)"); |
|
63 try { |
|
64 for (let prop in data) |
|
65 stmt.params[prop] = data[prop]; |
|
66 stmt.execute(); |
|
67 } |
|
68 finally { |
|
69 stmt.finalize(); |
|
70 } |
|
71 |
|
72 // Toggle history to get everything to update |
|
73 EventUtils.synthesizeMouse(history, 0, 0, {}, aWin); |
|
74 EventUtils.synthesizeMouse(history, 0, 0, {}, aWin); |
|
75 |
|
76 ok(!history.checked, "history checkbox is not checked"); |
|
77 ok(!downloads.disabled, "downloads checkbox is not disabled"); |
|
78 ok(downloads.checked, "downloads checkbox is checked"); |
|
79 } |
|
80 |
|
81 function test_checkedAndDisabledWithHistoryChecked(aWin) |
|
82 { |
|
83 let doc = aWin.document; |
|
84 let downloads = doc.getElementById("downloads-checkbox"); |
|
85 let history = doc.getElementById("history-checkbox"); |
|
86 |
|
87 EventUtils.synthesizeMouse(history, 0, 0, {}, aWin); |
|
88 ok(history.checked, "history checkbox is checked"); |
|
89 ok(downloads.disabled, "downloads checkbox is disabled"); |
|
90 ok(downloads.checked, "downloads checkbox is checked"); |
|
91 } |
|
92 |
|
93 let tests = [ |
|
94 test_checkedAndDisabledAtStart, |
|
95 test_checkedAndDisabledOnHistoryToggle, |
|
96 test_checkedAfterAddingDownload, |
|
97 test_checkedAndDisabledWithHistoryChecked, |
|
98 ]; |
|
99 |
|
100 ////////////////////////////////////////////////////////////////////////////// |
|
101 //// Run the tests |
|
102 |
|
103 let dm = Cc["@mozilla.org/download-manager;1"]. |
|
104 getService(Ci.nsIDownloadManager); |
|
105 let db = dm.DBConnection; |
|
106 |
|
107 // Empty any old downloads |
|
108 db.executeSimpleSQL("DELETE FROM moz_downloads"); |
|
109 |
|
110 // Close the UI if necessary |
|
111 let win = Services.ww.getWindowByName("Sanitize", null); |
|
112 if (win && (win instanceof Ci.nsIDOMWindow)) |
|
113 win.close(); |
|
114 |
|
115 // Start the test when the sanitize window loads |
|
116 Services.ww.registerNotification(function (aSubject, aTopic, aData) { |
|
117 Services.ww.unregisterNotification(arguments.callee); |
|
118 aSubject.QueryInterface(Ci.nsIDOMEventTarget) |
|
119 .addEventListener("DOMContentLoaded", doTest, false); |
|
120 }); |
|
121 |
|
122 // Let the methods that run onload finish before we test |
|
123 let doTest = function() setTimeout(function() { |
|
124 let win = Services.ww.getWindowByName("Sanitize", null) |
|
125 .QueryInterface(Ci.nsIDOMWindow); |
|
126 |
|
127 for (let i = 0; i < tests.length; i++) |
|
128 tests[i](win); |
|
129 |
|
130 win.close(); |
|
131 finish(); |
|
132 }, 0); |
|
133 |
|
134 // Show the UI |
|
135 Services.ww.openWindow(window, |
|
136 "chrome://browser/content/sanitize.xul", |
|
137 "Sanitize", |
|
138 "chrome,titlebar,centerscreen", |
|
139 null); |
|
140 |
|
141 waitForExplicitFinish(); |
|
142 } |