toolkit/crashreporter/test/browser/browser_clearReports.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/test/browser/browser_clearReports.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,136 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 +* License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 +* You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function clickClearReports(tab, cb) {
     1.9 +  let doc = gBrowser.getBrowserForTab(tab).contentDocument;
    1.10 +
    1.11 +  let button = doc.getElementById("clear-reports");
    1.12 +
    1.13 +  if (!button) {
    1.14 +    ok(false, "Button not found");
    1.15 +    cb();
    1.16 +    return;
    1.17 +  }
    1.18 +
    1.19 +  let style = doc.defaultView.getComputedStyle(button, "");
    1.20 +
    1.21 +  isnot(style.display, "none", "Clear reports button visible");
    1.22 +
    1.23 +  var observer = new MutationObserver(function(mutations) {
    1.24 +    for (let mutation of mutations) {
    1.25 +      if (mutation.type == "attributes" &&
    1.26 +          mutation.attributeName == "style") {
    1.27 +        observer.disconnect();
    1.28 +        is(style.display, "none", "Clear reports button hidden");
    1.29 +        cb();
    1.30 +      }
    1.31 +    }
    1.32 +  });
    1.33 +  observer.observe(button, {
    1.34 +      attributes: true,
    1.35 +      childList: true,
    1.36 +      characterData: true,
    1.37 +      attributeFilter: ["style"],
    1.38 +  });
    1.39 +
    1.40 +  button.click();
    1.41 +}
    1.42 +
    1.43 +var promptShown = false;
    1.44 +
    1.45 +let oldPrompt = Services.prompt;
    1.46 +Services.prompt = {
    1.47 +  confirm: function() {
    1.48 +    promptShown = true;
    1.49 +    return true;
    1.50 +  },
    1.51 +};
    1.52 +
    1.53 +registerCleanupFunction(function () {
    1.54 +  Services.prompt = oldPrompt;
    1.55 +});
    1.56 +
    1.57 +function test() {
    1.58 +  waitForExplicitFinish();
    1.59 +
    1.60 +  let appD = make_fake_appdir();
    1.61 +  let crD = appD.clone();
    1.62 +  crD.append("Crash Reports");
    1.63 +
    1.64 +  // Add crashes to submitted dir
    1.65 +  let submitdir = crD.clone();
    1.66 +  submitdir.append("submitted");
    1.67 +
    1.68 +  let file1 = submitdir.clone();
    1.69 +  file1.append("bp-nontxt");
    1.70 +  file1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    1.71 +  let file2 = submitdir.clone();
    1.72 +  file2.append("nonbp-file.txt");
    1.73 +  file2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    1.74 +  add_fake_crashes(crD, 5);
    1.75 +
    1.76 +  // Add crashes to pending dir
    1.77 +  let pendingdir = crD.clone();
    1.78 +  pendingdir.append("pending");
    1.79 +
    1.80 +  let crashes = add_fake_crashes(crD, 2);
    1.81 +  addPendingCrashreport(crD, crashes[0].date);
    1.82 +  addPendingCrashreport(crD, crashes[1].date);
    1.83 +
    1.84 +  // Add crashes to reports dir
    1.85 +  let report1 = crD.clone();
    1.86 +  report1.append("NotInstallTime777");
    1.87 +  report1.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    1.88 +  let report2 = crD.clone();
    1.89 +  report2.append("InstallTime" + Services.appinfo.appBuildID);
    1.90 +  report2.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    1.91 +  let report3 = crD.clone();
    1.92 +  report3.append("InstallTimeNew");
    1.93 +  report3.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    1.94 +  let report4 = crD.clone();
    1.95 +  report4.append("InstallTimeOld");
    1.96 +  report4.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0666);
    1.97 +  report4.lastModifiedTime = Date.now() - 63172000000;
    1.98 +
    1.99 +  let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
   1.100 +
   1.101 +  registerCleanupFunction(function () {
   1.102 +    cleanup_fake_appdir();
   1.103 +    gBrowser.removeTab(tab);
   1.104 +  });
   1.105 +
   1.106 +  let browser = gBrowser.getBrowserForTab(tab);
   1.107 +
   1.108 +  browser.addEventListener("load", function onLoad() {
   1.109 +    browser.removeEventListener("load", onLoad, true);
   1.110 +
   1.111 +    executeSoon(function() {
   1.112 +      let dirs = [ submitdir, pendingdir, crD ];
   1.113 +      let existing = [ file1.path, file2.path, report1.path, report2.path,
   1.114 +                       report3.path, submitdir.path, pendingdir.path ];
   1.115 +
   1.116 +      clickClearReports(tab, function() {
   1.117 +        for (let dir of dirs) {
   1.118 +          let entries = dir.directoryEntries;
   1.119 +          while (entries.hasMoreElements()) {
   1.120 +            let file = entries.getNext().QueryInterface(Ci.nsIFile);
   1.121 +            let index = existing.indexOf(file.path);
   1.122 +            isnot(index, -1, file.leafName + " exists");
   1.123 +
   1.124 +            if (index != -1) {
   1.125 +              existing.splice(index, 1);
   1.126 +            }
   1.127 +          }
   1.128 +        }
   1.129 +
   1.130 +        is(existing.length, 0, "All the files that should still exist exist");
   1.131 +        ok(promptShown, "Prompt shown");
   1.132 +
   1.133 +        finish();
   1.134 +      });
   1.135 +    });
   1.136 +  }, true);
   1.137 +
   1.138 +  browser.loadURI("about:crashes", null, null);
   1.139 +}

mercurial