| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 window.addEventListener('load', () => { | 5 window.addEventListener('load', function() { |
| 6 // Register the fullscreen change listener. This is used to determine when to | 6 document.body.onclick = function toggleBodyFullscreen() { |
| 7 // signal the C++ side of this test that the document has entered/exited | |
| 8 // fullscreen. NOTE: It's very important NOT to use the | |
| 9 // tabCapture.onStatusChanged listener to signal the C++ side of this test | |
| 10 // because sometimes the document's fullscreen state change lags behind what | |
| 11 // the tabCapture API knows about the browser window's fullscreen state. | |
| 12 // Otherwise, the C++ side of this test might proceed out-of-sync and fail. | |
| 13 // http://crbug.com/675851 | |
| 14 if (document.fullscreenEnabled) { | |
| 15 document.onfullscreenchange = () => { | |
| 16 if (document.fullscreenElement) | |
| 17 chrome.test.sendMessage('entered_fullscreen'); | |
| 18 }; | |
| 19 } else if (document.webkitFullscreenEnabled) { | |
| 20 document.onwebkitfullscreenchange = () => { | |
| 21 if (document.webkitFullscreenElement) | |
| 22 chrome.test.sendMessage('entered_fullscreen'); | |
| 23 }; | |
| 24 } else { | |
| 25 chrome.test.assertTrue(!'HTML5 Fullscreen API missing'); | |
| 26 } | |
| 27 | |
| 28 // Register an onclick listener that toggles the entire document into or | |
| 29 // out-of fullscreen mode. The clicks are generated by the C++ side of this | |
| 30 // test. | |
| 31 document.documentElement.onclick = () => { | |
| 32 if (document.fullscreenElement || document.webkitFullscreenElement) { | 7 if (document.fullscreenElement || document.webkitFullscreenElement) { |
| 33 if (document.exitFullscreen) | 8 if (document.exitFullscreen) |
| 34 document.exitFullscreen(); | 9 document.exitFullscreen(); |
| 35 else if (document.webkitExitFullscreen) | 10 else if (document.webkitExitFullscreen) |
| 36 document.webkitExitFullscreen(); | 11 document.webkitExitFullscreen(); |
| 37 else | 12 else |
| 38 chrome.test.assertTrue(!'HTML5 Fullscreen API missing'); | 13 chrome.test.assertTrue(!"HTML5 Fullscreen API missing"); |
| 39 } else { | 14 } else { |
| 40 if (document.documentElement.requestFullscreen) | 15 if (document.body.requestFullscreen) |
| 41 document.documentElement.requestFullscreen(); | 16 document.body.requestFullscreen(); |
| 42 else if (document.documentElement.webkitRequestFullscreen) | 17 else if (document.body.webkitRequestFullscreen) |
| 43 document.documentElement.webkitRequestFullscreen(); | 18 document.body.webkitRequestFullscreen(); |
| 44 else | 19 else |
| 45 chrome.test.assertTrue(!'HTML5 Fullscreen API missing'); | 20 chrome.test.assertTrue(!"HTML5 Fullscreen API missing"); |
| 46 } | 21 } |
| 47 }; | 22 }; |
| 23 }); |
| 48 | 24 |
| 49 let mediaStream = null; | 25 var mediaStream = null; |
| 50 const events = []; | 26 var events = []; |
| 51 | 27 |
| 52 // Register the tab capture status change listener, which records the changes | 28 chrome.tabCapture.onStatusChanged.addListener(function(info) { |
| 53 // to fullscreen state according to the tab capture API implementation. Once | 29 if (info.status == 'active') { |
| 54 // there are three changes, check the results and succeed() the test. | 30 events.push(info.fullscreen); |
| 55 chrome.tabCapture.onStatusChanged.addListener(info => { | 31 if (events.length == 3) { |
| 56 if (info.status == 'active') { | 32 chrome.test.assertFalse(events[0]); |
| 57 events.push(info.fullscreen); | 33 chrome.test.assertTrue(events[1]); |
| 58 if (events.length == 3) { | 34 chrome.test.assertFalse(events[2]); |
| 59 mediaStream.getVideoTracks()[0].stop(); | 35 mediaStream.getVideoTracks()[0].stop(); |
| 60 mediaStream.getAudioTracks()[0].stop(); | 36 mediaStream.getAudioTracks()[0].stop(); |
| 61 chrome.test.assertFalse(events[0]); | 37 chrome.test.succeed(); |
| 62 chrome.test.assertTrue(events[1]); | |
| 63 chrome.test.assertFalse(events[2]); | |
| 64 chrome.test.succeed(); | |
| 65 } | |
| 66 } | 38 } |
| 67 }); | |
| 68 | 39 |
| 69 // Now that all listeners are in-place, start tab capture. Once tab capture is | 40 if (info.fullscreen) |
| 70 // running, notify the C++ side of this test that it may commence with the | 41 chrome.test.sendMessage('entered_fullscreen'); |
| 71 // "fullscreen toggle mouse clicks." | 42 } |
| 72 chrome.tabCapture.capture({audio: true, video: true}, stream => { | |
| 73 chrome.test.assertTrue(!!stream); | |
| 74 mediaStream = stream; | |
| 75 chrome.test.notifyPass(); | |
| 76 chrome.test.sendMessage('tab_capture_started'); | |
| 77 }); | |
| 78 }); | 43 }); |
| 44 |
| 45 chrome.tabCapture.capture({audio: true, video: true}, function(stream) { |
| 46 chrome.test.assertTrue(!!stream); |
| 47 mediaStream = stream; |
| 48 chrome.test.notifyPass(); |
| 49 chrome.test.sendMessage('tab_capture_started'); |
| 50 }); |
| OLD | NEW |