mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 23:31:56 +00:00
Bug 839778 - Use OS.File in about:crashes. r=adw
This commit is contained in:
parent
ced63f557e
commit
b8e40d8501
@ -2,14 +2,18 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
const Cc = Components.classes;
|
const { classes: Cc, utils: Cu, interfaces: Ci } = Components;
|
||||||
const Ci = Components.interfaces;
|
|
||||||
|
|
||||||
var reportURL;
|
var reportURL;
|
||||||
|
|
||||||
Components.utils.import("resource://gre/modules/CrashReports.jsm");
|
Cu.import("resource://gre/modules/CrashReports.jsm");
|
||||||
Components.utils.import("resource://gre/modules/CrashSubmit.jsm");
|
Cu.import("resource://gre/modules/Services.jsm");
|
||||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
Cu.import("resource://gre/modules/Task.jsm");
|
||||||
|
Cu.import("resource://gre/modules/osfile.jsm");
|
||||||
|
|
||||||
|
XPCOMUtils.defineLazyModuleGetter(this, "CrashSubmit",
|
||||||
|
"resource://gre/modules/CrashSubmit.jsm");
|
||||||
|
|
||||||
const buildID = Services.appinfo.appBuildID;
|
const buildID = Services.appinfo.appBuildID;
|
||||||
|
|
||||||
@ -127,46 +131,53 @@ function populateReportList() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearReports() {
|
let clearReports = Task.async(function*() {
|
||||||
var bundles = Cc["@mozilla.org/intl/stringbundle;1"].
|
let bundle = Services.strings.createBundle("chrome://global/locale/crashes.properties");
|
||||||
getService(Ci.nsIStringBundleService);
|
|
||||||
var bundle = bundles.createBundle("chrome://global/locale/crashes.properties");
|
|
||||||
var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
||||||
getService(Ci.nsIPromptService);
|
|
||||||
if (!prompts.confirm(window,
|
|
||||||
bundle.GetStringFromName("deleteconfirm.title"),
|
|
||||||
bundle.GetStringFromName("deleteconfirm.description")))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var entries = CrashReports.submittedDir.directoryEntries;
|
if (!Services.
|
||||||
while (entries.hasMoreElements()) {
|
prompt.confirm(window,
|
||||||
var file = entries.getNext().QueryInterface(Ci.nsIFile);
|
bundle.GetStringFromName("deleteconfirm.title"),
|
||||||
var leaf = file.leafName;
|
bundle.GetStringFromName("deleteconfirm.description"))) {
|
||||||
if (leaf.substr(0, 3) == "bp-" &&
|
return;
|
||||||
leaf.substr(-4) == ".txt") {
|
}
|
||||||
file.remove(false);
|
|
||||||
|
let cleanupFolder = Task.async(function*(path, filter) {
|
||||||
|
let iterator = new OS.File.DirectoryIterator(path);
|
||||||
|
try {
|
||||||
|
yield iterator.forEach(Task.async(function*(aEntry) {
|
||||||
|
if (!filter || (yield filter(aEntry))) {
|
||||||
|
yield OS.File.remove(aEntry.path);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
} catch (e if e instanceof OS.File.Error && e.becauseNoSuchFile) {
|
||||||
|
} finally {
|
||||||
|
iterator.close();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
entries = CrashReports.reportsDir.directoryEntries;
|
|
||||||
var oneYearAgo = Date.now() - 31586000000;
|
yield cleanupFolder(CrashReports.submittedDir.path, function*(aEntry) {
|
||||||
while (entries.hasMoreElements()) {
|
return aEntry.name.startsWith("bp-") && aEntry.name.endsWith(".txt");
|
||||||
var file = entries.getNext().QueryInterface(Ci.nsIFile);
|
});
|
||||||
var leaf = file.leafName;
|
|
||||||
if (leaf.substr(0, 11) == "InstallTime" &&
|
let oneYearAgo = Date.now() - 31586000000;
|
||||||
file.lastModifiedTime < oneYearAgo &&
|
yield cleanupFolder(CrashReports.reportsDir.path, function*(aEntry) {
|
||||||
leaf != "InstallTime" + buildID) {
|
if (!aEntry.name.startsWith("InstallTime") ||
|
||||||
file.remove(false);
|
aEntry.name == "InstallTime" + buildID) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
entries = CrashReports.pendingDir.directoryEntries;
|
let date = aEntry.winLastWriteDate;
|
||||||
while (entries.hasMoreElements()) {
|
if (!date) {
|
||||||
entries.getNext().QueryInterface(Ci.nsIFile).remove(false);
|
let stat = yield OS.File.stat(aEntry.path);
|
||||||
}
|
date = stat.lastModificationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (date < oneYearAgo);
|
||||||
|
});
|
||||||
|
|
||||||
|
yield cleanupFolder(CrashReports.pendingDir.path);
|
||||||
|
|
||||||
document.getElementById("clear-reports").style.display = "none";
|
document.getElementById("clear-reports").style.display = "none";
|
||||||
document.getElementById("reportList").style.display = "none";
|
document.getElementById("reportList").style.display = "none";
|
||||||
document.getElementById("noReports").style.display = "block";
|
document.getElementById("noReports").style.display = "block";
|
||||||
}
|
});
|
||||||
|
|
||||||
function init() {
|
|
||||||
populateReportList();
|
|
||||||
}
|
|
||||||
|
@ -66,9 +66,9 @@ td:last-child {
|
|||||||
<script type="application/javascript;version=1.8" src="chrome://global/content/crashes.js"/>
|
<script type="application/javascript;version=1.8" src="chrome://global/content/crashes.js"/>
|
||||||
|
|
||||||
<title>&crashes.title;</title>
|
<title>&crashes.title;</title>
|
||||||
</head><body onload="init()" dir="&locale.dir;">
|
</head><body onload="populateReportList()" dir="&locale.dir;">
|
||||||
<button chromedir="&locale.dir;" id="clear-reports"
|
<button chromedir="&locale.dir;" id="clear-reports"
|
||||||
onclick="clearReports()">&clearAllReports.label;</button>
|
onclick="clearReports().then(null, Cu.reportError)">&clearAllReports.label;</button>
|
||||||
<h1>&crashes.title;</h1>
|
<h1>&crashes.title;</h1>
|
||||||
<div id="reportList">
|
<div id="reportList">
|
||||||
<table>
|
<table>
|
||||||
|
@ -8,3 +8,4 @@ skip-if = e10s # Bug 929045 - [tracking] e10s support for Crash Reporting
|
|||||||
[browser_aboutCrashes.js]
|
[browser_aboutCrashes.js]
|
||||||
[browser_aboutCrashesResubmit.js]
|
[browser_aboutCrashesResubmit.js]
|
||||||
[browser_bug471404.js]
|
[browser_bug471404.js]
|
||||||
|
[browser_clearReports.js]
|
||||||
|
136
toolkit/crashreporter/test/browser/browser_clearReports.js
Normal file
136
toolkit/crashreporter/test/browser/browser_clearReports.js
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
function clickClearReports(tab, cb) {
|
||||||
|
let doc = gBrowser.getBrowserForTab(tab).contentDocument;
|
||||||
|
|
||||||
|
let button = doc.getElementById("clear-reports");
|
||||||
|
|
||||||
|
if (!button) {
|
||||||
|
ok(false, "Button not found");
|
||||||
|
cb();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let style = doc.defaultView.getComputedStyle(button, "");
|
||||||
|
|
||||||
|
isnot(style.display, "none", "Clear reports button visible");
|
||||||
|
|
||||||
|
var observer = new MutationObserver(function(mutations) {
|
||||||
|
for (let mutation of mutations) {
|
||||||
|
if (mutation.type == "attributes" &&
|
||||||
|
mutation.attributeName == "style") {
|
||||||
|
observer.disconnect();
|
||||||
|
is(style.display, "none", "Clear reports button hidden");
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
observer.observe(button, {
|
||||||
|
attributes: true,
|
||||||
|
childList: true,
|
||||||
|
characterData: true,
|
||||||
|
attributeFilter: ["style"],
|
||||||
|
});
|
||||||
|
|
||||||
|
button.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
var promptShown = false;
|
||||||
|
|
||||||
|
let oldPrompt = Services.prompt;
|
||||||
|
Services.prompt = {
|
||||||
|
confirm: function() {
|
||||||
|
promptShown = true;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
registerCleanupFunction(function () {
|
||||||
|
Services.prompt = oldPrompt;
|
||||||
|
});
|
||||||
|
|
||||||
|
function test() {
|
||||||
|
waitForExplicitFinish();
|
||||||
|
|
||||||
|
let appD = make_fake_appdir();
|
||||||
|
let crD = appD.clone();
|
||||||
|
crD.append("Crash Reports");
|
||||||
|
|
||||||
|
// Add crashes to submitted dir
|
||||||
|
let submitdir = crD.clone();
|
||||||
|
submitdir.append("submitted");
|
||||||
|
|
||||||
|
let file1 = submitdir.clone();
|
||||||
|
file1.append("bp-nontxt");
|
||||||
|
file1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
||||||
|
let file2 = submitdir.clone();
|
||||||
|
file2.append("nonbp-file.txt");
|
||||||
|
file2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
||||||
|
add_fake_crashes(crD, 5);
|
||||||
|
|
||||||
|
// Add crashes to pending dir
|
||||||
|
let pendingdir = crD.clone();
|
||||||
|
pendingdir.append("pending");
|
||||||
|
|
||||||
|
let crashes = add_fake_crashes(crD, 2);
|
||||||
|
addPendingCrashreport(crD, crashes[0].date);
|
||||||
|
addPendingCrashreport(crD, crashes[1].date);
|
||||||
|
|
||||||
|
// Add crashes to reports dir
|
||||||
|
let report1 = crD.clone();
|
||||||
|
report1.append("NotInstallTime777");
|
||||||
|
report1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
||||||
|
let report2 = crD.clone();
|
||||||
|
report2.append("InstallTime" + Services.appinfo.appBuildID);
|
||||||
|
report2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
||||||
|
let report3 = crD.clone();
|
||||||
|
report3.append("InstallTimeNew");
|
||||||
|
report3.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
||||||
|
let report4 = crD.clone();
|
||||||
|
report4.append("InstallTimeOld");
|
||||||
|
report4.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
|
||||||
|
report4.lastModifiedTime = Date.now() - 63172000000;
|
||||||
|
|
||||||
|
let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
|
||||||
|
|
||||||
|
registerCleanupFunction(function () {
|
||||||
|
cleanup_fake_appdir();
|
||||||
|
gBrowser.removeTab(tab);
|
||||||
|
});
|
||||||
|
|
||||||
|
let browser = gBrowser.getBrowserForTab(tab);
|
||||||
|
|
||||||
|
browser.addEventListener("load", function onLoad() {
|
||||||
|
browser.removeEventListener("load", onLoad, true);
|
||||||
|
|
||||||
|
executeSoon(function() {
|
||||||
|
let dirs = [ submitdir, pendingdir, crD ];
|
||||||
|
let existing = [ file1.path, file2.path, report1.path, report2.path,
|
||||||
|
report3.path, submitdir.path, pendingdir.path ];
|
||||||
|
|
||||||
|
clickClearReports(tab, function() {
|
||||||
|
for (let dir of dirs) {
|
||||||
|
let entries = dir.directoryEntries;
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
let file = entries.getNext().QueryInterface(Ci.nsIFile);
|
||||||
|
let index = existing.indexOf(file.path);
|
||||||
|
isnot(index, -1, file.leafName + " exists");
|
||||||
|
|
||||||
|
if (index != -1) {
|
||||||
|
existing.splice(index, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is(existing.length, 0, "All the files that should still exist exist");
|
||||||
|
ok(promptShown, "Prompt shown");
|
||||||
|
|
||||||
|
finish();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, true);
|
||||||
|
|
||||||
|
browser.loadURI("about:crashes", null, null);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user