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