Bug 1266077. Fix <base> href getter to follow the spec; it should be using the fallback base URI to resolve against, not the document URI. r=bkelly
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 22 Apr 2016 17:59:16 -0400
changeset 294548 1d1b0febedc2aa87ce679402b28e689ff36d0986
parent 294547 1e006c7b5eda3864a980561e5c9a61b95bc7bbf9
child 294549 df899bb47807cc1e7c8841dd77d2eed979ebeb77
push id75589
push userbzbarsky@mozilla.com
push dateFri, 22 Apr 2016 21:59:54 +0000
treeherdermozilla-inbound@1d1b0febedc2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbkelly
bugs1266077
milestone48.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 1266077. Fix <base> href getter to follow the spec; it should be using the fallback base URI to resolve against, not the document URI. r=bkelly
dom/html/HTMLSharedElement.cpp
testing/web-platform/meta/MANIFEST.json
testing/web-platform/meta/html/semantics/document-metadata/the-base-element/base_about_blank.html.ini
testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base_about_blank.html
testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base_href_invalid.html
testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base_srcdoc.html
--- a/dom/html/HTMLSharedElement.cpp
+++ b/dom/html/HTMLSharedElement.cpp
@@ -56,23 +56,25 @@ NS_IMPL_URI_ATTR(HTMLSharedElement, Cite
 NS_IMPL_STRING_ATTR(HTMLSharedElement, Version, version)
 
 // nsIDOMHTMLBaseElement
 NS_IMPL_STRING_ATTR(HTMLSharedElement, Target, target)
 
 NS_IMETHODIMP
 HTMLSharedElement::GetHref(nsAString& aValue)
 {
+  MOZ_ASSERT(mNodeInfo->Equals(nsGkAtoms::base),
+             "This should only get called for <base> elements");
   nsAutoString href;
   GetAttr(kNameSpaceID_None, nsGkAtoms::href, href);
 
   nsCOMPtr<nsIURI> uri;
   nsIDocument* doc = OwnerDoc();
   nsContentUtils::NewURIWithDocumentCharset(
-    getter_AddRefs(uri), href, doc, doc->GetDocumentURI());
+    getter_AddRefs(uri), href, doc, doc->GetFallbackBaseURI());
 
   if (!uri) {
     aValue = href;
     return NS_OK;
   }
   
   nsAutoCString spec;
   uri->GetSpec(spec);
--- a/testing/web-platform/meta/MANIFEST.json
+++ b/testing/web-platform/meta/MANIFEST.json
@@ -35241,16 +35241,34 @@
       },
       "testharness": {
         "XMLHttpRequest/open-url-multi-window-6.htm": [
           {
             "path": "XMLHttpRequest/open-url-multi-window-6.htm",
             "url": "/XMLHttpRequest/open-url-multi-window-6.htm"
           }
         ],
+        "html/semantics/document-metadata/the-base-element/base_about_blank.html": [
+          {
+            "path": "html/semantics/document-metadata/the-base-element/base_about_blank.html",
+            "url": "/html/semantics/document-metadata/the-base-element/base_about_blank.html"
+          }
+        ],
+        "html/semantics/document-metadata/the-base-element/base_href_invalid.html": [
+          {
+            "path": "html/semantics/document-metadata/the-base-element/base_href_invalid.html",
+            "url": "/html/semantics/document-metadata/the-base-element/base_href_invalid.html"
+          }
+        ],
+        "html/semantics/document-metadata/the-base-element/base_srcdoc.html": [
+          {
+            "path": "html/semantics/document-metadata/the-base-element/base_srcdoc.html",
+            "url": "/html/semantics/document-metadata/the-base-element/base_srcdoc.html"
+          }
+        ],
         "html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html": [
           {
             "path": "html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html",
             "url": "/html/semantics/embedded-content/the-embed-element/embed-ignored-in-media-element.html"
           }
         ],
         "html/webappapis/scripting/processing-model-2/window-onerror-with-cross-frame-event-listeners-1.html": [
           {
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/html/semantics/document-metadata/the-base-element/base_about_blank.html.ini
@@ -0,0 +1,4 @@
+[base_about_blank.html]
+  type: testharness
+  [base element in about:blank document should resolve against its fallback base URI]
+    expected: FAIL
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base_about_blank.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>base element in about:blank document should resolve against its fallback base URI</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<iframe></iframe>
+<script>
+var t = async_test();
+addEventListener("load", t.step_func_done(function() {
+  var doc = frames[0].document;
+  var b = doc.createElement("base");
+  b.setAttribute("href", "test");
+  var newBaseValue = location.href.replace(/\/[^/]*$/, "/") + "test";
+  assert_equals(b.href, newBaseValue);
+  assert_equals(doc.baseURI, location.href);
+  doc.head.appendChild(b);
+  assert_equals(doc.baseURI, newBaseValue);
+}));
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base_href_invalid.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>base element with unparseable href should have .href getter return attr value</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+test(function() {
+  var b = document.createElement("base");
+  b.setAttribute("href", "//test:test");
+  assert_equals(b.href, "//test:test");
+});
+</script>
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/semantics/document-metadata/the-base-element/base_srcdoc.html
@@ -0,0 +1,19 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>base element in srcdoc document should resolve against its fallback base URI</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<iframe srcdoc=""></iframe>
+<script>
+var t = async_test();
+addEventListener("load", t.step_func_done(function() {
+  var doc = frames[0].document;
+  var b = doc.createElement("base");
+  b.setAttribute("href", "test");
+  var newBaseValue = location.href.replace(/\/[^/]*$/, "/") + "test";
+  assert_equals(b.href, newBaseValue);
+  assert_equals(doc.baseURI, location.href);
+  doc.head.appendChild(b);
+  assert_equals(doc.baseURI, newBaseValue);
+}));
+</script>