Bug 1254477 - Return null for defaultRequest at receiver side. r=smaug
authorKershaw Chang <kechang@mozilla.com>
Thu, 26 May 2016 08:27:00 -0400
changeset 338249 d4a5ef2ca595a3f3fcafd16062c4f1c22ce35c79
parent 338248 d61769108d96a74b2389bc36c4c00f4686a0b794
child 338250 0d9cbc1fdbe9baac069a21caec3c98a239a8f331
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1254477
milestone49.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 1254477 - Return null for defaultRequest at receiver side. r=smaug
dom/presentation/Presentation.cpp
dom/presentation/tests/mochitest/file_presentation_receiver.html
--- a/dom/presentation/Presentation.cpp
+++ b/dom/presentation/Presentation.cpp
@@ -47,22 +47,30 @@ Presentation::WrapObject(JSContext* aCx,
                          JS::Handle<JSObject*> aGivenProto)
 {
   return PresentationBinding::Wrap(aCx, this, aGivenProto);
 }
 
 void
 Presentation::SetDefaultRequest(PresentationRequest* aRequest)
 {
+  if (IsInPresentedContent()) {
+    return;
+  }
+
   mDefaultRequest = aRequest;
 }
 
 already_AddRefed<PresentationRequest>
 Presentation::GetDefaultRequest() const
 {
+  if (IsInPresentedContent()) {
+    return nullptr;
+  }
+
   RefPtr<PresentationRequest> request = mDefaultRequest;
   return request.forget();
 }
 
 already_AddRefed<PresentationReceiver>
 Presentation::GetReceiver()
 {
   // return the same receiver if already created
--- a/dom/presentation/tests/mochitest/file_presentation_receiver.html
+++ b/dom/presentation/tests/mochitest/file_presentation_receiver.html
@@ -49,16 +49,30 @@ function testConnectionAvailable() {
         ok(false, "Error occurred when getting the connection: " + aError);
         finish();
         aReject();
       }
     );
   });
 }
 
+function testDefauleRequestIsNull() {
+  return new Promise(function(aResolve, aReject) {
+    navigator.presentation.defaultRequest = new PresentationRequest("http://example.com");
+    if (navigator.presentation.defaultRequest === null) {
+      ok(true, "defaultRequest should be null.");
+      aResolve();
+    }
+    else {
+      ok(false, "defaultRequest should be null.");
+      aReject();
+    }
+  });
+}
+
 function testConnectionAvailableSameOriginInnerIframe() {
   return new Promise(function(aResolve, aReject) {
     var iframe = document.createElement('iframe');
     iframe.setAttribute('src', './file_presentation_receiver_inner_iframe.html');
     document.body.appendChild(iframe);
 
     aResolve();
   });
@@ -109,16 +123,17 @@ function testTerminateConnection() {
       aResolve();
     };
 
     connection.terminate();
   });
 }
 
 testConnectionAvailable().
+then(testDefauleRequestIsNull).
 then(testConnectionAvailableSameOriginInnerIframe).
 then(testConnectionUnavailableDiffOriginInnerIframe).
 then(testConnectionReady).
 then(testIncomingMessage).
 then(testTerminateConnection).
 then(finish);
 
 </script>