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 file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | function clickClearReports(tab, cb) { |
michael@0 | 6 | let doc = gBrowser.getBrowserForTab(tab).contentDocument; |
michael@0 | 7 | |
michael@0 | 8 | let button = doc.getElementById("clear-reports"); |
michael@0 | 9 | |
michael@0 | 10 | if (!button) { |
michael@0 | 11 | ok(false, "Button not found"); |
michael@0 | 12 | cb(); |
michael@0 | 13 | return; |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | let style = doc.defaultView.getComputedStyle(button, ""); |
michael@0 | 17 | |
michael@0 | 18 | isnot(style.display, "none", "Clear reports button visible"); |
michael@0 | 19 | |
michael@0 | 20 | var observer = new MutationObserver(function(mutations) { |
michael@0 | 21 | for (let mutation of mutations) { |
michael@0 | 22 | if (mutation.type == "attributes" && |
michael@0 | 23 | mutation.attributeName == "style") { |
michael@0 | 24 | observer.disconnect(); |
michael@0 | 25 | is(style.display, "none", "Clear reports button hidden"); |
michael@0 | 26 | cb(); |
michael@0 | 27 | } |
michael@0 | 28 | } |
michael@0 | 29 | }); |
michael@0 | 30 | observer.observe(button, { |
michael@0 | 31 | attributes: true, |
michael@0 | 32 | childList: true, |
michael@0 | 33 | characterData: true, |
michael@0 | 34 | attributeFilter: ["style"], |
michael@0 | 35 | }); |
michael@0 | 36 | |
michael@0 | 37 | button.click(); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | var promptShown = false; |
michael@0 | 41 | |
michael@0 | 42 | let oldPrompt = Services.prompt; |
michael@0 | 43 | Services.prompt = { |
michael@0 | 44 | confirm: function() { |
michael@0 | 45 | promptShown = true; |
michael@0 | 46 | return true; |
michael@0 | 47 | }, |
michael@0 | 48 | }; |
michael@0 | 49 | |
michael@0 | 50 | registerCleanupFunction(function () { |
michael@0 | 51 | Services.prompt = oldPrompt; |
michael@0 | 52 | }); |
michael@0 | 53 | |
michael@0 | 54 | function test() { |
michael@0 | 55 | waitForExplicitFinish(); |
michael@0 | 56 | |
michael@0 | 57 | let appD = make_fake_appdir(); |
michael@0 | 58 | let crD = appD.clone(); |
michael@0 | 59 | crD.append("Crash Reports"); |
michael@0 | 60 | |
michael@0 | 61 | // Add crashes to submitted dir |
michael@0 | 62 | let submitdir = crD.clone(); |
michael@0 | 63 | submitdir.append("submitted"); |
michael@0 | 64 | |
michael@0 | 65 | let file1 = submitdir.clone(); |
michael@0 | 66 | file1.append("bp-nontxt"); |
michael@0 | 67 | file1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 68 | let file2 = submitdir.clone(); |
michael@0 | 69 | file2.append("nonbp-file.txt"); |
michael@0 | 70 | file2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 71 | add_fake_crashes(crD, 5); |
michael@0 | 72 | |
michael@0 | 73 | // Add crashes to pending dir |
michael@0 | 74 | let pendingdir = crD.clone(); |
michael@0 | 75 | pendingdir.append("pending"); |
michael@0 | 76 | |
michael@0 | 77 | let crashes = add_fake_crashes(crD, 2); |
michael@0 | 78 | addPendingCrashreport(crD, crashes[0].date); |
michael@0 | 79 | addPendingCrashreport(crD, crashes[1].date); |
michael@0 | 80 | |
michael@0 | 81 | // Add crashes to reports dir |
michael@0 | 82 | let report1 = crD.clone(); |
michael@0 | 83 | report1.append("NotInstallTime777"); |
michael@0 | 84 | report1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 85 | let report2 = crD.clone(); |
michael@0 | 86 | report2.append("InstallTime" + Services.appinfo.appBuildID); |
michael@0 | 87 | report2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 88 | let report3 = crD.clone(); |
michael@0 | 89 | report3.append("InstallTimeNew"); |
michael@0 | 90 | report3.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 91 | let report4 = crD.clone(); |
michael@0 | 92 | report4.append("InstallTimeOld"); |
michael@0 | 93 | report4.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); |
michael@0 | 94 | report4.lastModifiedTime = Date.now() - 63172000000; |
michael@0 | 95 | |
michael@0 | 96 | let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); |
michael@0 | 97 | |
michael@0 | 98 | registerCleanupFunction(function () { |
michael@0 | 99 | cleanup_fake_appdir(); |
michael@0 | 100 | gBrowser.removeTab(tab); |
michael@0 | 101 | }); |
michael@0 | 102 | |
michael@0 | 103 | let browser = gBrowser.getBrowserForTab(tab); |
michael@0 | 104 | |
michael@0 | 105 | browser.addEventListener("load", function onLoad() { |
michael@0 | 106 | browser.removeEventListener("load", onLoad, true); |
michael@0 | 107 | |
michael@0 | 108 | executeSoon(function() { |
michael@0 | 109 | let dirs = [ submitdir, pendingdir, crD ]; |
michael@0 | 110 | let existing = [ file1.path, file2.path, report1.path, report2.path, |
michael@0 | 111 | report3.path, submitdir.path, pendingdir.path ]; |
michael@0 | 112 | |
michael@0 | 113 | clickClearReports(tab, function() { |
michael@0 | 114 | for (let dir of dirs) { |
michael@0 | 115 | let entries = dir.directoryEntries; |
michael@0 | 116 | while (entries.hasMoreElements()) { |
michael@0 | 117 | let file = entries.getNext().QueryInterface(Ci.nsIFile); |
michael@0 | 118 | let index = existing.indexOf(file.path); |
michael@0 | 119 | isnot(index, -1, file.leafName + " exists"); |
michael@0 | 120 | |
michael@0 | 121 | if (index != -1) { |
michael@0 | 122 | existing.splice(index, 1); |
michael@0 | 123 | } |
michael@0 | 124 | } |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | is(existing.length, 0, "All the files that should still exist exist"); |
michael@0 | 128 | ok(promptShown, "Prompt shown"); |
michael@0 | 129 | |
michael@0 | 130 | finish(); |
michael@0 | 131 | }); |
michael@0 | 132 | }); |
michael@0 | 133 | }, true); |
michael@0 | 134 | |
michael@0 | 135 | browser.loadURI("about:crashes", null, null); |
michael@0 | 136 | } |