Bug 1192101 - Part 5 - Support PresentationRequest / PresentationAvailability / getSession(s). Part 5 - Tests. r=smaug
authorSean Lin <selin@mozilla.com>
Wed, 09 Sep 2015 17:49:32 +0800
changeset 294911 967ff76a23a3dd43b5e03034783225649b504ed9
parent 294910 2fe2431a5f083a1aa4e003f5e571c091a4ba9291
child 294912 0dc9f022bede140148965c91f4285b3cf15c5613
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1192101
milestone43.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 1192101 - Part 5 - Support PresentationRequest / PresentationAvailability / getSession(s). Part 5 - Tests. r=smaug
dom/presentation/tests/mochitest/file_presentation_non_receiver_oop.html
dom/presentation/tests/mochitest/file_presentation_receiver.html
dom/presentation/tests/mochitest/file_presentation_receiver_oop.html
dom/presentation/tests/mochitest/file_presentation_receiver_start_session_error.html
dom/presentation/tests/mochitest/mochitest.ini
dom/presentation/tests/mochitest/test_presentation_receiver.html
dom/presentation/tests/mochitest/test_presentation_sender.html
dom/presentation/tests/mochitest/test_presentation_sender_default_request.html
dom/presentation/tests/mochitest/test_presentation_sender_disconnect.html
dom/presentation/tests/mochitest/test_presentation_sender_start_session_error.html
--- a/dom/presentation/tests/mochitest/file_presentation_non_receiver_oop.html
+++ b/dom/presentation/tests/mochitest/file_presentation_non_receiver_oop.html
@@ -24,18 +24,28 @@ function info(msg) {
 
 function finish() {
   alert('DONE');
 }
 
 function testSessionAvailable() {
   return new Promise(function(aResolve, aReject) {
     ok(navigator.presentation, "navigator.presentation should be available in OOP pages.");
-    ok(!navigator.presentation.session, "Non-receiving OOP pages shouldn't get a predefined presentation session instance.");
-    aResolve();
+
+    navigator.presentation.getSessions().then(
+      function(aSessions) {
+        is(aSessions.length, 0, "Non-receiving OOP pages shouldn't get a predefined presentation session instance.");
+        aResolve();
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting sessions: " + aError);
+        teardown();
+        aReject();
+      }
+    );
   });
 }
 
 testSessionAvailable().
 then(finish);
 
 </script>
 </body>
--- a/dom/presentation/tests/mochitest/file_presentation_receiver.html
+++ b/dom/presentation/tests/mochitest/file_presentation_receiver.html
@@ -31,20 +31,30 @@ function finish() {
 }
 
 var session;
 
 function testSessionAvailable() {
   return new Promise(function(aResolve, aReject) {
     ok(navigator.presentation, "navigator.presentation should be available.");
 
-    session = navigator.presentation.session;
-    ok(session.id, "Session ID should be set: " + session.id);
-    is(session.state, "disconnected", "Session state at receiver side should be disconnected by default.");
-    aResolve();
+    navigator.presentation.getSession().then(
+      function(aSession) {
+        session = aSession;
+
+        ok(session.id, "Session ID should be set: " + session.id);
+        is(session.state, "disconnected", "Session state at receiver side should be disconnected by default.");
+        aResolve();
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting the session: " + aError);
+        teardown();
+        aReject();
+      }
+    );
   });
 }
 
 function testSessionReady() {
   return new Promise(function(aResolve, aReject) {
     session.onstatechange = function() {
       session.onstatechange = null;
       is(session.state, "connected", "Session state should become connected.");
--- a/dom/presentation/tests/mochitest/file_presentation_receiver_oop.html
+++ b/dom/presentation/tests/mochitest/file_presentation_receiver_oop.html
@@ -31,20 +31,30 @@ function finish() {
 }
 
 var session;
 
 function testSessionAvailable() {
   return new Promise(function(aResolve, aReject) {
     ok(navigator.presentation, "navigator.presentation should be available.");
 
-    session = navigator.presentation.session;
-    ok(session.id, "Session ID should be set: " + session.id);
-    is(session.state, "disconnected", "Session state at receiver side should be disconnected by default.");
-    aResolve();
+    navigator.presentation.getSession().then(
+      function(aSession) {
+        session = aSession;
+
+        ok(session.id, "Session ID should be set: " + session.id);
+        is(session.state, "disconnected", "Session state at receiver side should be disconnected by default.");
+        aResolve();
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting the session: " + aError);
+        teardown();
+        aReject();
+      }
+    );
   });
 }
 
 function testSessionReady() {
   return new Promise(function(aResolve, aReject) {
     session.onstatechange = function() {
       session.onstatechange = null;
       is(session.state, "connected", "Session state should become connected.");
--- a/dom/presentation/tests/mochitest/file_presentation_receiver_start_session_error.html
+++ b/dom/presentation/tests/mochitest/file_presentation_receiver_start_session_error.html
@@ -31,20 +31,30 @@ function finish() {
 }
 
 var session;
 
 function testSessionAvailable() {
   return new Promise(function(aResolve, aReject) {
     ok(navigator.presentation, "navigator.presentation should be available.");
 
-    session = navigator.presentation.session;
-    ok(session.id, "Session ID should be set: " + session.id);
-    is(session.state, "disconnected", "Session state at receiver side should be disconnected by default.");
-    aResolve();
+    navigator.presentation.getSession().then(
+      function(aSession) {
+        session = aSession;
+
+        ok(session.id, "Session ID should be set: " + session.id);
+        is(session.state, "disconnected", "Session state at receiver side should be disconnected by default.");
+        aResolve();
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting the session: " + aError);
+        teardown();
+        aReject();
+      }
+    );
   });
 }
 
 function testUnexpectedControlChannelClose() {
   return new Promise(function(aResolve, aReject) {
     session.onstatechange = function() {
       session.onstatechange = null;
       is(session.state, "terminated", "Session state should become terminated.");
--- a/dom/presentation/tests/mochitest/mochitest.ini
+++ b/dom/presentation/tests/mochitest/mochitest.ini
@@ -10,16 +10,18 @@ support-files =
 [test_presentation_device_info.html]
 [test_presentation_device_info_permission.html]
 [test_presentation_sender_disconnect.html]
 skip-if = toolkit == 'android' # Bug 1129785
 [test_presentation_sender_start_session_error.html]
 skip-if = toolkit == 'android' # Bug 1129785
 [test_presentation_sender.html]
 skip-if = toolkit == 'android' # Bug 1129785
+[test_presentation_sender_default_request.html]
+skip-if = toolkit == 'android' # Bug 1129785
 [test_presentation_receiver_start_session_error.html]
 skip-if = (e10s || toolkit == 'gonk' || toolkit == 'android') # Bug 1129785
 [test_presentation_receiver_start_session_timeout.html]
 skip-if = (e10s || toolkit == 'gonk' || toolkit == 'android') # Bug 1129785
 [test_presentation_receiver.html]
 skip-if = (e10s || toolkit == 'gonk' || toolkit == 'android') # Bug 1129785
 [test_presentation_receiver_oop.html]
 skip-if = (e10s || toolkit == 'gonk' || toolkit == 'android') # Bug 1129785
--- a/dom/presentation/tests/mochitest/test_presentation_receiver.html
+++ b/dom/presentation/tests/mochitest/test_presentation_receiver.html
@@ -88,19 +88,28 @@ function setup() {
 
 function testIncomingSessionRequest() {
   return new Promise(function(aResolve, aReject) {
     gScript.addMessageListener('receiver-launching', function launchReceiverHandler(aSessionId) {
       gScript.removeMessageListener('receiver-launching', launchReceiverHandler);
       info("Trying to launch receiver page.");
 
       ok(navigator.presentation, "navigator.presentation should be available in in-process pages.");
-      ok(!navigator.presentation.session, "Non-receiving in-process pages shouldn't get a predefined presentation session instance.");
 
-      aResolve();
+      navigator.presentation.getSessions().then(
+        function(aSessions) {
+          is(aSessions.length, 0, "Non-receiving in-process pages shouldn't get a predefined presentation session instance.");
+          aResolve();
+        },
+        function(aError) {
+          ok(false, "Error occurred when getting sessions: " + aError);
+          teardown();
+          aReject();
+        }
+      );
     });
 
     gScript.sendAsyncMessage('trigger-incoming-session-request', receiverUrl);
   });
 }
 
 function teardown() {
   gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
--- a/dom/presentation/tests/mochitest/test_presentation_sender.html
+++ b/dom/presentation/tests/mochitest/test_presentation_sender.html
@@ -10,26 +10,37 @@
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for B2G Presentation API at sender side</a>
 <script type="application/javascript;version=1.8">
 
 'use strict';
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
-var presentation;
+var request;
 var session;
 
 function testSetup() {
   return new Promise(function(aResolve, aReject) {
-    presentation.onavailablechange = function(aIsAvailable) {
-      presentation.onavailablechange = null;
-      ok(aIsAvailable, "Device should be available.");
-      aResolve();
-    };
+    request = new PresentationRequest("http://example.com");
+
+    request.getAvailability().then(
+      function(aAvailability) {
+        aAvailability.onchange = function() {
+          aAvailability.onchange = null;
+          ok(aAvailability.value, "Device should be available.");
+          aResolve();
+        }
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting availability: " + aError);
+        teardown();
+        aReject();
+      }
+    );
 
     gScript.sendAsyncMessage('trigger-device-add');
   });
 }
 
 function testStartSession() {
   return new Promise(function(aResolve, aReject) {
     gScript.addMessageListener('device-prompt', function devicePromptHandler() {
@@ -71,23 +82,39 @@ function testStartSession() {
       gScript.sendAsyncMessage('trigger-incoming-answer');
     });
 
     gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
       gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
       info("Data notification is enabled for data transport channel.");
     });
 
-    presentation.startSession("http://example.com").then(
+    var sessionFromEvent;
+    request.onsessionconnect = function(aEvent) {
+      request.onsessionconnect = null;
+      sessionFromEvent = aEvent.session;
+      ok(sessionFromEvent, "|sessionconnect| event is fired with a session.");
+
+      if (session) {
+        is(session, sessionFromEvent, "The session from promise and the one from |sessionconnect| event should be the same.");
+        aResolve();
+      }
+    };
+
+    request.start().then(
       function(aSession) {
         session = aSession;
         ok(session, "Session should be availlable.");
         ok(session.id, "Session ID should be set.");
         is(session.state, "connected", "Session state at sender side should be connected by default.");
-        aResolve();
+
+        if (sessionFromEvent) {
+          is(session, sessionFromEvent, "The session from promise and the one from |sessionconnect| event should be the same.");
+          aResolve();
+        }
       },
       function(aError) {
         ok(false, "Error occurred when starting session: " + aError);
         teardown();
         aReject();
       }
     );
   });
@@ -144,18 +171,17 @@ function teardown() {
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage('teardown');
 }
 
 function runTests() {
-  ok(navigator.presentation, "navigator.presentation should be available.");
-  presentation = navigator.presentation;
+  ok(window.PresentationRequest, "PresentationRequest should be available.");
 
   testSetup().
   then(testStartSession).
   then(testSend).
   then(testIncomingMessage).
   then(testCloseSession).
   then(teardown);
 }
new file mode 100644
--- /dev/null
+++ b/dom/presentation/tests/mochitest/test_presentation_sender_default_request.html
@@ -0,0 +1,150 @@
+<!DOCTYPE HTML>
+<html>
+<!-- Any copyright is dedicated to the Public Domain.
+   - http://creativecommons.org/publicdomain/zero/1.0/ -->
+<head>
+  <meta charset="utf-8">
+  <title>Test default request for B2G Presentation API at sender side</title>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test default request for B2G Presentation API at sender side</a>
+<script type="application/javascript;version=1.8">
+
+'use strict';
+
+var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
+var session;
+
+function testSetup() {
+  return new Promise(function(aResolve, aReject) {
+    navigator.presentation.defaultRequest = new PresentationRequest("http://example.com");
+
+    navigator.presentation.defaultRequest.getAvailability().then(
+      function(aAvailability) {
+        aAvailability.onchange = function() {
+          aAvailability.onchange = null;
+          ok(aAvailability.value, "Device should be available.");
+          aResolve();
+        }
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting availability: " + aError);
+        teardown();
+        aReject();
+      }
+    );
+
+    gScript.sendAsyncMessage('trigger-device-add');
+  });
+}
+
+function testStartSession() {
+  return new Promise(function(aResolve, aReject) {
+    gScript.addMessageListener('device-prompt', function devicePromptHandler() {
+      gScript.removeMessageListener('device-prompt', devicePromptHandler);
+      info("Device prompt is triggered.");
+      gScript.sendAsyncMessage('trigger-device-prompt-select');
+    });
+
+    gScript.addMessageListener('control-channel-established', function controlChannelEstablishedHandler() {
+      gScript.removeMessageListener('control-channel-established', controlChannelEstablishedHandler);
+      info("A control channel is established.");
+      gScript.sendAsyncMessage('trigger-control-channel-open');
+    });
+
+    gScript.addMessageListener('control-channel-opened', function controlChannelOpenedHandler(aReason) {
+      gScript.removeMessageListener('control-channel-opened', controlChannelOpenedHandler);
+      info("The control channel is opened.");
+    });
+
+    gScript.addMessageListener('control-channel-closed', function controlChannelClosedHandler(aReason) {
+      gScript.removeMessageListener('control-channel-closed', controlChannelClosedHandler);
+      info("The control channel is closed. " + aReason);
+    });
+
+    gScript.addMessageListener('offer-sent', function offerSentHandler() {
+      gScript.removeMessageListener('offer-sent', offerSentHandler);
+      info("An offer is sent out.");
+      gScript.sendAsyncMessage('trigger-incoming-transport');
+    });
+
+    gScript.addMessageListener('answer-received', function answerReceivedHandler() {
+      gScript.removeMessageListener('answer-received', answerReceivedHandler);
+      info("An answer is received.");
+    });
+
+    gScript.addMessageListener('data-transport-initialized', function dataTransportInitializedHandler() {
+      gScript.removeMessageListener('data-transport-initialized', dataTransportInitializedHandler);
+      info("Data transport channel is initialized.");
+      gScript.sendAsyncMessage('trigger-incoming-answer');
+    });
+
+    navigator.presentation.defaultRequest.onsessionconnect = function(aEvent) {
+      navigator.presentation.defaultRequest.onsessionconnect = null;
+      session = aEvent.session;
+      ok(session, "|sessionconnect| event is fired with a session.");
+      ok(session.id, "Session ID should be set.");
+      is(session.state, "connected", "Session state at sender side should be connected by default.");
+      aResolve();
+    };
+
+    // Simulate the UA triggers |start()| of the default request.
+    navigator.presentation.defaultRequest.start();
+  });
+}
+
+function testCloseSession() {
+  return new Promise(function(aResolve, aReject) {
+    gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
+      gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
+      info("The data transport is closed. " + aReason);
+    });
+
+    session.onstatechange = function() {
+      session.onstatechange = null;
+      is(session.state, "terminated", "Session should be terminated.");
+      aResolve();
+    };
+
+    session.close();
+  });
+}
+
+function teardown() {
+  gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
+    gScript.removeMessageListener('teardown-complete', teardownCompleteHandler);
+    gScript.destroy();
+    SimpleTest.finish();
+  });
+
+  gScript.sendAsyncMessage('teardown');
+}
+
+function runTests() {
+  ok(window.PresentationRequest, "PresentationRequest should be available.");
+  ok(navigator.presentation, "navigator.presentation should be available.");
+
+  testSetup().
+  then(testStartSession).
+  then(testCloseSession).
+  then(teardown);
+}
+
+SimpleTest.expectAssertions(0, 5);
+SimpleTest.waitForExplicitFinish();
+SpecialPowers.pushPermissions([
+  {type: 'presentation-device-manage', allow: false, context: document},
+  {type: 'presentation', allow: true, context: document},
+], function() {
+  SpecialPowers.pushPrefEnv({ 'set': [["dom.presentation.enabled", true],
+                                      ["dom.ignore_webidl_scope_checks", true],
+                                      ["dom.presentation.test.enabled", true],
+                                      ["dom.presentation.test.stage", 0]]},
+                            runTests);
+});
+
+</script>
+</body>
+</html>
--- a/dom/presentation/tests/mochitest/test_presentation_sender_disconnect.html
+++ b/dom/presentation/tests/mochitest/test_presentation_sender_disconnect.html
@@ -10,26 +10,37 @@
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for session disconnection of B2G Presentation API at sender side</a>
 <script type="application/javascript;version=1.8">
 
 'use strict';
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
-var presentation;
+var request;
 var session;
 
 function testSetup() {
   return new Promise(function(aResolve, aReject) {
-    presentation.onavailablechange = function(aIsAvailable) {
-      presentation.onavailablechange = null;
-      ok(aIsAvailable, "Device should be available.");
-      aResolve();
-    };
+    request = new PresentationRequest("http://example.com");
+
+    request.getAvailability().then(
+      function(aAvailability) {
+        aAvailability.onchange = function() {
+          aAvailability.onchange = null;
+          ok(aAvailability.value, "Device should be available.");
+          aResolve();
+        }
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting availability: " + aError);
+        teardown();
+        aReject();
+      }
+    );
 
     gScript.sendAsyncMessage('trigger-device-add');
   });
 }
 
 function testStartSession() {
   return new Promise(function(aResolve, aReject) {
     gScript.addMessageListener('device-prompt', function devicePromptHandler() {
@@ -71,17 +82,17 @@ function testStartSession() {
       info("Data transport channel is initialized.");
     });
 
     gScript.addMessageListener('data-transport-notification-enabled', function dataTransportNotificationEnabledHandler() {
       gScript.removeMessageListener('data-transport-notification-enabled', dataTransportNotificationEnabledHandler);
       info("Data notification is enabled for data transport channel.");
     });
 
-    presentation.startSession("http://example.com").then(
+    request.start().then(
       function(aSession) {
         session = aSession;
         ok(session, "Session should be availlable.");
         ok(session.id, "Session ID should be set.");
         is(session.state, "connected", "Session state at sender side should be connected by default.");
         aResolve();
       },
       function(aError) {
@@ -128,18 +139,17 @@ function teardown() {
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage('teardown');
 }
 
 function runTests() {
-  ok(navigator.presentation, "navigator.presentation should be available.");
-  presentation = navigator.presentation;
+  ok(window.PresentationRequest, "PresentationRequest should be available.");
 
   testSetup().
   then(testStartSession).
   then(testSessionDisconnection).
   then(testCloseSession).
   then(teardown);
 }
 
--- a/dom/presentation/tests/mochitest/test_presentation_sender_start_session_error.html
+++ b/dom/presentation/tests/mochitest/test_presentation_sender_start_session_error.html
@@ -10,60 +10,67 @@
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1069230">Test for startSession errors of B2G Presentation API at sender side</a>
 <script type="application/javascript;version=1.8">
 
 'use strict';
 
 var gScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL('PresentationSessionChromeScript.js'));
-var presentation;
+var request;
 
 function setup() {
   return new Promise(function(aResolve, aReject) {
-    presentation.onavailablechange = function(aIsAvailable) {
-      presentation.onavailablechange = null;
-      ok(aIsAvailable, "Device should be available.");
-      aResolve();
-    };
+    request = new PresentationRequest("http://example.com");
+
+    request.getAvailability().then(
+      function(aAvailability) {
+        aAvailability.onchange = function() {
+          aAvailability.onchange = null;
+          ok(aAvailability.value, "Device should be available.");
+          aResolve();
+        }
+      },
+      function(aError) {
+        ok(false, "Error occurred when getting availability: " + aError);
+        teardown();
+        aReject();
+      }
+    );
 
     gScript.sendAsyncMessage('trigger-device-add');
   });
 }
 
-function testStartSessionNoAvailableDevice() {
+function testCreateRequestWithEmptyURL() {
   return new Promise(function(aResolve, aReject) {
-    presentation.startSession("http://example.com").then(
-      function(aSession) {
-        ok(false, "startSession shouldn't succeed in this case.");
-        aReject();
-      },
-      function(aError) {
-        is(aError.name, "InvalidStateError", "InvalidStateError is expected when starting session.");
-        aResolve();
-      }
-    );
+    try {
+      request = new PresentationRequest("");
+    } catch (aError) {
+      is(aError.name, "SyntaxError", "SyntaxError is expected when using an empty URL.");
+      aResolve();
+    }
   });
 }
 
 function testStartSessionCancelPrompt() {
   return new Promise(function(aResolve, aReject) {
     gScript.addMessageListener('device-prompt', function devicePromptHandler() {
       gScript.removeMessageListener('device-prompt', devicePromptHandler);
       info("Device prompt is triggered.");
       gScript.sendAsyncMessage('trigger-device-prompt-cancel');
     });
 
-    presentation.startSession("http://example.com").then(
+    request.start().then(
       function(aSession) {
-        ok(false, "startSession shouldn't succeed in this case.");
+        ok(false, "|start| shouldn't succeed in this case.");
         aReject();
       },
       function(aError) {
-        is(aError.name, "NS_ERROR_DOM_PROP_ACCESS_DENIED", "NS_ERROR_DOM_PROP_ACCESS_DENIED is expected when starting session.");
+        is(aError.name, "AbortError", "AbortError is expected when the prompt is canceled.");
         aResolve();
       }
     );
   });
 }
 
 function testStartSessionUnexpectedControlChannelCloseBeforeDataTransportInit() {
   return new Promise(function(aResolve, aReject) {
@@ -90,23 +97,23 @@ function testStartSessionUnexpectedContr
     });
 
     gScript.addMessageListener('offer-sent', function offerSentHandler(aIsValid) {
       gScript.removeMessageListener('offer-sent', offerSentHandler);
       ok(aIsValid, "A valid offer is sent out.");
       gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_ERROR_FAILURE);
     });
 
-    presentation.startSession("http://example.com").then(
+    request.start().then(
       function(aSession) {
-        ok(false, "startSession shouldn't succeed in this case.");
+        ok(false, "|start| shouldn't succeed in this case.");
         aReject();
       },
       function(aError) {
-        is(aError.name, "NS_ERROR_FAILURE", "NS_ERROR_FAILURE is expected when starting session.");
+        is(aError.name, "OperationError", "OperationError is expected when a connection error happens during starting session.");
         aResolve();
       }
     );
   });
 }
 
 function testStartSessionUnexpectedControlChannelCloseBeforeDataTransportReady() {
   return new Promise(function(aResolve, aReject) {
@@ -144,23 +151,23 @@ function testStartSessionUnexpectedContr
       gScript.sendAsyncMessage('trigger-control-channel-close', SpecialPowers.Cr.NS_ERROR_ABORT);
     });
 
     gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
       gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
       info("The data transport is closed. " + aReason);
     });
 
-    presentation.startSession("http://example.com").then(
+    request.start().then(
       function(aSession) {
-        ok(false, "startSession shouldn't succeed in this case.");
+        ok(false, "|start| shouldn't succeed in this case.");
         aReject();
       },
       function(aError) {
-        is(aError.name, "NS_ERROR_ABORT", "NS_ERROR_ABORT is expected when starting session.");
+        is(aError.name, "OperationError", "OperationError is expected when a connection error happens during starting session.");
         aResolve();
       }
     );
   });
 }
 
 function testStartSessionUnexpectedDataTransportClose() {
   return new Promise(function(aResolve, aReject) {
@@ -198,23 +205,23 @@ function testStartSessionUnexpectedDataT
       gScript.sendAsyncMessage('trigger-data-transport-close', SpecialPowers.Cr.NS_ERROR_UNEXPECTED);
     });
 
     gScript.addMessageListener('data-transport-closed', function dataTransportClosedHandler(aReason) {
       gScript.removeMessageListener('data-transport-closed', dataTransportClosedHandler);
       info("The data transport is closed. " + aReason);
     });
 
-    presentation.startSession("http://example.com").then(
+    request.start().then(
       function(aSession) {
-        ok(false, "startSession shouldn't succeed in this case.");
+        ok(false, "|start| shouldn't succeed in this case.");
         aReject();
       },
       function(aError) {
-        is(aError.name, "NS_ERROR_UNEXPECTED", "NS_ERROR_UNEXPECTED is expected when starting session.");
+        is(aError.name, "OperationError", "OperationError is expected when a connection error happens during starting session.");
         aResolve();
       }
     );
   });
 }
 
 function teardown() {
   gScript.addMessageListener('teardown-complete', function teardownCompleteHandler() {
@@ -222,20 +229,19 @@ function teardown() {
     gScript.destroy();
     SimpleTest.finish();
   });
 
   gScript.sendAsyncMessage('teardown');
 }
 
 function runTests() {
-  ok(navigator.presentation, "navigator.presentation should be available.");
-  presentation = navigator.presentation;
+  ok(window.PresentationRequest, "PresentationRequest should be available.");
 
-  testStartSessionNoAvailableDevice().
+  testCreateRequestWithEmptyURL().
   then(setup).
   then(testStartSessionCancelPrompt).
   then(testStartSessionUnexpectedControlChannelCloseBeforeDataTransportInit).
   then(testStartSessionUnexpectedControlChannelCloseBeforeDataTransportReady).
   then(testStartSessionUnexpectedDataTransportClose).
   then(teardown);
 }