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 var tabCapture = chrome.tabCapture; | 5 var tabCapture = chrome.tabCapture; |
6 | 6 |
7 chrome.test.runTests([ | 7 chrome.test.runTests([ |
8 function captureTabAndVerifyStateTransitions() { | 8 function captureTabAndVerifyStateTransitions() { |
9 // Tab capture events in the order they happen. | 9 // Tab capture events in the order they happen. |
10 var tabCaptureEvents = []; | 10 var tabCaptureEvents = []; |
11 | 11 |
12 var tabCaptureListener = function(info) { | 12 var tabCaptureListener = function(info) { |
13 console.log(info.status); | 13 console.log(info.status); |
14 if (info.status == 'stopped') { | 14 if (info.status == 'stopped') { |
15 chrome.test.assertEq('active', tabCaptureEvents.pop()); | 15 chrome.test.assertEq('active', tabCaptureEvents.pop()); |
16 chrome.test.assertEq('pending', tabCaptureEvents.pop()); | 16 chrome.test.assertEq('pending', tabCaptureEvents.pop()); |
17 tabCapture.onStatusChanged.removeListener(tabCaptureListener); | 17 tabCapture.onStatusChanged.removeListener(tabCaptureListener); |
18 chrome.test.succeed(); | 18 chrome.test.succeed(); |
19 return; | 19 return; |
20 } | 20 } |
21 tabCaptureEvents.push(info.status); | 21 tabCaptureEvents.push(info.status); |
22 }; | 22 }; |
23 tabCapture.onStatusChanged.addListener(tabCaptureListener); | 23 tabCapture.onStatusChanged.addListener(tabCaptureListener); |
24 | 24 |
25 tabCapture.capture({audio: true, video: true}, function(stream) { | 25 tabCapture.capture({audio: true, video: true}, function(stream) { |
26 chrome.test.assertTrue(!!stream); | 26 chrome.test.assertTrue(!!stream); |
27 stream.stop(); | 27 stream.getVideoTracks()[0].stop(); |
| 28 stream.getAudioTracks()[0].stop(); |
28 }); | 29 }); |
29 }, | 30 }, |
30 | 31 |
31 function getCapturedTabs() { | 32 function getCapturedTabs() { |
32 chrome.tabs.create({active: true}, function(secondTab) { | 33 chrome.tabs.create({active: true}, function(secondTab) { |
33 // chrome.tabCapture.capture() will only capture the active tab. | 34 // chrome.tabCapture.capture() will only capture the active tab. |
34 chrome.test.assertTrue(secondTab.active); | 35 chrome.test.assertTrue(secondTab.active); |
35 | 36 |
36 function checkInfoForSecondTabHasStatus(infos, status) { | 37 function checkInfoForSecondTabHasStatus(infos, status) { |
37 for (var i = 0; i < infos.length; ++i) { | 38 for (var i = 0; i < infos.length; ++i) { |
(...skipping 21 matching lines...) Expand all Loading... |
59 // returns 'stopped' capturing status for the second tab. | 60 // returns 'stopped' capturing status for the second tab. |
60 var capturedTabsAfterStopCapture = function(infos) { | 61 var capturedTabsAfterStopCapture = function(infos) { |
61 checkInfoForSecondTabHasStatus(infos, 'stopped'); | 62 checkInfoForSecondTabHasStatus(infos, 'stopped'); |
62 chrome.tabs.remove(secondTab.id); | 63 chrome.tabs.remove(secondTab.id); |
63 }; | 64 }; |
64 | 65 |
65 // Step 2: After the stream is started, check that getCapturedTabs() | 66 // Step 2: After the stream is started, check that getCapturedTabs() |
66 // returns 'active' capturing status for the second tab. | 67 // returns 'active' capturing status for the second tab. |
67 var capturedTabsAfterStartCapture = function(infos) { | 68 var capturedTabsAfterStartCapture = function(infos) { |
68 checkInfoForSecondTabHasStatus(infos, 'active'); | 69 checkInfoForSecondTabHasStatus(infos, 'active'); |
69 activeStream.stop(); | 70 activeStream.getVideoTracks()[0].stop(); |
| 71 activeStream.getAudioTracks()[0].stop(); |
70 tabCapture.getCapturedTabs(capturedTabsAfterStopCapture); | 72 tabCapture.getCapturedTabs(capturedTabsAfterStopCapture); |
71 }; | 73 }; |
72 | 74 |
73 // Step 1: Start capturing the second tab (the currently active tab). | 75 // Step 1: Start capturing the second tab (the currently active tab). |
74 tabCapture.capture({audio: true, video: true}, function(stream) { | 76 tabCapture.capture({audio: true, video: true}, function(stream) { |
75 chrome.test.assertTrue(!!stream); | 77 chrome.test.assertTrue(!!stream); |
76 activeStream = stream; | 78 activeStream = stream; |
77 tabCapture.getCapturedTabs(capturedTabsAfterStartCapture); | 79 tabCapture.getCapturedTabs(capturedTabsAfterStartCapture); |
78 }); | 80 }); |
79 }); | 81 }); |
80 }, | 82 }, |
81 | 83 |
82 function captureSameTab() { | 84 function captureSameTab() { |
83 var stream1 = null; | 85 var stream1 = null; |
84 | 86 |
85 var tabMediaRequestCallback2 = function(stream) { | 87 var tabMediaRequestCallback2 = function(stream) { |
86 chrome.test.assertLastError( | 88 chrome.test.assertLastError( |
87 'Cannot capture a tab with an active stream.'); | 89 'Cannot capture a tab with an active stream.'); |
88 chrome.test.assertTrue(!stream); | 90 chrome.test.assertTrue(!stream); |
89 stream1.stop(); | 91 stream1.getVideoTracks()[0].stop(); |
| 92 stream1.getAudioTracks()[0].stop(); |
90 chrome.test.succeed(); | 93 chrome.test.succeed(); |
91 }; | 94 }; |
92 | 95 |
93 tabCapture.capture({audio: true, video: true}, function(stream) { | 96 tabCapture.capture({audio: true, video: true}, function(stream) { |
94 chrome.test.assertTrue(!!stream); | 97 chrome.test.assertTrue(!!stream); |
95 stream1 = stream; | 98 stream1 = stream; |
96 tabCapture.capture({audio: true, video: true}, tabMediaRequestCallback2); | 99 tabCapture.capture({audio: true, video: true}, tabMediaRequestCallback2); |
97 }); | 100 }); |
98 }, | 101 }, |
99 | 102 |
100 function tabIsUnmutedWhenTabCaptured() { | 103 function tabIsUnmutedWhenTabCaptured() { |
101 var stream1 = null; | 104 var stream1 = null; |
102 | 105 |
103 chrome.tabs.getCurrent(function(tab) { | 106 chrome.tabs.getCurrent(function(tab) { |
104 var stopListener = chrome.test.listenForever(chrome.tabs.onUpdated, | 107 var stopListener = chrome.test.listenForever(chrome.tabs.onUpdated, |
105 function(tabId, changeInfo, updatedTab) { | 108 function(tabId, changeInfo, updatedTab) { |
106 if ((changeInfo.mutedInfo.muted === true)) { | 109 if ((changeInfo.mutedInfo.muted === true)) { |
107 tabCapture.capture({audio: true}, function(stream) { | 110 tabCapture.capture({audio: true}, function(stream) { |
108 stream1 = stream; | 111 stream1 = stream; |
109 }); | 112 }); |
110 } | 113 } |
111 else if ((changeInfo.mutedInfo.reason == "capture") && | 114 else if ((changeInfo.mutedInfo.reason == "capture") && |
112 (changeInfo.mutedInfo.muted === false)) { | 115 (changeInfo.mutedInfo.muted === false)) { |
113 stream1.stop(); | 116 stream1.getAudioTracks()[0].stop(); |
114 stopListener(); | 117 stopListener(); |
115 } | 118 } |
116 }); | 119 }); |
117 | 120 |
118 chrome.tabs.update(tab.id, {muted: true}); | 121 chrome.tabs.update(tab.id, {muted: true}); |
119 }); | 122 }); |
120 }, | 123 }, |
121 | 124 |
122 function onlyVideo() { | 125 function onlyVideo() { |
123 tabCapture.capture({video: true}, function(stream) { | 126 tabCapture.capture({video: true}, function(stream) { |
124 chrome.test.assertTrue(!!stream); | 127 chrome.test.assertTrue(!!stream); |
125 stream.stop(); | 128 stream.getVideoTracks()[0].stop(); |
126 chrome.test.succeed(); | 129 chrome.test.succeed(); |
127 }); | 130 }); |
128 }, | 131 }, |
129 | 132 |
130 function onlyAudio() { | 133 function onlyAudio() { |
131 tabCapture.capture({audio: true}, function(stream) { | 134 tabCapture.capture({audio: true}, function(stream) { |
132 chrome.test.assertTrue(!!stream); | 135 chrome.test.assertTrue(!!stream); |
133 stream.stop(); | 136 stream.getAudioTracks()[0].stop(); |
134 chrome.test.succeed(); | 137 chrome.test.succeed(); |
135 }); | 138 }); |
136 }, | 139 }, |
137 | 140 |
138 function noAudioOrVideoRequested() { | 141 function noAudioOrVideoRequested() { |
139 // If not specified, video is not requested. | 142 // If not specified, video is not requested. |
140 tabCapture.capture({audio: false}, function(stream) { | 143 tabCapture.capture({audio: false}, function(stream) { |
141 chrome.test.assertTrue(!stream); | 144 chrome.test.assertTrue(!stream); |
142 chrome.test.succeed(); | 145 chrome.test.succeed(); |
143 }); | 146 }); |
144 } | 147 } |
145 ]); | 148 ]); |
OLD | NEW |