toolkit/crashreporter/test/browser/browser_clearReports.js

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

mercurial