Bug 614350 - Web console's console object colliding with content breaks sites; f=rcampbell r=gavin.sharp a=blocking2.0
authorRob Campbell <rcampbell@mozilla.com>
Fri, 10 Dec 2010 09:28:17 -0800
changeset 59075 0b6a14a73d940f6d32efd5f972649da6192611f8
parent 59074 2705b22189f9f633ff52c3b76e86080d898d0930
child 59076 ed44f2f4c7cbe58838f64f0ea7583d7650a1b288
push idunknown
push userunknown
push dateunknown
reviewersgavin.sharp, blocking2.0
bugs614350
milestone2.0b8pre
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 614350 - Web console's console object colliding with content breaks sites; f=rcampbell r=gavin.sharp a=blocking2.0
dom/base/ConsoleAPI.js
dom/tests/browser/browser_ConsoleAPITests.js
dom/tests/browser/test-console-api.html
toolkit/components/console/hudservice/tests/browser/Makefile.in
toolkit/components/console/hudservice/tests/browser/browser_webconsole_console_extras.js
toolkit/components/console/hudservice/tests/browser/test-console-extras.html
--- a/dom/base/ConsoleAPI.js
+++ b/dom/base/ConsoleAPI.js
@@ -14,16 +14,18 @@
  * The Original Code is Console API code.
  *
  * The Initial Developer of the Original Code is Mozilla Foundation
  * Portions created by the Initial Developer are Copyright (C) 2010
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *  David Dahl <ddahl@mozilla.com>  (Original Author)
+ *  Ryan Flint <rflint@mozilla.com>
+ *  Rob Campbell <rcampbell@mozilla.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
@@ -68,17 +70,20 @@ ConsoleAPI.prototype = {
       info: function CA_info() {
         self.notifyObservers(id, "info", arguments);
       },
       warn: function CA_warn() {
         self.notifyObservers(id, "warn", arguments);
       },
       error: function CA_error() {
         self.notifyObservers(id, "error", arguments);
-      }
+      },
+      // many flavors of console objects exist on the web, so calling
+      // unimplemented methods shouldn't be fatal. See bug 614350
+      __noSuchMethod__: function CA_nsm() {}
     };
   },
 
   /**
    * Notify all observers of any console API call
    **/
   notifyObservers: function CA_notifyObservers(aID, aLevel, aArguments) {
     if (!aID)
--- a/dom/tests/browser/browser_ConsoleAPITests.js
+++ b/dom/tests/browser/browser_ConsoleAPITests.js
@@ -15,16 +15,17 @@
  * The Original Code is DevTools test code.
  *
  * The Initial Developer of the Original Code is Mozilla Foundation.
  * Portions created by the Initial Developer are Copyright (C) 2010
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *  David Dahl <ddahl@mozilla.com>
+ *  Rob Campbell <rcampbell@mozilla.com>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either the GNU General Public License Version 2 or later (the "GPL"), or
  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
--- a/dom/tests/browser/test-console-api.html
+++ b/dom/tests/browser/test-console-api.html
@@ -1,14 +1,15 @@
 <!DOCTYPE HTML>
 <html dir="ltr" xml:lang="en-US" lang="en-US"><head>
     <title>Console API test page</title>
     <script type="text/javascript">
       function test() {
         var str = "Test Message."
+        console.foobar(str); // if this throws, we don't execute following funcs
         console.log(str);
         console.info(str);
         console.warn(str);
         console.error(str);
       }
     </script>
   </head>
   <body>
--- a/toolkit/components/console/hudservice/tests/browser/Makefile.in
+++ b/toolkit/components/console/hudservice/tests/browser/Makefile.in
@@ -104,16 +104,17 @@ include $(topsrcdir)/config/rules.mk
 	browser_webconsole_bug_593003_iframe_wrong_hud.js \
 	browser_webconsole_bug_601909_remember_height.js \
 	browser_webconsole_bug_613013_console_api_iframe.js \
 	browser_webconsole_bug_597756_reopen_closed_tab.js \
 	browser_webconsole_bug_600183_charset.js \
 	browser_webconsole_bug_601177_log_levels.js \
 	browser_webconsole_bug_587615_lastTimestamp.js \
 	browser_webconsole_bug_597460_filter_scroll.js \
+	browser_webconsole_console_extras.js \
 	head.js \
 	$(NULL)
 
 _BROWSER_TEST_PAGES = \
 	test-console.html \
 	test-network.html \
 	test-network-request.html \
 	test-mutation.html \
@@ -142,15 +143,16 @@ include $(topsrcdir)/config/rules.mk
 	test-bug-597136-external-script-errors.html \
 	test-bug-597136-external-script-errors.js \
 	test-bug-613013-console-api-iframe.html \
 	test-bug-597756-reopen-closed-tab.html \
 	test-bug-600183-charset.html \
 	test-bug-600183-charset.html^headers^ \
 	test-bug-601177-log-levels.html \
 	test-bug-601177-log-levels.js \
+	test-console-extras.html \
 	$(NULL)
 
 libs:: $(_BROWSER_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
 
 libs:: $(_BROWSER_TEST_PAGES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/toolkit/components/console/hudservice/tests/browser/browser_webconsole_console_extras.js
@@ -0,0 +1,68 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is DevTools test code.
+ *
+ * The Initial Developer of the Original Code is Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Rob Campbell <rcampbell@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+// Tests that the basic console.log()-style APIs and filtering work.
+
+const TEST_URI = "http://example.com/browser/toolkit/components/console/hudservice/tests/browser/test-console-extras.html";
+
+function test() {
+  addTab(TEST_URI);
+  browser.addEventListener("DOMContentLoaded", onLoad, false);
+}
+
+function onLoad() {
+  browser.removeEventListener("DOMContentLoaded", onLoad, false);
+  let doc = content.document;
+  openConsole();
+  let button = doc.querySelector("button");
+  ok(button, "we have the button");
+  EventUtils.sendMouseEvent({ type: "click" }, button, content);
+  executeSoon(testButtonClicked);
+}
+
+function testButtonClicked()
+{
+  let hudId = HUDService.displaysIndex()[0];
+  let console = browser.contentWindow.wrappedJSObject.console;
+  let hudBox = HUDService.getHeadsUpDisplay(hudId);
+  let outputNode = hudBox.querySelector(".hud-output-node");
+  let nodes = outputNode.querySelectorAll(".hud-msg-node");
+  is(nodes.length, 2, "two nodes");
+  ok(/start/.test(nodes[0].textContent), "start found");
+  ok(/end/.test(nodes[1].textContent), "end found - complete!");
+  finishTest();
+}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/console/hudservice/tests/browser/test-console-extras.html
@@ -0,0 +1,31 @@
+<!DOCTYPE HTML>
+<html dir="ltr" xml:lang="en-US" lang="en-US"><head>
+    <title>Console extended API test</title>
+    <script type="text/javascript">
+      function test() {
+        console.log("start");
+        console.time();
+        console.timeEnd()
+        console.exception()
+        console.assert()
+        console.clear()
+        console.dir()
+        console.dirxml()
+        console.trace()
+        console.group()
+        console.groupCollapsed()
+        console.groupEnd()
+        console.profile()
+        console.profileEnd()
+        console.count()
+        console.table()
+        console.log("end");
+      }
+    </script>
+  </head>
+  <body>
+    <h1 id="header">Heads Up Display Demo</h1>
+    <button onclick="test();">Test Extended API</button>
+    <div id="myDiv"></div>
+  </body>
+</html>