OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 var tabCapture = chrome.tabCapture; | |
Aaron Boodman
2012/10/16 04:19:27
It would be good to have a test somewhere that you
justinlin
2012/10/17 08:32:26
See previous comment.
| |
6 | |
7 chrome.test.runTests([ | |
8 | |
9 function getTabMediaInvalidTab() { | |
10 var tabMediaRequestCallback = function(stream) { | |
11 chrome.test.assertEq(undefined, stream); | |
12 chrome.test.assertLastError('Could not find the specified tab.'); | |
13 chrome.test.succeed(); | |
14 }; | |
15 | |
16 tabCapture.capture(-1, {audio: true, video: true}, | |
17 tabMediaRequestCallback); | |
18 }, | |
19 | |
20 function getTabMedia() { | |
21 var tabId = -1; | |
22 // Tab capture events in the order they happen. | |
23 var tabCaptureEvents = []; | |
24 | |
25 var tabMediaRequestCallback = function(stream) { | |
26 chrome.test.assertTrue(stream !== undefined); | |
27 stream.stop(); | |
28 }; | |
29 | |
30 var tabCaptureListener = function(info) { | |
31 chrome.test.assertEq(tabId, info.tabId); | |
32 console.log(info.status); | |
33 if (info.status == 'stopped') { | |
34 chrome.test.assertEq('active', tabCaptureEvents.pop()); | |
35 chrome.test.assertEq('pending', tabCaptureEvents.pop()); | |
36 chrome.test.assertEq('requested', tabCaptureEvents.pop()); | |
37 chrome.test.succeed(); | |
38 return; | |
39 } | |
40 tabCaptureEvents.push(info.status); | |
41 } | |
42 | |
43 tabCapture.onStatusChanged.addListener(tabCaptureListener); | |
44 | |
45 var gotTabId = function(tab) { | |
46 tabId = tab[0].id; | |
47 console.log('using tab: ' + tabId); | |
48 tabCapture.capture(tabId, {audio: true, video: true}, | |
49 tabMediaRequestCallback); | |
50 }; | |
51 chrome.tabs.query({active: true}, gotTabId); | |
52 }, | |
53 | |
54 function getCapturedTabs() { | |
55 var tabId = -1; | |
56 var activeStream = null; | |
57 | |
58 var capturedTabsAfterClose = function(infos) { | |
59 chrome.test.assertEq(1, infos.length); | |
60 chrome.test.assertEq(tabId, infos[0].tabId); | |
61 chrome.test.assertEq('stopped', infos[0].status); | |
62 chrome.test.succeed(); | |
63 } | |
64 | |
65 var capturedTabsAfterOpen = function(infos) { | |
66 chrome.test.assertEq(1, infos.length); | |
67 chrome.test.assertEq(tabId, infos[0].tabId); | |
68 chrome.test.assertEq('active', infos[0].status); | |
69 activeStream.stop(); | |
70 } | |
71 | |
72 var tabMediaRequestCallback = function(stream) { | |
73 chrome.test.assertTrue(stream !== undefined); | |
74 activeStream = stream; | |
75 tabCapture.getCapturedTabs(capturedTabsAfterOpen); | |
76 }; | |
77 | |
78 var gotTabId = function(tab) { | |
79 tabId = tab[0].id; | |
80 console.log('using tab: ' + tabId); | |
81 tabCapture.capture(tabId, {audio: true, video: true}, | |
82 tabMediaRequestCallback); | |
83 }; | |
84 chrome.tabs.query({active: true}, gotTabId); | |
85 }, | |
86 | |
87 function captureSameTab() { | |
88 var tabId = -1; | |
89 var stream1 = null; | |
90 | |
91 var tabMediaRequestCallback2 = function(stream) { | |
92 chrome.test.assertLastError( | |
93 'Cannot capture a tab with an active stream.'); | |
94 chrome.test.assertTrue(stream === undefined); | |
95 stream1.stop(); | |
96 chrome.test.succeed(); | |
97 }; | |
98 | |
99 var tabMediaRequestCallback = function(stream) { | |
100 chrome.test.assertTrue(stream !== undefined); | |
101 stream1 = stream; | |
102 tabCapture.capture(tabId, {audio: true, video: true}, | |
103 tabMediaRequestCallback2); | |
104 }; | |
105 | |
106 var gotTabId = function(tab) { | |
107 tabId = tab[0].id; | |
108 console.log('using tab: ' + tabId); | |
109 tabCapture.capture(tabId, {audio: true, video: true}, | |
110 tabMediaRequestCallback); | |
111 }; | |
112 chrome.tabs.query({active: true}, gotTabId); | |
113 }, | |
114 | |
115 ]); | |
OLD | NEW |