toolkit/crashreporter/test/browser/browser_clearReports.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     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/. */
     5 function clickClearReports(tab, cb) {
     6   let doc = gBrowser.getBrowserForTab(tab).contentDocument;
     8   let button = doc.getElementById("clear-reports");
    10   if (!button) {
    11     ok(false, "Button not found");
    12     cb();
    13     return;
    14   }
    16   let style = doc.defaultView.getComputedStyle(button, "");
    18   isnot(style.display, "none", "Clear reports button visible");
    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   });
    37   button.click();
    38 }
    40 var promptShown = false;
    42 let oldPrompt = Services.prompt;
    43 Services.prompt = {
    44   confirm: function() {
    45     promptShown = true;
    46     return true;
    47   },
    48 };
    50 registerCleanupFunction(function () {
    51   Services.prompt = oldPrompt;
    52 });
    54 function test() {
    55   waitForExplicitFinish();
    57   let appD = make_fake_appdir();
    58   let crD = appD.clone();
    59   crD.append("Crash Reports");
    61   // Add crashes to submitted dir
    62   let submitdir = crD.clone();
    63   submitdir.append("submitted");
    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);
    73   // Add crashes to pending dir
    74   let pendingdir = crD.clone();
    75   pendingdir.append("pending");
    77   let crashes = add_fake_crashes(crD, 2);
    78   addPendingCrashreport(crD, crashes[0].date);
    79   addPendingCrashreport(crD, crashes[1].date);
    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;
    96   let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
    98   registerCleanupFunction(function () {
    99     cleanup_fake_appdir();
   100     gBrowser.removeTab(tab);
   101   });
   103   let browser = gBrowser.getBrowserForTab(tab);
   105   browser.addEventListener("load", function onLoad() {
   106     browser.removeEventListener("load", onLoad, true);
   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 ];
   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");
   121             if (index != -1) {
   122               existing.splice(index, 1);
   123             }
   124           }
   125         }
   127         is(existing.length, 0, "All the files that should still exist exist");
   128         ok(promptShown, "Prompt shown");
   130         finish();
   131       });
   132     });
   133   }, true);
   135   browser.loadURI("about:crashes", null, null);
   136 }

mercurial