From 5d1cec2db6c34a2e36863f0cfa086ce1da03981f Mon Sep 17 00:00:00 2001
From: Dave Townsend
Date: Tue, 3 Mar 2015 14:07:08 -0800
Subject: [PATCH] Bug 1139099: Dispatch DOMDocElementInserted to match the
document-element-inserted observer notification. r=mrbkap
---
dom/base/nsContentSink.cpp | 4 ++++
dom/html/test/browser.ini | 1 +
.../test/browser_DOMDocElementInserted.js | 24 +++++++++++++++++++
.../test_DOMWindowCreated_chromeonly.html | 1 +
4 files changed, 30 insertions(+)
create mode 100644 dom/html/test/browser_DOMDocElementInserted.js
diff --git a/dom/base/nsContentSink.cpp b/dom/base/nsContentSink.cpp
index 222e77e93bd..f9f034f246b 100644
--- a/dom/base/nsContentSink.cpp
+++ b/dom/base/nsContentSink.cpp
@@ -1550,4 +1550,8 @@ nsContentSink::NotifyDocElementCreated(nsIDocument* aDoc)
NotifyObservers(domDoc, "document-element-inserted",
EmptyString().get());
}
+
+ nsContentUtils::DispatchChromeEvent(aDoc, aDoc,
+ NS_LITERAL_STRING("DOMDocElementInserted"),
+ true, false);
}
diff --git a/dom/html/test/browser.ini b/dom/html/test/browser.ini
index a27acfac297..7755e4be588 100644
--- a/dom/html/test/browser.ini
+++ b/dom/html/test/browser.ini
@@ -13,3 +13,4 @@ support-files =
file_bug1108547-1.html
file_bug1108547-2.html
file_bug1108547-3.html
+[browser_DOMDocElementInserted.js]
diff --git a/dom/html/test/browser_DOMDocElementInserted.js b/dom/html/test/browser_DOMDocElementInserted.js
new file mode 100644
index 00000000000..9fa8335e6dc
--- /dev/null
+++ b/dom/html/test/browser_DOMDocElementInserted.js
@@ -0,0 +1,24 @@
+// Tests that the DOMDocElementInserted event is visible on the frame
+add_task(function*() {
+ let tab = gBrowser.addTab();
+ let uri = "data:text/html;charset=utf-8,"
+
+ let eventPromise = ContentTask.spawn(tab.linkedBrowser, null, function() {
+ Cu.import("resource://gre/modules/PromiseUtils.jsm");
+ let deferred = PromiseUtils.defer();
+
+ let listener = (event) => {
+ removeEventListener("DOMDocElementInserted", listener, true);
+ deferred.resolve(event.target.documentURIObject.spec);
+ };
+ addEventListener("DOMDocElementInserted", listener, true);
+
+ return deferred.promise;
+ });
+
+ tab.linkedBrowser.loadURI(uri);
+ let loadedURI = yield eventPromise;
+ is(loadedURI, uri, "Should have seen the event for the right URI");
+
+ gBrowser.removeTab(tab);
+});
diff --git a/dom/tests/mochitest/bugs/test_DOMWindowCreated_chromeonly.html b/dom/tests/mochitest/bugs/test_DOMWindowCreated_chromeonly.html
index d75e24bb314..fc1a4cbbc1f 100644
--- a/dom/tests/mochitest/bugs/test_DOMWindowCreated_chromeonly.html
+++ b/dom/tests/mochitest/bugs/test_DOMWindowCreated_chromeonly.html
@@ -9,5 +9,6 @@