Bug 481777. Don't fire DOMTitleChanged events to content. r+sr=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 06 Mar 2009 13:12:23 -0500
changeset 25813 07d7d6a3bc9c579aeaf01f5e2f234f9078e241fd
parent 25812 5edc7cd0164de5ba279f60f1c8fc41eec39fa3d6
child 25814 c460743a79d72e8badf584aad783542506affe26
push id5756
push userbzbarsky@mozilla.com
push dateFri, 06 Mar 2009 18:13:04 +0000
treeherdermozilla-central@07d7d6a3bc9c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs481777
milestone1.9.2a1pre
Bug 481777. Don't fire DOMTitleChanged events to content. r+sr=smaug
content/base/src/nsDocument.cpp
content/base/test/chrome/Makefile.in
content/base/test/chrome/test_title.xul
content/base/test/chrome/title_window.xul
content/base/test/test_title.html
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -5040,19 +5040,19 @@ nsDocument::DoNotifyPossibleTitleChange(
     nsCOMPtr<nsIBaseWindow> docShellWin = do_QueryInterface(container);
     if (!docShellWin)
       continue;
 
     docShellWin->SetTitle(PromiseFlatString(title).get());
   }
 
   // Fire a DOM event for the title change.
-  nsContentUtils::DispatchTrustedEvent(this, static_cast<nsIDocument*>(this),
-                                       NS_LITERAL_STRING("DOMTitleChanged"),
-                                       PR_TRUE, PR_TRUE);
+  nsContentUtils::DispatchChromeEvent(this, static_cast<nsIDocument*>(this),
+                                      NS_LITERAL_STRING("DOMTitleChanged"),
+                                      PR_TRUE, PR_TRUE);
 }
 
 NS_IMETHODIMP
 nsDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult)
 {
   nsCOMPtr<nsIContent> content(do_QueryInterface(aElement));
   NS_ENSURE_TRUE(content, NS_ERROR_UNEXPECTED);
 
--- a/content/base/test/chrome/Makefile.in
+++ b/content/base/test/chrome/Makefile.in
@@ -47,15 +47,17 @@ include $(topsrcdir)/config/rules.mk
     bug421622-referer.sjs \
     $(NULL)
 
 _CHROME_FILES = \
     test_bug421622.xul \
     test_bug429785.xul \
     test_bug430050.xul \
     test_bug467123.xul \
+    test_title.xul \
+    title_window.xul \
     $(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 
 libs:: $(_CHROME_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/chrome/$(relativesrcdir)
new file mode 100644
--- /dev/null
+++ b/content/base/test/chrome/test_title.xul
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=481777
+-->
+<window title="Mozilla Bug 481777"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"></script>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=481777"
+     target="_blank">Mozilla Bug 481777</a>
+  </body>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+
+  /** Test for Bug 481777 **/
+
+    SimpleTest.waitForExplicitFinish();
+    window.open("title_window.xul", "bug481777",
+                "chrome,width=100,height=100");
+  ]]>
+  </script>
+</window>
new file mode 100644
--- /dev/null
+++ b/content/base/test/chrome/title_window.xul
@@ -0,0 +1,178 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<window title="Mozilla Bug 481777 subwindow"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        onload="runTests()">
+
+  <iframe type="content" id="html1" src="data:text/html,&lt;html&gt;&lt;head&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;"/>
+  <iframe type="content" id="html2" src="data:text/html,&lt;html&gt;&lt;head&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;title&gt;Foo&lt;/title&gt;&lt;/head&gt;&lt;/html&gt;"/>
+  <iframe type="content" id="html3" src="data:text/html,&lt;html&gt;&lt;/html&gt;"/>
+  <iframe type="content" id="xhtml1" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;body&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;/body&gt;&lt;/html&gt;"/>
+  <iframe type="content" id="xhtml2" src="data:text/xml,&lt;title xmlns='http://www.w3.org/1999/xhtml'&gt;Test&lt;/title&gt;"/>
+  <iframe type="content" id="xhtml3" src="data:text/xml,&lt;title xmlns='http://www.w3.org/1999/xhtml'&gt;Te&lt;div&gt;bogus&lt;/div&gt;st&lt;/title&gt;"/>
+  <iframe type="content" id="xhtml4" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'/>"/>
+  <iframe type="content" id="xhtml5" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;head/>&lt;/html&gt;"/>
+  <iframe type="content" id="xhtml6" src="data:text/xml,&lt;html xmlns='http://www.w3.org/1999/xhtml'&gt;&lt;head&gt;&lt;style/>&lt;/head&gt;&lt;/html&gt;"/>
+  <iframe type="content" id="xul1" src="data:application/vnd.mozilla.xul+xml,&lt;window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' title='Test'/>"/>
+  <iframe type="content" id="xul2" src="data:application/vnd.mozilla.xul+xml,&lt;window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul' title='Test'/>"/>
+  <iframe type="content" id="svg1" src="data:text/xml,&lt;svg xmlns='http://www.w3.org/2000/svg'&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;/svg&gt;"/>
+  <iframe type="content" id="svg2" src="data:text/xml,&lt;svg xmlns='http://www.w3.org/2000/svg'&gt;&lt;title id='t'&gt;Test&lt;/title&gt;&lt;/svg&gt;"/>
+
+  <script type="application/javascript">
+    <![CDATA[
+    var imports = [ "SimpleTest", "is", "isnot", "ok" ];
+    for each (var import in imports) {
+      window[import] = window.opener.wrappedJSObject[import];
+    }
+
+    function testStatics() {
+      function testStatic(id, expect, description) {
+        is(document.getElementById(id).contentDocument.title, expect, description);
+      }
+
+      testStatic("html1", "Test", "HTML <title>");
+      testStatic("html2", "Test", "choose the first HTML <title>");
+      testStatic("html3", "", "No title");
+      testStatic("xhtml1", "Test", "XHTML <title> in body");
+      testStatic("xhtml2", "Test", "XHTML <title> as root element");
+      testStatic("xhtml3", "Test", "XHTML <title> containing an element");
+      testStatic("xul1", "Test", "XUL <window> title attribute");
+      testStatic("svg1", "Test", "SVG <title>");
+    }
+
+    function testDynamics() {
+      var inProgress = {};
+      var inProgressDoc = {};
+      var inProgressWin = {};
+      function testDynamic(id, expect, description, op, checkDOM) {
+        inProgress[description] = true;
+        inProgressDoc[description] = true;
+        inProgressWin[description] = true;
+        var frame = document.getElementById(id);
+        var done = false;
+
+        function listener(ev) {
+          inProgress[description] = false;
+          is(frame.contentDocument.title, expect, "'title': " + description);
+          is(frame.contentDocument, ev.target, "Unexpected target: " + description);
+          if (typeof(checkDOM) != "undefined") {
+            checkDOM(frame.contentDocument, "DOM: " + description);
+          }
+        }
+
+        function listener2(ev) {
+          inProgressDoc[description] = false;
+        }
+        function listener3(ev) {
+          inProgressWin[description] = false;
+        }
+        frame.addEventListener("DOMTitleChanged", listener, false);
+        frame.contentDocument.addEventListener("DOMTitleChanged", listener2, false);
+        frame.contentWindow.addEventListener("DOMTitleChanged", listener3, false);
+
+        op(frame.contentDocument);
+      }
+
+      testDynamic("html1", "Hello", "Setting HTML <title> text contents",
+                  function(doc){
+                    var t = doc.getElementById("t"); t.textContent = "Hello";
+                  });
+      testDynamic("html2", "Foo", "Removing HTML <title>",
+                  function(doc){
+                    var t = doc.getElementById("t"); t.parentNode.removeChild(t);
+                  });
+      testDynamic("html3", "Hello", "Appending HTML <title> element to root element",
+                  function(doc){
+                    var t = doc.createElement("title"); t.textContent = "Hello"; doc.documentElement.appendChild(t);
+                  });
+
+      testDynamic("xhtml3", "Hello", "Setting 'title' clears existing <title> contents",
+                  function(doc){
+                    doc.title = "Hello";
+                  },
+                  function(doc, desc) {
+                    is(doc.documentElement.firstChild.data, "Hello", desc);
+                    is(doc.documentElement.firstChild.nextSibling, null, desc);
+                  });
+      // This one does nothing and won't fire an event
+      document.getElementById("xhtml4").contentDocument.title = "Hello";
+      is(document.getElementById("xhtml4").contentDocument.title, "", "Setting 'title' does nothing with no <head>");
+      testDynamic("xhtml5", "Hello", "Setting 'title' works with a <head>",
+                  function(doc){
+                    doc.title = "Hello";
+                  },
+                  function(doc, desc) {
+                    var head = doc.documentElement.firstChild;
+                    var title = head.firstChild;
+                    is(title.tagName.toLowerCase(), "title", desc);
+                    is(title.firstChild.data, "Hello", desc);
+                    is(title.firstChild.nextSibling, null, desc);
+                    is(title.nextSibling, null, desc);
+                  });
+      testDynamic("xhtml6", "Hello", "Setting 'title' appends to <head>",
+                  function(doc){
+                    doc.title = "Hello";
+                  },
+                  function(doc, desc) {
+                    var head = doc.documentElement.firstChild;
+                    is(head.firstChild.tagName.toLowerCase(), "style", desc);
+                    var title = head.firstChild.nextSibling;
+                    is(title.tagName.toLowerCase(), "title", desc);
+                    is(title.firstChild.data, "Hello", desc);
+                    is(title.firstChild.nextSibling, null, desc);
+                    is(title.nextSibling, null, desc);
+                  });
+
+      testDynamic("xul1", "Hello", "Setting XUL <window> title attribute",
+                  function(doc){
+                    doc.documentElement.setAttribute("title", "Hello");
+                  });
+      testDynamic("xul2", "Hello", "Setting 'title' in XUL",
+                  function(doc){
+                    doc.title = "Hello";
+                  },
+                  function(doc, desc) {
+                    is(doc.documentElement.getAttribute("title"), "Hello", desc);
+                    is(doc.documentElement.firstChild, null, desc);
+                  });
+
+      testDynamic("svg1", "Hello", "Setting SVG <title> text contents",
+                  function(doc){
+                    var t = doc.getElementById("t"); t.textContent = "Hello";
+                  });
+      testDynamic("svg2", "", "Removing SVG <title>",
+                  function(doc){
+                    var t = doc.getElementById("t"); t.parentNode.removeChild(t);
+                  });
+
+      function end() {
+        for (description in inProgress) {
+          ok(!inProgress[description],
+             description + ": DOMTitleChange not fired");
+        }
+        for (description in inProgressDoc) {
+          ok(inProgressDoc[description],
+             description + ": DOMTitleChange fired on content document");
+        }
+        for (description in inProgressWin) {
+          ok(inProgressWin[description],
+             description + ": DOMTitleChange fired on content window");
+        }
+
+        // Closing the window will nuke the global properties, since this
+        // function is not really running on this window... or something
+        // like that.  Thanks, executeSoon!
+        var tester = SimpleTest;
+        window.close();
+        tester.finish();
+      }
+      SimpleTest.executeSoon(end);
+    }
+
+    function runTests() {
+      testStatics();
+      testDynamics();
+    }
+    ]]>
+  </script>
+</window>
--- a/content/base/test/test_title.html
+++ b/content/base/test/test_title.html
@@ -28,118 +28,28 @@
   <iframe id="svg1" src="data:text/xml,<svg xmlns='http://www.w3.org/2000/svg'><title id='t'>Test</title></svg>"></iframe>
   <iframe id="svg2" src="data:text/xml,<svg xmlns='http://www.w3.org/2000/svg'><title id='t'>Test</title></svg>"></iframe>
 </div>
 
 <pre id="test">
 <script>
 SimpleTest.waitForExplicitFinish();
 
-function testStatics() {
+function runTests() {
   function testStatic(id, expect, description) {
     is(document.getElementById(id).contentDocument.title, expect, description);
   }
 
   testStatic("html1", "Test", "HTML <title>");
   testStatic("html2", "Test", "choose the first HTML <title>");
   testStatic("html3", "", "No title");
   testStatic("xhtml1", "Test", "XHTML <title> in body");
   testStatic("xhtml2", "Test", "XHTML <title> as root element");
   testStatic("xhtml3", "Test", "XHTML <title> containing an element");
   testStatic("xul1", "Test", "XUL <window> title attribute");
   testStatic("svg1", "Test", "SVG <title>");
+
+  SimpleTest.finish();
 }
-
-function testDynamics() {
-  var inProgress = {};
-  function testDynamic(id, expect, description, op, checkDOM) {
-    inProgress[description] = true;
-    var frame = document.getElementById(id);
-    var done = false;
-
-    function listener() {
-      inProgress[description] = false;
-      is(frame.contentDocument.title, expect, "'title': " + description);
-      if (typeof(checkDOM) != undefined) {
-        checkDOM(frame.contentDocument, "DOM: " + description);
-      }
-    }
-    frame.contentDocument.addEventListener("DOMTitleChanged", listener, false);
-
-    op(frame.contentDocument);
-  }
-
-  testDynamic("html1", "Hello", "Setting HTML <title> text contents", function(doc){
-      var t = doc.getElementById("t"); t.textContent = "Hello";
-    });
-  testDynamic("html2", "Foo", "Removing HTML <title>", function(doc){
-      var t = doc.getElementById("t"); t.parentNode.removeChild(t);
-    });
-  testDynamic("html3", "Hello", "Appending HTML <title> element to root element", function(doc){
-      var t = doc.createElement("title"); t.textContent = "Hello"; doc.documentElement.appendChild(t);
-    });
-
-  testDynamic("xhtml3", "Hello", "Setting 'title' clears existing <title> contents", function(doc){
-      doc.title = "Hello";
-    }, function(doc, desc) {
-      is(doc.documentElement.firstChild.data, "Hello", desc);
-      is(doc.documentElement.firstChild.nextSibling, null, desc);
-    });
-  // This one does nothing and won't fire an event
-  document.getElementById("xhtml4").contentDocument.title = "Hello";
-  is(document.getElementById("xhtml4").contentDocument.title, "", "Setting 'title' does nothing with no <head>");
-  testDynamic("xhtml5", "Hello", "Setting 'title' works with a <head>", function(doc){
-      doc.title = "Hello";
-    }, function(doc, desc) {
-      var head = doc.documentElement.firstChild;
-      var title = head.firstChild;
-      is(title.tagName.toLowerCase(), "title", desc);
-      is(title.firstChild.data, "Hello", desc);
-      is(title.firstChild.nextSibling, null, desc);
-      is(title.nextSibling, null, desc);
-    });
-  testDynamic("xhtml6", "Hello", "Setting 'title' appends to <head>", function(doc){
-      doc.title = "Hello";
-    }, function(doc, desc) {
-      var head = doc.documentElement.firstChild;
-      is(head.firstChild.tagName.toLowerCase(), "style", desc);
-      var title = head.firstChild.nextSibling;
-      is(title.tagName.toLowerCase(), "title", desc);
-      is(title.firstChild.data, "Hello", desc);
-      is(title.firstChild.nextSibling, null, desc);
-      is(title.nextSibling, null, desc);
-    });
-
-  testDynamic("xul1", "Hello", "Setting XUL <window> title attribute", function(doc){
-      doc.documentElement.setAttribute("title", "Hello");
-    });
-  testDynamic("xul2", "Hello", "Setting 'title' in XUL", function(doc){
-      doc.title = "Hello";
-    }, function(doc, desc) {
-      is(doc.documentElement.getAttribute("title"), "Hello", desc);
-      is(doc.documentElement.firstChild, null, desc);
-    });
-
-  testDynamic("svg1", "Hello", "Setting SVG <title> text contents", function(doc){
-      var t = doc.getElementById("t"); t.textContent = "Hello";
-    });
-  testDynamic("svg2", "", "Removing SVG <title>", function(doc){
-      var t = doc.getElementById("t"); t.parentNode.removeChild(t);
-    });
-
-  function end() {
-    for (description in inProgress) {
-      ok(!inProgress[description], description + ": DOMTitleChange not fired");
-    }
-    SimpleTest.finish();
-  }
-  setTimeout(end, 500);
-}
-
-function runTests() {
-  testStatics();
-  testDynamics();
-}
-
 </script>
 </pre>
 </body>
 </html>