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 = []; |
(...skipping 11 matching lines...) Expand all Loading... |
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.stop(); |
28 }); | 28 }); |
29 }, | 29 }, |
30 | 30 |
31 function getCapturedTabs() { | 31 function getCapturedTabs() { |
32 var activeStream = null; | 32 chrome.tabs.create({active:true}, function(secondTab) { |
| 33 // chrome.tabCapture.capture() will only capture the active tab. |
| 34 chrome.test.assertTrue(secondTab.active); |
33 | 35 |
34 var capturedTabsAfterClose = function(infos) { | 36 function checkInfoForSecondTabHasStatus(infos, status) { |
35 chrome.test.assertEq(1, infos.length); | 37 for (var i = 0; i < infos.length; ++i) { |
36 chrome.test.assertEq('stopped', infos[0].status); | 38 if (infos[i].tabId == secondTab) { |
37 chrome.test.succeed(); | 39 chrome.test.assertNe(null, status); |
38 }; | 40 chrome.test.assertEq(status, infos[i].status); |
| 41 chrome.test.assertEq(false, infos[i].fullscreen); |
| 42 return; |
| 43 } |
| 44 } |
| 45 } |
39 | 46 |
40 var capturedTabsAfterOpen = function(infos) { | 47 // Step 4: After the second tab is closed, check that getCapturedTabs() |
41 chrome.test.assertEq(1, infos.length); | 48 // returns no info at all about the second tab. http://crbug.com/338445 |
42 chrome.test.assertEq('active', infos[0].status); | 49 chrome.tabs.onRemoved.addListener(function() { |
43 activeStream.stop(); | 50 tabCapture.getCapturedTabs(function checkNoInfos(infos) { |
44 tabCapture.getCapturedTabs(capturedTabsAfterClose); | 51 checkInfoForSecondTabHasStatus(infos, null); |
45 }; | 52 chrome.test.succeed(); |
| 53 }); |
| 54 }); |
46 | 55 |
47 tabCapture.capture({audio: true, video: true}, function(stream) { | 56 var activeStream = null; |
48 chrome.test.assertTrue(!!stream); | 57 |
49 activeStream = stream; | 58 // Step 3: After the stream is stopped, check that getCapturedTabs() |
50 tabCapture.getCapturedTabs(capturedTabsAfterOpen); | 59 // returns 'stopped' capturing status for the second tab. |
| 60 var capturedTabsAfterStopCapture = function(infos) { |
| 61 checkInfoForSecondTabHasStatus(infos, 'stopped'); |
| 62 chrome.tabs.remove(secondTab.id); |
| 63 }; |
| 64 |
| 65 // Step 2: After the stream is started, check that getCapturedTabs() |
| 66 // returns 'active' capturing status for the second tab. |
| 67 var capturedTabsAfterStartCapture = function(infos) { |
| 68 checkInfoForSecondTabHasStatus(infos, 'active'); |
| 69 activeStream.stop(); |
| 70 tabCapture.getCapturedTabs(capturedTabsAfterStopCapture); |
| 71 }; |
| 72 |
| 73 // Step 1: Start capturing the second tab (the currently active tab). |
| 74 tabCapture.capture({audio: true, video: true}, function(stream) { |
| 75 chrome.test.assertTrue(!!stream); |
| 76 activeStream = stream; |
| 77 tabCapture.getCapturedTabs(capturedTabsAfterStartCapture); |
| 78 }); |
51 }); | 79 }); |
52 }, | 80 }, |
53 | 81 |
54 function captureSameTab() { | 82 function captureSameTab() { |
55 var stream1 = null; | 83 var stream1 = null; |
56 | 84 |
57 var tabMediaRequestCallback2 = function(stream) { | 85 var tabMediaRequestCallback2 = function(stream) { |
58 chrome.test.assertLastError( | 86 chrome.test.assertLastError( |
59 'Cannot capture a tab with an active stream.'); | 87 'Cannot capture a tab with an active stream.'); |
60 chrome.test.assertTrue(!stream); | 88 chrome.test.assertTrue(!stream); |
(...skipping 18 matching lines...) Expand all Loading... |
79 | 107 |
80 function noAudioOrVideoRequested() { | 108 function noAudioOrVideoRequested() { |
81 // If not specified, video is not requested. | 109 // If not specified, video is not requested. |
82 tabCapture.capture({audio: false}, function(stream) { | 110 tabCapture.capture({audio: false}, function(stream) { |
83 chrome.test.assertTrue(!stream); | 111 chrome.test.assertTrue(!stream); |
84 chrome.test.succeed(); | 112 chrome.test.succeed(); |
85 }); | 113 }); |
86 } | 114 } |
87 | 115 |
88 ]); | 116 ]); |
OLD | NEW |