| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <body> | 3 <body> |
| 4 <script> | 4 <script> |
| 5 | 5 |
| 6 var FAKE_SESSION_ID = 'fake'; | 6 const FAKE_SESSION_ID = 'fake'; |
| 7 var gCurrentConnection = null; | 7 let gCurrentConnection = null; |
| 8 | 8 |
| 9 // Returns the test runner used to run this test.. | 9 // Returns the test runner used to run this test.. |
| 10 // Current possible values are 'blink' and 'manual'. | 10 // Current possible values are 'blink' and 'manual'. |
| 11 function getTestRunner() { | 11 function getTestRunner() { |
| 12 if ('internals' in window) | 12 if ('internals' in window) |
| 13 return 'blink'; | 13 return 'blink'; |
| 14 return 'manual'; | 14 return 'manual'; |
| 15 } | 15 } |
| 16 | 16 |
| 17 // Returns a promise that is resolved when the user press a 'click me' button or | 17 // Returns a promise that is resolved when the user press a 'click me' button or |
| 18 // is automatically resolved if a supported test runner is detected. | 18 // is automatically resolved if a supported test runner is detected. |
| 19 function getUserGesture() { | 19 function getUserGesture() { |
| 20 return new Promise(function (resolve) { | 20 return new Promise(function (resolve) { |
| 21 switch (getTestRunner()) { | 21 switch (getTestRunner()) { |
| 22 case 'blink': | 22 case 'blink': |
| 23 internals.settings.setPresentationRequiresUserGesture(false); | 23 internals.settings.setPresentationRequiresUserGesture(false); |
| 24 setTimeout(resolve); | 24 setTimeout(resolve); |
| 25 break; | 25 break; |
| 26 case 'manual': | 26 case 'manual': |
| 27 var button = document.createElement('button'); | 27 const button = document.createElement('button'); |
| 28 button.textContent = 'click me'; | 28 button.textContent = 'click me'; |
| 29 button.onclick = function() { | 29 button.onclick = function() { |
| 30 document.body.removeChild(button); | 30 document.body.removeChild(button); |
| 31 resolve(); | 31 resolve(); |
| 32 }; | 32 }; |
| 33 document.body.appendChild(button); | 33 document.body.appendChild(button); |
| 34 break; | 34 break; |
| 35 default: | 35 default: |
| 36 parent.window.postMessage({ error: 'unknown test runner' }, '*'); | 36 parent.window.postMessage({ error: 'unknown test runner' }, '*'); |
| 37 } | 37 } |
| 38 }); | 38 }); |
| 39 } | 39 } |
| 40 | 40 |
| 41 var results = []; | 41 const results = []; |
| 42 | 42 |
| 43 // start() | 43 // start() |
| 44 getUserGesture().then(function() { | 44 getUserGesture().then(function() { |
| 45 if (getTestRunner() == 'manual') { | 45 if (getTestRunner() == 'manual') { |
| 46 var description = document.createElement('div'); | 46 const description = document.createElement('div'); |
| 47 description.id = 'description'; | 47 description.id = 'description'; |
| 48 description.textContent = 'Pick a device if asked for it'; | 48 description.textContent = 'Pick a device if asked for it'; |
| 49 document.body.appendChild(description); | 49 document.body.appendChild(description); |
| 50 } | 50 } |
| 51 | 51 |
| 52 var p = new PresentationRequest('https://example.com'); | 52 const p = new PresentationRequest('https://example.com'); |
| 53 return p.start().then(function(connection) { | 53 return p.start().then(function(connection) { |
| 54 gCurrentConnection = connection; | 54 gCurrentConnection = connection; |
| 55 results.push({ test: 'start', status: 'success' }) | 55 results.push({ test: 'start', status: 'success' }) |
| 56 }, function(e) { | 56 }, function(e) { |
| 57 results.push({ test: 'start', status: 'failure', name: e.name }); | 57 results.push({ test: 'start', status: 'failure', name: e.name }); |
| 58 }).then(function() { | 58 }).then(function() { |
| 59 if (getTestRunner() == 'manual') | 59 if (getTestRunner() == 'manual') |
| 60 document.body.removeChild(document.querySelector('#description')); | 60 document.body.removeChild(document.querySelector('#description')); |
| 61 }); | 61 }); |
| 62 }).then(function() { | 62 }).then(function() { |
| 63 // reconnect() | 63 // reconnect() |
| 64 return getUserGesture().then(function() { | 64 return getUserGesture().then(function() { |
| 65 var p = new PresentationRequest('https://example.com'); | 65 const p = new PresentationRequest('https://example.com'); |
| 66 return p.reconnect(gCurrentConnection ? gCurrentConnection.id : FAKE_SESSION
_ID).then(function() { | 66 return p.reconnect(gCurrentConnection ? |
| 67 gCurrentConnection.id : |
| 68 FAKE_SESSION_ID).then(function() { |
| 67 results.push({ test: 'reconnect', status: 'success' }) | 69 results.push({ test: 'reconnect', status: 'success' }) |
| 68 }, function(e) { | 70 }, function(e) { |
| 69 results.push({ test: 'reconnect', status: 'failure', name: e.name }); | 71 results.push({ test: 'reconnect', status: 'failure', name: e.name }); |
| 70 }); | 72 }); |
| 71 }); | 73 }); |
| 72 }).then(function() { | 74 }).then(function() { |
| 73 // getAvailability() | 75 // getAvailability() |
| 74 return getUserGesture().then(function() { | 76 return getUserGesture().then(function() { |
| 75 var p = new PresentationRequest('https://example.com'); | 77 const p = new PresentationRequest('https://example.com'); |
| 76 return p.getAvailability().then(function() { | 78 return p.getAvailability().then(function() { |
| 77 results.push({ test: 'getAvailability', status: 'success' }) | 79 results.push({ test: 'getAvailability', status: 'success' }) |
| 78 }, function(e) { | 80 }, function(e) { |
| 79 results.push({ test: 'getAvailability', status: 'failure', name: e.name })
; | 81 results.push({ test: 'getAvailability', status: 'failure', name: e.name })
; |
| 80 }); | 82 }); |
| 81 }); | 83 }); |
| 82 }).then(function() { | 84 }).then(function() { |
| 83 parent.window.postMessage(results, '*'); | 85 parent.window.postMessage(results, '*'); |
| 84 }); | 86 }); |
| 85 | 87 |
| 86 </script> | 88 </script> |
| 87 </body> | 89 </body> |
| 88 </html> | 90 </html> |
| OLD | NEW |