Bug 1093033 - Imports should update their CustomElements. r=wchen
authorGabor Krizsanits <gkrizsanits@mozilla.com>
Thu, 06 Nov 2014 14:05:36 +0100
changeset 214393 e2a1f8575950dc6f5a9cdb54ef2b2fa39a043904
parent 214392 f1989cb41965b06f4d3db89764c3606ee136814a
child 214394 b141758cfbc325e2c1bcf6f694e4f40d225820b3
push id27780
push userkwierso@gmail.com
push dateFri, 07 Nov 2014 02:25:05 +0000
treeherdermozilla-central@e6d47abb6a7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswchen
bugs1093033
milestone36.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 1093033 - Imports should update their CustomElements. r=wchen
dom/base/nsDocument.cpp
dom/base/nsDocument.h
dom/html/test/imports/file_element_upgrade.html
dom/html/test/imports/mochitest.ini
dom/html/test/imports/test_element_upgrade.html
testing/web-platform/meta/custom-elements/creating-and-passing-registries/share-registry-import-document.html.ini
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2302,17 +2302,22 @@ nsDocument::ResetToURI(nsIURI *aURI, nsI
       mChildren.RemoveChildAt(i);
       nsNodeUtils::ContentRemoved(this, content, i, previousSibling);
       content->UnbindFromTree();
     }
     mCachedRootElement = nullptr;
   }
   mInUnlinkOrDeletion = oldVal;
 
-  mRegistry = nullptr;
+  if (!mMasterDocument) {
+    // "When creating an import, use the registry of the master document."
+    // Note: at this point the mMasterDocument is already set for imports
+    // (and only for imports)
+    mRegistry = nullptr;
+  }
 
   // Reset our stylesheets
   ResetStylesheetsToURI(aURI);
 
   // Release the listener manager
   if (mListenerManager) {
     mListenerManager->Disconnect();
     mListenerManager = nullptr;
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -1299,17 +1299,19 @@ public:
   virtual nsIDocument* MasterDocument()
   {
     return mMasterDocument ? mMasterDocument.get()
                            : this;
   }
 
   virtual void SetMasterDocument(nsIDocument* master)
   {
+    MOZ_ASSERT(master);
     mMasterDocument = master;
+    UseRegistryFromDocument(mMasterDocument);
   }
 
   virtual bool IsMasterDocument()
   {
     return !mMasterDocument;
   }
 
   virtual mozilla::dom::ImportManager* ImportManager()
new file mode 100644
--- /dev/null
+++ b/dom/html/test/imports/file_element_upgrade.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html lang="en-US">
+<head>
+</head>
+<body>
+  <x-foo></x-foo>
+  <script>
+    var prototype = Object.create(HTMLElement.prototype);
+    prototype.createdCallback = function() {
+      createdCallbackCalled = true;
+    }
+    document.registerElement('x-foo', {prototype: prototype});
+  </script>
+</body>
+</html>
--- a/dom/html/test/imports/mochitest.ini
+++ b/dom/html/test/imports/mochitest.ini
@@ -32,21 +32,24 @@ support-files =
   file_cycle_4_D.html
   file_cycle_4_E.html
   file_encoding.html
   file_simple_import.html
   file_blocking_DOMContentLoaded_A.html
   file_blocking_DOMContentLoaded_B.html
   file_blocking_DOMContentLoaded_C.html
   file_blocking_DOMContentLoaded_D.html
+  file_element_upgrade.html
+
 
 [test_cycle_1.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_cycle_2.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_cycle_3.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_cycle_4.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_blocking_DOMContentLoaded.html]
 skip-if = toolkit == 'gonk' # nested imports fail on b2g emulator
 [test_encoding.html]
 [test_defaultView.html]
+[test_element_upgrade.html]
new file mode 100644
--- /dev/null
+++ b/dom/html/test/imports/test_element_upgrade.html
@@ -0,0 +1,34 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1081107
+-->
+<head>
+  <title>Test for Bug 1081107</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
+</head>
+<body>
+  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1081107">Mozilla Bug 1081107</a>
+  <script type="text/javascript">
+    SimpleTest.waitForExplicitFinish();
+    var counter = 0;
+    var fcounter = 0;
+    var createdCallbackCalled = false;
+    function loaded() {
+      counter++;
+    }
+    function failed() {
+      fcounter++;
+    }
+  </script>
+  <link rel="import" href="file_element_upgrade.html" onload="loaded()" onerror="failed()"></link>
+  <script type="text/javascript">
+    is(counter, 1, "Imports are loaded");
+    is(fcounter, 0, "No error in imports");
+    ok(createdCallbackCalled, "custom element in import has been upgraded");
+    SimpleTest.finish();
+  </script>
+</body>
+</html>
--- a/testing/web-platform/meta/custom-elements/creating-and-passing-registries/share-registry-import-document.html.ini
+++ b/testing/web-platform/meta/custom-elements/creating-and-passing-registries/share-registry-import-document.html.ini
@@ -8,11 +8,8 @@
     expected: TIMEOUT
 
   [Registry of the imported document should be shared with master document. Import is asynchronous]
     expected: TIMEOUT
 
   [Registry of the master document should be shared with imported document. Import is asynchronous]
     expected: TIMEOUT
 
-  [Registry of the master document should be shared with imported document. Import is syncronous]
-    expected: FAIL
-