startNewPresentation_success-manual.https.html (4362B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>Checking the chain of events when starting a new presentation</title> 4 <link rel="author" title="Marius Wessel" href="http://www.fokus.fraunhofer.de"> 5 <link rel="author" title="Tomoyuki Shimizu" href="https://github.com/tomoyukilabs"> 6 <link rel="help" href="http://w3c.github.io/presentation-api/#dfn-controlling-user-agent"> 7 <script src="/resources/testharness.js"></script> 8 <script src="/resources/testharnessreport.js"></script> 9 <script src="common.js"></script> 10 11 <p>Click the button below and select the available presentation display, to start the manual test.</p> 12 <button id="presentBtn">Start Presentation Test</button> 13 14 15 <script> 16 // description of event order 17 var description = [ 18 "Phase #1: Promise is resolved", 19 "Phase #2: 'connectionavailable' event fired", 20 "Phase #3: 'connect' event fired" 21 ]; 22 var step = 0; 23 24 // presentation connection 25 var connection; 26 27 // disable the timeout function for the tests 28 setup({explicit_timeout: true}); 29 30 // ---------- 31 // DOM Object 32 // ---------- 33 var presentBtn = document.getElementById("presentBtn"); 34 35 // --------------------------------------------- 36 // Start New Presentation Test (success) - begin 37 // --------------------------------------------- 38 presentBtn.onclick = function () { 39 presentBtn.disabled = true; 40 promise_test(function (t) { 41 var phase = -1, actual = -1; 42 43 // increment the count in the actual event order 44 var count = function(evt) { actual++; return evt; }; 45 // increment the count in the expected event order and compare it with the actual event order 46 var checkPhase = function(evt) { phase++; assert_equals(description[actual], description[phase], 'Event order is incorrect.'); return evt; }; 47 48 var request = new PresentationRequest(presentationUrls); 49 var eventWatcher = new EventWatcher(t, request, 'connectionavailable'); 50 var waitConnectionavailable = eventWatcher.wait_for('connectionavailable').then(count).then(function(evt) { connection = connection || evt.connection; return evt; }); 51 var waitConnect; 52 53 t.add_cleanup(function() { 54 if(connection) 55 connection.terminate(); 56 }); 57 58 return request.start().then(count) 59 .then(checkPhase).then(function (c) { 60 // Phase #1: Promise is resolved 61 connection = c; 62 63 // No more user input needed, re-enable timeout 64 t.step_timeout(function() { 65 t.force_timeout(); 66 t.done(); 67 }, 5000); 68 69 // Check the initial state of the presentation connection 70 assert_equals(connection.state, 'connecting', 'Check the initial state of the presentation connection.'); 71 assert_true(!!connection.id, 'The connection ID is set.'); 72 assert_equals(typeof connection.id, 'string', 'The connection ID is a string.'); 73 assert_true(connection instanceof PresentationConnection, 'The connection is an instance of PresentationConnection.'); 74 75 var eventWatcher = new EventWatcher(t, connection, 'connect'); 76 waitConnect = eventWatcher.wait_for('connect').then(count); 77 78 return waitConnectionavailable; 79 }) 80 .then(checkPhase).then(function (evt) { 81 // Phase #2: "connectionavailable" event fired 82 assert_equals(connection, evt.connection, 'Both Promise from PresentationRequest() and a "connectionavailable" event handler receive the same presentation connection.'); 83 84 return waitConnect; 85 }) 86 .then(checkPhase).then(function () { 87 // Phase #3: "connect" event fired 88 assert_equals(connection.state, 'connected', 'The state of the presentation connection is "connected" when a "connect" event fires.'); 89 }); 90 }); 91 } 92 // ------------------------------------------- 93 // Start New Presentation Test (success) - end 94 // ------------------------------------------- 95 </script>