michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function clickClearReports(tab, cb) { michael@0: let doc = gBrowser.getBrowserForTab(tab).contentDocument; michael@0: michael@0: let button = doc.getElementById("clear-reports"); michael@0: michael@0: if (!button) { michael@0: ok(false, "Button not found"); michael@0: cb(); michael@0: return; michael@0: } michael@0: michael@0: let style = doc.defaultView.getComputedStyle(button, ""); michael@0: michael@0: isnot(style.display, "none", "Clear reports button visible"); michael@0: michael@0: var observer = new MutationObserver(function(mutations) { michael@0: for (let mutation of mutations) { michael@0: if (mutation.type == "attributes" && michael@0: mutation.attributeName == "style") { michael@0: observer.disconnect(); michael@0: is(style.display, "none", "Clear reports button hidden"); michael@0: cb(); michael@0: } michael@0: } michael@0: }); michael@0: observer.observe(button, { michael@0: attributes: true, michael@0: childList: true, michael@0: characterData: true, michael@0: attributeFilter: ["style"], michael@0: }); michael@0: michael@0: button.click(); michael@0: } michael@0: michael@0: var promptShown = false; michael@0: michael@0: let oldPrompt = Services.prompt; michael@0: Services.prompt = { michael@0: confirm: function() { michael@0: promptShown = true; michael@0: return true; michael@0: }, michael@0: }; michael@0: michael@0: registerCleanupFunction(function () { michael@0: Services.prompt = oldPrompt; michael@0: }); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let appD = make_fake_appdir(); michael@0: let crD = appD.clone(); michael@0: crD.append("Crash Reports"); michael@0: michael@0: // Add crashes to submitted dir michael@0: let submitdir = crD.clone(); michael@0: submitdir.append("submitted"); michael@0: michael@0: let file1 = submitdir.clone(); michael@0: file1.append("bp-nontxt"); michael@0: file1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); michael@0: let file2 = submitdir.clone(); michael@0: file2.append("nonbp-file.txt"); michael@0: file2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); michael@0: add_fake_crashes(crD, 5); michael@0: michael@0: // Add crashes to pending dir michael@0: let pendingdir = crD.clone(); michael@0: pendingdir.append("pending"); michael@0: michael@0: let crashes = add_fake_crashes(crD, 2); michael@0: addPendingCrashreport(crD, crashes[0].date); michael@0: addPendingCrashreport(crD, crashes[1].date); michael@0: michael@0: // Add crashes to reports dir michael@0: let report1 = crD.clone(); michael@0: report1.append("NotInstallTime777"); michael@0: report1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); michael@0: let report2 = crD.clone(); michael@0: report2.append("InstallTime" + Services.appinfo.appBuildID); michael@0: report2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); michael@0: let report3 = crD.clone(); michael@0: report3.append("InstallTimeNew"); michael@0: report3.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); michael@0: let report4 = crD.clone(); michael@0: report4.append("InstallTimeOld"); michael@0: report4.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666); michael@0: report4.lastModifiedTime = Date.now() - 63172000000; michael@0: michael@0: let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank"); michael@0: michael@0: registerCleanupFunction(function () { michael@0: cleanup_fake_appdir(); michael@0: gBrowser.removeTab(tab); michael@0: }); michael@0: michael@0: let browser = gBrowser.getBrowserForTab(tab); michael@0: michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: michael@0: executeSoon(function() { michael@0: let dirs = [ submitdir, pendingdir, crD ]; michael@0: let existing = [ file1.path, file2.path, report1.path, report2.path, michael@0: report3.path, submitdir.path, pendingdir.path ]; michael@0: michael@0: clickClearReports(tab, function() { michael@0: for (let dir of dirs) { michael@0: let entries = dir.directoryEntries; michael@0: while (entries.hasMoreElements()) { michael@0: let file = entries.getNext().QueryInterface(Ci.nsIFile); michael@0: let index = existing.indexOf(file.path); michael@0: isnot(index, -1, file.leafName + " exists"); michael@0: michael@0: if (index != -1) { michael@0: existing.splice(index, 1); michael@0: } michael@0: } michael@0: } michael@0: michael@0: is(existing.length, 0, "All the files that should still exist exist"); michael@0: ok(promptShown, "Prompt shown"); michael@0: michael@0: finish(); michael@0: }); michael@0: }); michael@0: }, true); michael@0: michael@0: browser.loadURI("about:crashes", null, null); michael@0: }