Bug 1154812. Fix location.pathname to return the right thing in workers. r=baku
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 15 Apr 2015 16:32:53 -0400
changeset 258320 3fb858ffea7c5cef00bb0c23b9b72dde89fb24c5
parent 258296 7798f96e4cae923eff08d41b64b35546faaea473
child 258321 a6eac2cc6ba7757a01e262a5a5decb9bf09e31d9
push id8007
push userraliiev@mozilla.com
push dateMon, 11 May 2015 19:23:16 +0000
treeherdermozilla-aurora@e2ce1aac996e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1154812
milestone40.0a1
Bug 1154812. Fix location.pathname to return the right thing in workers. r=baku
dom/base/nsContentUtils.cpp
dom/base/nsContentUtils.h
dom/workers/WorkerPrivate.cpp
testing/web-platform/meta/workers/interfaces/WorkerGlobalScope/location/members.html.ini
testing/web-platform/meta/workers/interfaces/WorkerGlobalScope/location/redirect.html.ini
testing/web-platform/meta/workers/interfaces/WorkerGlobalScope/location/setting-members.html.ini
testing/web-platform/meta/workers/interfaces/WorkerGlobalScope/location/worker-separate-file.html.ini
testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.html
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -7134,32 +7134,37 @@ nsContentUtils::GetInnerWindowID(nsIRequ
   }
 
   nsPIDOMWindow* inner = pwindow->IsInnerWindow() ? pwindow.get() : pwindow->GetCurrentInnerWindow();
 
   return inner ? inner->WindowID() : 0;
 }
 
 void
-nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost)
+nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI, nsCString& aHost)
 {
   aHost.Truncate();
-  nsAutoCString hostname;
-  nsresult rv = aURI->GetHost(hostname);
+  nsresult rv = aURI->GetHost(aHost);
   if (NS_FAILED(rv)) { // Some URIs do not have a host
     return;
   }
 
-  if (hostname.FindChar(':') != -1) { // Escape IPv6 address
-    MOZ_ASSERT(!hostname.Length() ||
-      (hostname[0] !='[' && hostname[hostname.Length() - 1] != ']'));
-    hostname.Insert('[', 0);
-    hostname.Append(']');
-  }
-
+  if (aHost.FindChar(':') != -1) { // Escape IPv6 address
+    MOZ_ASSERT(!aHost.Length() ||
+      (aHost[0] !='[' && aHost[aHost.Length() - 1] != ']'));
+    aHost.Insert('[', 0);
+    aHost.Append(']');
+  }
+}
+
+void
+nsContentUtils::GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost)
+{
+  nsAutoCString hostname;
+  GetHostOrIPv6WithBrackets(aURI, hostname);
   CopyUTF8toUTF16(hostname, aHost);
 }
 
 void
 nsContentUtils::CallOnAllRemoteChildren(nsIMessageBroadcaster* aManager,
                                         CallOnRemoteChildFunction aCallback,
                                         void* aArg)
 {
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -2277,16 +2277,17 @@ public:
    */
   static uint64_t GetInnerWindowID(nsIRequest* aRequest);
 
   /**
    * If the hostname for aURI is an IPv6 it encloses it in brackets,
    * otherwise it just outputs the hostname in aHost.
    */
   static void GetHostOrIPv6WithBrackets(nsIURI* aURI, nsAString& aHost);
+  static void GetHostOrIPv6WithBrackets(nsIURI* aURI, nsCString& aHost);
 
   /*
    * Call the given callback on all remote children of the given top-level
    * window.
    */
   static void CallOnAllRemoteChildren(nsIDOMWindow* aWindow,
                                       CallOnRemoteChildFunction aCallback,
                                       void* aArg);
--- a/dom/workers/WorkerPrivate.cpp
+++ b/dom/workers/WorkerPrivate.cpp
@@ -3991,27 +3991,26 @@ WorkerPrivateParent<Derived>::SetBaseURI
   }
 
   mLoadInfo.mBaseURI = aBaseURI;
 
   if (NS_FAILED(aBaseURI->GetSpec(mLocationInfo.mHref))) {
     mLocationInfo.mHref.Truncate();
   }
 
-  if (NS_FAILED(aBaseURI->GetHost(mLocationInfo.mHostname))) {
-    mLocationInfo.mHostname.Truncate();
-  }
-
-  if (NS_FAILED(aBaseURI->GetPath(mLocationInfo.mPathname))) {
+  mLocationInfo.mHostname.Truncate();
+  nsContentUtils::GetHostOrIPv6WithBrackets(aBaseURI, mLocationInfo.mHostname);
+
+  nsCOMPtr<nsIURL> url(do_QueryInterface(aBaseURI));
+  if (!url || NS_FAILED(url->GetFilePath(mLocationInfo.mPathname))) {
     mLocationInfo.mPathname.Truncate();
   }
 
   nsCString temp;
 
-  nsCOMPtr<nsIURL> url(do_QueryInterface(aBaseURI));
   if (url && NS_SUCCEEDED(url->GetQuery(temp)) && !temp.IsEmpty()) {
     mLocationInfo.mSearch.Assign('?');
     mLocationInfo.mSearch.Append(temp);
   }
 
   if (NS_SUCCEEDED(aBaseURI->GetRef(temp)) && !temp.IsEmpty()) {
     nsCOMPtr<nsITextToSubURI> converter =
       do_GetService(NS_ITEXTTOSUBURI_CONTRACTID);
deleted file mode 100644
--- a/testing/web-platform/meta/workers/interfaces/WorkerGlobalScope/location/members.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[members.html]
-  type: testharness
-  [members of WorkerLocation]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/workers/interfaces/WorkerGlobalScope/location/redirect.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[redirect.html]
-  type: testharness
-  [location with a worker in separate file that redirects]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/workers/interfaces/WorkerGlobalScope/location/setting-members.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[setting-members.html]
-  type: testharness
-  [setting members of WorkerLocation]
-    expected: FAIL
-
deleted file mode 100644
--- a/testing/web-platform/meta/workers/interfaces/WorkerGlobalScope/location/worker-separate-file.html.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-[worker-separate-file.html]
-  type: testharness
-  [location with a worker in separate file]
-    expected: FAIL
-
--- a/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.html
+++ b/testing/web-platform/tests/workers/interfaces/WorkerGlobalScope/location/redirect.html
@@ -4,17 +4,17 @@
 <!doctype html>
 <title>location with a worker in separate file that redirects</title>
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
 <div id="log"></div>
 <script>
 async_test(function() {
   var worker = new Worker('helper-redirect.py?fail');
-  worker.onmessage = this.step_func(function(e) {
+  worker.onmessage = this.step_func_done(function(e) {
     assert_equals(e.data[0], location.href.replace(/\/[^\/]+$/, '/post-location-members.js?a'));
     assert_equals(e.data[1], location.protocol);
     assert_equals(e.data[2], location.host);
     assert_equals(e.data[3], location.hostname);
     assert_equals(e.data[4], location.port);
     assert_equals(e.data[5], location.pathname.replace(/\/[^\/]+$/, '/post-location-members.js'));
     assert_equals(e.data[6], '?a');
     assert_equals(e.data[7], '');