[Cronet] Delay StartNetLog and StopNetLog until native request context is initialized
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / tab_capture / api_tests.js
blob8f3e1d168ffaf9d2717c2d1ad3448292348cdd90
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
3 // found in the LICENSE file.
5 var tabCapture = chrome.tabCapture;
7 chrome.test.runTests([
8 function captureTabAndVerifyStateTransitions() {
9 // Tab capture events in the order they happen.
10 var tabCaptureEvents = [];
12 var tabCaptureListener = function(info) {
13 console.log(info.status);
14 if (info.status == 'stopped') {
15 chrome.test.assertEq('active', tabCaptureEvents.pop());
16 chrome.test.assertEq('pending', tabCaptureEvents.pop());
17 tabCapture.onStatusChanged.removeListener(tabCaptureListener);
18 chrome.test.succeed();
19 return;
21 tabCaptureEvents.push(info.status);
23 tabCapture.onStatusChanged.addListener(tabCaptureListener);
25 tabCapture.capture({audio: true, video: true}, function(stream) {
26 chrome.test.assertTrue(!!stream);
27 stream.stop();
28 });
31 function getCapturedTabs() {
32 chrome.tabs.create({active:true}, function(secondTab) {
33 // chrome.tabCapture.capture() will only capture the active tab.
34 chrome.test.assertTrue(secondTab.active);
36 function checkInfoForSecondTabHasStatus(infos, status) {
37 for (var i = 0; i < infos.length; ++i) {
38 if (infos[i].tabId == secondTab) {
39 chrome.test.assertNe(null, status);
40 chrome.test.assertEq(status, infos[i].status);
41 chrome.test.assertEq(false, infos[i].fullscreen);
42 return;
47 // Step 4: After the second tab is closed, check that getCapturedTabs()
48 // returns no info at all about the second tab.
49 chrome.tabs.onRemoved.addListener(function() {
50 tabCapture.getCapturedTabs(function checkNoInfos(infos) {
51 checkInfoForSecondTabHasStatus(infos, null);
52 chrome.test.succeed();
53 });
54 });
56 var activeStream = null;
58 // Step 3: After the stream is stopped, check that getCapturedTabs()
59 // returns 'stopped' capturing status for the second tab.
60 var capturedTabsAfterStopCapture = function(infos) {
61 checkInfoForSecondTabHasStatus(infos, 'stopped');
62 chrome.tabs.remove(secondTab.id);
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);
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 });
79 });
82 function captureSameTab() {
83 var stream1 = null;
85 var tabMediaRequestCallback2 = function(stream) {
86 chrome.test.assertLastError(
87 'Cannot capture a tab with an active stream.');
88 chrome.test.assertTrue(!stream);
89 stream1.stop();
90 chrome.test.succeed();
93 tabCapture.capture({audio: true, video: true}, function(stream) {
94 chrome.test.assertTrue(!!stream);
95 stream1 = stream;
96 tabCapture.capture({audio: true, video: true}, tabMediaRequestCallback2);
97 });
100 function onlyVideo() {
101 tabCapture.capture({video: true}, function(stream) {
102 chrome.test.assertTrue(!!stream);
103 stream.stop();
104 chrome.test.succeed();
108 function onlyAudio() {
109 tabCapture.capture({audio: true}, function(stream) {
110 chrome.test.assertTrue(!!stream);
111 stream.stop();
112 chrome.test.succeed();
116 function noAudioOrVideoRequested() {
117 // If not specified, video is not requested.
118 tabCapture.capture({audio: false}, function(stream) {
119 chrome.test.assertTrue(!stream);
120 chrome.test.succeed();