Bug 1291971 - Part 6, enable receiver idlharness test. r=smaug. draft
authorShih-Chiang Chien <schien@mozilla.com>
Thu, 20 Oct 2016 11:27:55 +0800
changeset 430817 70595ad9e8e56856c464fa12c2c2eeadc9e48063
parent 430816 2b47a273aa9a4276aa24ae6ee10cb003b04417ba
child 430818 cce21a157c964f41f31c7c3f3bf69e3046fb6a1d
push id33907
push userschien@mozilla.com
push dateFri, 28 Oct 2016 06:37:18 +0000
reviewerssmaug
bugs1291971
milestone52.0a1
Bug 1291971 - Part 6, enable receiver idlharness test. r=smaug. MozReview-Commit-ID: BDZ8daA2gpj
dom/base/nsContentUtils.cpp
dom/presentation/Presentation.cpp
dom/presentation/PresentationReceiver.cpp
testing/profiles/prefs_general.js
testing/web-platform/meta/presentation-api/receiving-ua/idlharness.html.ini
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -9336,16 +9336,41 @@ nsContentUtils::SetScrollbarsVisibility(
   }
 }
 
 /* static */ void
 nsContentUtils::GetPresentationURL(nsIDocShell* aDocShell, nsAString& aPresentationUrl)
 {
   MOZ_ASSERT(aDocShell);
 
+  // Simulate receiver context for web platform test
+  if (Preferences::GetBool("dom.presentation.testing.simulate-receiver")) {
+    nsCOMPtr<nsIDocument> doc;
+
+    nsCOMPtr<nsPIDOMWindowOuter> docShellWin =
+      do_QueryInterface(aDocShell->GetScriptGlobalObject());
+    if (docShellWin) {
+      doc = docShellWin->GetExtantDoc();
+    }
+
+    if (NS_WARN_IF(!doc)) {
+      return;
+    }
+
+    nsCOMPtr<nsIURI> uri = doc->GetDocumentURI();
+    if (NS_WARN_IF(!uri)) {
+      return;
+    }
+
+    nsAutoCString uriStr;
+    uri->GetSpec(uriStr);
+    aPresentationUrl = NS_ConvertUTF8toUTF16(uriStr);
+    return;
+  }
+
   if (XRE_IsContentProcess()) {
     nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
     aDocShell->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
     nsCOMPtr<nsIDocShellTreeItem> root;
     aDocShell->GetRootTreeItem(getter_AddRefs(root));
     if (sameTypeRoot.get() == root.get()) {
       // presentation URL is stored in TabChild for the top most
       // <iframe mozbrowser> in content process.
--- a/dom/presentation/Presentation.cpp
+++ b/dom/presentation/Presentation.cpp
@@ -57,17 +57,18 @@ Presentation::HasReceiverSupport(JSConte
 
   // Grant access to browser receiving pages and their same-origin iframes. (App
   // pages should be controlled by "presentation" permission in app manifests.)
   nsCOMPtr<nsIDocShell> docshell = inner->GetDocShell();
   if (!docshell) {
     return false;
   }
 
-  if (!docshell->GetIsInMozBrowserOrApp()) {
+  if (!Preferences::GetBool("dom.presentation.testing.simulate-receiver") &&
+      !docshell->GetIsInMozBrowserOrApp()) {
     return false;
   }
 
   nsAutoString presentationURL;
   nsContentUtils::GetPresentationURL(docshell, presentationURL);
 
   if (presentationURL.IsEmpty()) {
     return false;
--- a/dom/presentation/PresentationReceiver.cpp
+++ b/dom/presentation/PresentationReceiver.cpp
@@ -26,16 +26,17 @@ NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Pr
                                       mConnectionList)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(PresentationReceiver)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(PresentationReceiver)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PresentationReceiver)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsIPresentationRespondingListener)
+  NS_INTERFACE_MAP_ENTRY(nsISupports)
 NS_INTERFACE_MAP_END
 
 /* static */ already_AddRefed<PresentationReceiver>
 PresentationReceiver::Create(nsPIDOMWindowInner* aWindow)
 {
   RefPtr<PresentationReceiver> receiver = new PresentationReceiver(aWindow);
   return NS_WARN_IF(!receiver->Init()) ? nullptr : receiver.forget();
 }
--- a/testing/profiles/prefs_general.js
+++ b/testing/profiles/prefs_general.js
@@ -231,16 +231,17 @@ user_pref("general.useragent.updates.ena
 
 // Disable webapp updates.  Yes, it is supposed to be an integer.
 user_pref("browser.webapps.checkForUpdates", 0);
 
 // Enable debug logging in the tcp presentation server.
 user_pref("dom.presentation.tcp_server.debug", true);
 // Enable debug logging in the presentation core service.
 user_pref("logging.Presentation", "debug");
+user_pref("dom.presentation.testing.simulate-receiver", false);
 
 // Don't connect to Yahoo! for RSS feed tests.
 // en-US only uses .types.0.uri, but set all of them just to be sure.
 user_pref('browser.contentHandlers.types.0.uri', 'http://test1.example.org/rss?url=%%s')
 user_pref('browser.contentHandlers.types.1.uri', 'http://test1.example.org/rss?url=%%s')
 user_pref('browser.contentHandlers.types.2.uri', 'http://test1.example.org/rss?url=%%s')
 user_pref('browser.contentHandlers.types.3.uri', 'http://test1.example.org/rss?url=%%s')
 user_pref('browser.contentHandlers.types.4.uri', 'http://test1.example.org/rss?url=%%s')
--- a/testing/web-platform/meta/presentation-api/receiving-ua/idlharness.html.ini
+++ b/testing/web-platform/meta/presentation-api/receiving-ua/idlharness.html.ini
@@ -1,194 +1,8 @@
 [idlharness.html]
   type: testharness
-  [Navigator interface: attribute presentation]
-    expected: FAIL
-
-  [Presentation interface: existence and properties of interface object]
-    expected: FAIL
-
-  [Presentation interface object length]
-    expected: FAIL
-
-  [Presentation interface object name]
-    expected: FAIL
-
-  [Presentation interface: existence and properties of interface prototype object]
-    expected: FAIL
-
-  [Presentation interface: existence and properties of interface prototype object's "constructor" property]
-    expected: FAIL
-
-  [Presentation interface: attribute receiver]
-    expected: FAIL
-
-  [Presentation must be primary interface of navigator.presentation]
-    expected: FAIL
-
-  [Stringification of navigator.presentation]
-    expected: FAIL
-
-  [Presentation interface: navigator.presentation must inherit property "receiver" with the proper type (0)]
-    expected: FAIL
-
-  [PresentationConnectionAvailableEvent interface: existence and properties of interface object]
-    expected: FAIL
-
-  [PresentationConnectionAvailableEvent interface object length]
-    expected: FAIL
-
-  [PresentationConnectionAvailableEvent interface object name]
-    expected: FAIL
-
-  [PresentationConnectionAvailableEvent interface: existence and properties of interface prototype object]
-    expected: FAIL
-
-  [PresentationConnectionAvailableEvent interface: existence and properties of interface prototype object's "constructor" property]
-    expected: FAIL
-
-  [PresentationConnectionAvailableEvent interface: attribute connection]
-    expected: FAIL
-
-  [PresentationConnection interface: existence and properties of interface object]
-    expected: FAIL
-
-  [PresentationConnection interface object length]
-    expected: FAIL
-
-  [PresentationConnection interface object name]
-    expected: FAIL
-
-  [PresentationConnection interface: existence and properties of interface prototype object]
-    expected: FAIL
-
-  [PresentationConnection interface: existence and properties of interface prototype object's "constructor" property]
-    expected: FAIL
-
-  [PresentationConnection interface: attribute id]
-    expected: FAIL
-
-  [PresentationConnection interface: attribute state]
-    expected: FAIL
-
-  [PresentationConnection interface: operation close()]
-    expected: FAIL
-
-  [PresentationConnection interface: operation terminate()]
-    expected: FAIL
-
-  [PresentationConnection interface: attribute onconnect]
-    expected: FAIL
-
-  [PresentationConnection interface: attribute onclose]
-    expected: FAIL
-
-  [PresentationConnection interface: attribute onterminate]
-    expected: FAIL
-
-  [PresentationConnection interface: attribute binaryType]
-    expected: FAIL
-
-  [PresentationConnection interface: attribute onmessage]
-    expected: FAIL
-
-  [PresentationConnection interface: operation send(DOMString)]
-    expected: FAIL
-
-  [PresentationConnection interface: operation send(Blob)]
-    expected: FAIL
-
-  [PresentationConnection interface: operation send(ArrayBuffer)]
-    expected: FAIL
-
-  [PresentationConnection interface: operation send(ArrayBufferView)]
-    expected: FAIL
-
-  [PresentationConnectionClosedEvent interface: existence and properties of interface object]
-    expected: FAIL
-
-  [PresentationConnectionClosedEvent interface object length]
-    expected: FAIL
-
-  [PresentationConnectionClosedEvent interface object name]
-    expected: FAIL
-
-  [PresentationConnectionClosedEvent interface: existence and properties of interface prototype object]
-    expected: FAIL
-
-  [PresentationConnectionClosedEvent interface: existence and properties of interface prototype object's "constructor" property]
-    expected: FAIL
-
-  [PresentationConnectionClosedEvent interface: attribute reason]
-    expected: FAIL
-
-  [PresentationConnectionClosedEvent interface: attribute message]
-    expected: FAIL
-
-  [PresentationReceiver interface: existence and properties of interface object]
-    expected: FAIL
-
-  [PresentationReceiver interface object length]
-    expected: FAIL
-
-  [PresentationReceiver interface object name]
-    expected: FAIL
-
-  [PresentationReceiver interface: existence and properties of interface prototype object]
-    expected: FAIL
-
-  [PresentationReceiver interface: existence and properties of interface prototype object's "constructor" property]
-    expected: FAIL
-
-  [PresentationReceiver interface: attribute connectionList]
-    expected: FAIL
-
-  [PresentationReceiver must be primary interface of navigator.presentation.receiver]
-    expected: FAIL
-
-  [Stringification of navigator.presentation.receiver]
-    expected: FAIL
-
+  prefs: [dom.presentation.enabled: true,
+          dom.presentation.receiver.enabled: true,
+          dom.presentation.testing.simulate-receiver: true,
+          dom.presentation.device.name: "Firefox"]
   [PresentationReceiver interface: navigator.presentation.receiver must inherit property "connectionList" with the proper type (0)]
     expected: FAIL
-
-  [PresentationConnectionList interface: existence and properties of interface object]
-    expected: FAIL
-
-  [PresentationConnectionList interface object length]
-    expected: FAIL
-
-  [PresentationConnectionList interface object name]
-    expected: FAIL
-
-  [PresentationConnectionList interface: existence and properties of interface prototype object]
-    expected: FAIL
-
-  [PresentationConnectionList interface: existence and properties of interface prototype object's "constructor" property]
-    expected: FAIL
-
-  [PresentationConnectionList interface: attribute connections]
-    expected: FAIL
-
-  [PresentationConnectionList interface: attribute onconnectionavailable]
-    expected: FAIL
-
-  [PresentationConnectionCloseEvent interface: existence and properties of interface object]
-    expected: FAIL
-
-  [PresentationConnectionCloseEvent interface object length]
-    expected: FAIL
-
-  [PresentationConnectionCloseEvent interface object name]
-    expected: FAIL
-
-  [PresentationConnectionCloseEvent interface: existence and properties of interface prototype object]
-    expected: FAIL
-
-  [PresentationConnectionCloseEvent interface: existence and properties of interface prototype object's "constructor" property]
-    expected: FAIL
-
-  [PresentationConnectionCloseEvent interface: attribute reason]
-    expected: FAIL
-
-  [PresentationConnectionCloseEvent interface: attribute message]
-    expected: FAIL
-