Bug 750872 - Add yet more GCLI tests, this time for developer toolbar; r=robcee
authorJoe Walker <jwalker@mozilla.com>
Tue, 15 May 2012 11:27:19 +0100
changeset 94178 0f08ab4dfcacd66d7697e4c8ad27a0e1bb01b650
parent 94177 64580a473317f82dbe2fb6350640902932232aff
child 94179 d2e8c2ee67ae39e3839d148b54cdaaa64e44636a
push id9504
push userryanvm@gmail.com
push dateThu, 17 May 2012 00:46:10 +0000
treeherdermozilla-inbound@bd69b36934cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobcee
bugs750872
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 750872 - Add yet more GCLI tests, this time for developer toolbar; r=robcee
browser/devtools/shared/test/browser_toolbar_basic.js
browser/devtools/shared/test/head.js
--- a/browser/devtools/shared/test/browser_toolbar_basic.js
+++ b/browser/devtools/shared/test/browser_toolbar_basic.js
@@ -1,36 +1,124 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Tests that the developer toolbar works properly
 
+let imported = {};
+Components.utils.import("resource:///modules/HUDService.jsm", imported);
+registerCleanupFunction(function() {
+  imported = {};
+});
+
 const URL = "http://example.com/browser/browser/devtools/shared/test/browser_toolbar_basic.html";
 
 function test() {
   addTab(URL, function(browser, tab) {
     info("Starting browser_toolbar_basic.js");
     runTest();
   });
 }
 
 function runTest() {
-  Services.obs.addObserver(checkOpen, DeveloperToolbar.NOTIFICATIONS.SHOW, false);
-  // TODO: reopen the window so the pref has a chance to take effect
-  // EventUtils.synthesizeKey("v", { ctrlKey: true, shiftKey: true });
-  DeveloperToolbarTest.show();
+  ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible in runTest");
+
+  oneTimeObserve(DeveloperToolbar.NOTIFICATIONS.SHOW, catchFail(checkOpen));
+  document.getElementById("Tools:DevToolbar").doCommand();
 }
 
 function checkOpen() {
-  Services.obs.removeObserver(checkOpen, DeveloperToolbar.NOTIFICATIONS.SHOW, false);
-  ok(DeveloperToolbar.visible, "DeveloperToolbar is visible");
+  ok(DeveloperToolbar.visible, "DeveloperToolbar is visible in checkOpen");
+
+  let close = document.getElementById("developer-toolbar-closebutton");
+  let webconsole = document.getElementById("developer-toolbar-webconsole");
+  let inspector = document.getElementById("developer-toolbar-inspector");
+  let debuggr = document.getElementById("developer-toolbar-debugger");
+
+  ok(close, "Close button exists");
+
+  ok(!webconsole.checked, "web console button state 1");
+  ok(!inspector.checked, "inspector button state 1");
+  ok(!debuggr.checked, "debugger button state 1");
+
+  document.getElementById("Tools:WebConsole").doCommand();
+
+  ok(webconsole.checked, "web console button state 2");
+  ok(!inspector.checked, "inspector button state 2");
+  ok(!debuggr.checked, "debugger button state 2");
+
+  document.getElementById("Tools:Inspect").doCommand();
+
+  ok(webconsole.checked, "web console button state 3");
+  ok(inspector.checked, "inspector button state 3");
+  ok(!debuggr.checked, "debugger button state 3");
+
+  // Christmas tree!
 
-  Services.obs.addObserver(checkClosed, DeveloperToolbar.NOTIFICATIONS.HIDE, false);
-  // EventUtils.synthesizeKey("v", { ctrlKey: true, shiftKey: true });
-  DeveloperToolbarTest.hide();
+  // The web console opens synchronously, but closes asynchronously.
+  let hud = imported.HUDService.getHudByWindow(content);
+  imported.HUDService.disableAnimation(hud.hudId);
+
+  document.getElementById("Tools:WebConsole").doCommand();
+
+  ok(!webconsole.checked, "web console button state 6");
+  ok(inspector.checked, "inspector button state 6");
+  ok(!debuggr.checked, "debugger button state 6");
+
+  document.getElementById("Tools:Inspect").doCommand();
+
+  ok(!webconsole.checked, "web console button state 7");
+  ok(!inspector.checked, "inspector button state 7");
+  ok(!debuggr.checked, "debugger button state 7");
+
+  // All closed
+
+  // Check we can open and close and retain button state
+  document.getElementById("Tools:Inspect").doCommand();
+
+  ok(!webconsole.checked, "web console button state 8");
+  ok(inspector.checked, "inspector button state 8");
+  ok(!debuggr.checked, "debugger button state 8");
+
+  oneTimeObserve(DeveloperToolbar.NOTIFICATIONS.HIDE, catchFail(checkClosed));
+  document.getElementById("Tools:DevToolbar").doCommand();
 }
 
 function checkClosed() {
-  Services.obs.removeObserver(checkClosed, DeveloperToolbar.NOTIFICATIONS.HIDE, false);
-  ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible");
+  ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible in checkClosed");
+
+  // Check we grok state even when closed
+  document.getElementById("Tools:WebConsole").doCommand();
+
+  oneTimeObserve(DeveloperToolbar.NOTIFICATIONS.SHOW, catchFail(checkReOpen));
+  document.getElementById("Tools:DevToolbar").doCommand();
+}
+
+function checkReOpen() {
+  ok(DeveloperToolbar.visible, "DeveloperToolbar is visible in checkReOpen");
+
+  let webconsole = document.getElementById("developer-toolbar-webconsole");
+  let inspector = document.getElementById("developer-toolbar-inspector");
+  let debuggr = document.getElementById("developer-toolbar-debugger");
+
+  ok(webconsole.checked, "web console button state 9");
+  ok(inspector.checked, "inspector button state 9");
+  ok(!debuggr.checked, "debugger button state 9");
+
+  oneTimeObserve(DeveloperToolbar.NOTIFICATIONS.HIDE, catchFail(checkReClosed));
+  document.getElementById("developer-toolbar-closebutton").doCommand();
+}
+
+function checkReClosed() {
+  ok(!DeveloperToolbar.visible, "DeveloperToolbar is not visible in checkReClosed");
 
   finish();
 }
+
+//------------------------------------------------------------------------------
+
+function oneTimeObserve(name, callback) {
+  var func = function() {
+    Services.obs.removeObserver(func, name);
+    callback();
+  };
+  Services.obs.addObserver(func, name, false);
+}
--- a/browser/devtools/shared/test/head.js
+++ b/browser/devtools/shared/test/head.js
@@ -305,17 +305,29 @@ let DeveloperToolbarTest = {
 
     addTab(uri, function(browser, tab) {
       DeveloperToolbarTest.show(function() {
 
         try {
           testFunc(browser, tab);
         }
         catch (ex) {
-          ok(false, "" + ex);
+          ok(false, ex);
           console.error(ex);
           finish();
-          throw ex;
         }
       });
     });
   },
 };
+
+function catchFail(func) {
+  return function() {
+    try {
+      return func.apply(null, arguments);
+    }
+    catch (ex) {
+      ok(false, ex);
+      console.error(ex);
+      finish();
+    }
+  };
+}