Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/test/data/extensions/api_test/tab_capture/api_tests.js

Issue 1221483002: New tabCapture.captureOffscreenTab API, initially for Presentation API 1UA mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Register off-screen tabs as presentations via separate private API. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 var tabCapturePrivate = chrome.tabCapturePrivate;
7
8 var helloWorldPageUri = 'data:text/html;charset=UTF-8,' +
9 encodeURIComponent('<html><body>Hello world!</body></html>');
10
11 function assertIsSameSetOfTabs(list_a, list_b, id_field_name) {
12 chrome.test.assertEq(list_a.length, list_b.length);
13 function tabIdSortFunction(a, b) {
14 return (a[id_field_name] || 0) - (b[id_field_name] || 0);
15 }
16 list_a.sort(tabIdSortFunction);
17 list_b.sort(tabIdSortFunction);
18 for (var i = 0, end = list_a.length; i < end; ++i) {
19 chrome.test.assertEq(list_a[i][id_field_name], list_b[i][id_field_name]);
20 }
21 }
6 22
7 chrome.test.runTests([ 23 chrome.test.runTests([
8 function captureTabAndVerifyStateTransitions() { 24 function captureTabAndVerifyStateTransitions() {
9 // Tab capture events in the order they happen. 25 // Tab capture events in the order they happen.
10 var tabCaptureEvents = []; 26 var tabCaptureEvents = [];
11 27
12 var tabCaptureListener = function(info) { 28 var tabCaptureListener = function(info) {
13 console.log(info.status); 29 console.log(info.status);
14 if (info.status == 'stopped') { 30 if (info.status == 'stopped') {
15 chrome.test.assertEq('active', tabCaptureEvents.pop()); 31 chrome.test.assertEq('active', tabCaptureEvents.pop());
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 chrome.test.succeed(); 153 chrome.test.succeed();
138 }); 154 });
139 }, 155 },
140 156
141 function noAudioOrVideoRequested() { 157 function noAudioOrVideoRequested() {
142 // If not specified, video is not requested. 158 // If not specified, video is not requested.
143 tabCapture.capture({audio: false}, function(stream) { 159 tabCapture.capture({audio: false}, function(stream) {
144 chrome.test.assertTrue(!stream); 160 chrome.test.assertTrue(!stream);
145 chrome.test.succeed(); 161 chrome.test.succeed();
146 }); 162 });
163 },
164
165 function offscreenTabsDoNotShowUpAsCapturedTabs() {
166 tabCapture.getCapturedTabs(function(tab_list_before) {
167 tabCapture.captureOffscreenTab(
168 helloWorldPageUri,
169 {video: true},
170 function(stream) {
171 chrome.test.assertTrue(!!stream);
172 tabCapture.getCapturedTabs(function(tab_list_after) {
173 assertIsSameSetOfTabs(tab_list_before, tab_list_after, 'tabId');
174 stream.getVideoTracks()[0].stop();
175 chrome.test.succeed();
176 });
177 });
178 });
179 },
180
181 function offscreenTabsDoNotShowUpInTabsQuery() {
182 chrome.tabs.query({/* all tabs */}, function(tab_list_before) {
183 tabCapture.captureOffscreenTab(
184 helloWorldPageUri,
185 {video: true},
186 function(stream) {
187 chrome.test.assertTrue(!!stream);
188 chrome.tabs.query({/* all tabs */}, function(tab_list_after) {
189 assertIsSameSetOfTabs(tab_list_before, tab_list_after, 'id');
190 stream.getVideoTracks()[0].stop();
191 chrome.test.succeed();
192 });
193 });
194 });
195 },
196
197 function canRegisterOffscreenTabsAsPresentations() {
198 tabCapture.captureOffscreenTab(
199 helloWorldPageUri,
200 {video: true},
201 function(stream) {
202 chrome.test.assertTrue(!!stream);
203 chrome.test.assertTrue((stream['offscreenTabId'] || '').length > 0);
204 tabCapturePrivate.registerOffscreenTabAsPresentation(
205 stream['offscreenTabId'],
206 '<PRESENTATION ID>',
207 function() {
208 var error = chrome.runtime.lastError;
209 if (error) {
210 if (error.message) {
211 console.error(error.message);
212 }
213 chrome.test.fail();
214 } else {
215 chrome.test.succeed();
216 }
217 }
218 );
219 }
220 );
147 } 221 }
148 ]); 222 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698