bug 471404 - 'Remove All Reports' shouldn't be available if there aren't any reports. add a browser chrome test. r=dao
authorTed Mielczarek <ted.mielczarek@gmail.com>
Tue, 09 Jun 2009 08:56:38 -0400
changeset 29006 f3bf987761096a9823ff291144942f9d329944ce
parent 29005 9373d3073796951f79a6c9cc87fd93ebb5ad142b
child 29007 26d9acfe00928a51908f8326f100c3a40fac5d67
push id7367
push usertmielczarek@mozilla.com
push dateTue, 09 Jun 2009 12:58:54 +0000
treeherderautoland@f3bf98776109 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs471404
milestone1.9.2a1pre
bug 471404 - 'Remove All Reports' shouldn't be available if there aren't any reports. add a browser chrome test. r=dao
toolkit/crashreporter/test/Makefile.in
toolkit/crashreporter/test/browser/browser_bug471404.js
--- a/toolkit/crashreporter/test/Makefile.in
+++ b/toolkit/crashreporter/test/Makefile.in
@@ -114,13 +114,14 @@ ifndef MOZ_ENABLE_LIBXUL
 # therefore it is disabled. See Bug 474688.
 #check:: $(PROGRAM)
 #	$(RUN_TEST_PROGRAM) $(DIST)/bin/TestCrashReporterAPI
 endif
 
 _BROWSER_FILES = \
   browser/aboutcrashes_utils.js \
   browser/browser_aboutCrashes.js \
+  browser/browser_bug471404.js \
   $(NULL)
 
 
 libs::  $(_BROWSER_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)/browser
new file mode 100644
--- /dev/null
+++ b/toolkit/crashreporter/test/browser/browser_bug471404.js
@@ -0,0 +1,68 @@
+// load our utility script
+var scriptLoader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
+                             .getService(Components.interfaces.mozIJSSubScriptLoader);
+scriptLoader.loadSubScript("chrome://mochikit/content/browser/toolkit/crashreporter/test/browser/aboutcrashes_utils.js", this);
+
+function check_clear_visible(tab, aVisible) {
+  let doc = gBrowser.getBrowserForTab(tab).contentDocument;
+  let visible = false;
+  let button = doc.getElementById("clear-reports");
+  if (button) {
+    let style = doc.defaultView.getComputedStyle(button, "");
+    if (style.display != "none" &&
+        style.visibility == "visible")
+      visible = true;
+  }
+  is(visible, aVisible,
+     "clear reports button is " + (aVisible ? "visible" : "hidden"));
+}
+
+// each test here has a setup (run before loading about:crashes) and onload (run after about:crashes loads)
+let _tests = [{setup: null, onload: function(tab) { check_clear_visible(tab, false); }},
+              {setup: function(crD) { add_fake_crashes(crD, 1); },
+               onload: function(tab) { check_clear_visible(tab, true); }}
+              ];
+let _current_test = 0;
+
+function run_test_setup(crD) {
+  if (_tests[_current_test].setup) {
+    _tests[_current_test].setup(crD);
+  }
+}
+
+function run_test_onload(tab) {
+  if (_tests[_current_test].onload) {
+    _tests[_current_test].onload(tab);
+  }
+  _current_test++;
+
+  if (_current_test == _tests.length) {
+    cleanup_fake_appdir();
+    gBrowser.removeTab(tab);
+    finish();
+    return false;
+  }
+  return true;
+}
+
+function test() {
+  waitForExplicitFinish();
+  let appD = make_fake_appdir();
+  let crD = appD.clone();
+  crD.append("Crash Reports");
+
+  let tab = gBrowser.selectedTab = gBrowser.addTab("about:blank");
+  let browser = gBrowser.getBrowserForTab(tab);
+  browser.addEventListener("load", function() {
+      executeSoon(function() {
+          if (run_test_onload(tab)) {
+            // prep and run the next test
+            run_test_setup(crD);
+            executeSoon(function() { browser.loadURI("about:crashes", null, null); });
+          }
+        });
+    }, true);
+  // kick things off
+  run_test_setup(crD);
+  browser.loadURI("about:crashes", null, null);
+}