Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / test / data / extensions / api_test / tab_capture / api_tests.js
bloba942029c326f1867a3efa9038aba519474e90ffb
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 tabIsUnmutedWhenTabCaptured() {
101 var stream1 = null;
103 chrome.tabs.getCurrent(function(tab) {
104 var stopListener = chrome.test.listenForever(chrome.tabs.onUpdated,
105 function(tabId, changeInfo, updatedTab) {
106 if ((changeInfo["muted"] === true)) {
107 tabCapture.capture({audio: true}, function(stream) {
108 stream1 = stream;
111 else if ((changeInfo["mutedCause"] == "capture") &&
112 (changeInfo["muted"] === false)) {
113 stream1.stop();
114 stopListener();
118 chrome.tabs.update(tab.id, {muted: true});
122 function onlyVideo() {
123 tabCapture.capture({video: true}, function(stream) {
124 chrome.test.assertTrue(!!stream);
125 stream.stop();
126 chrome.test.succeed();
130 function onlyAudio() {
131 tabCapture.capture({audio: true}, function(stream) {
132 chrome.test.assertTrue(!!stream);
133 stream.stop();
134 chrome.test.succeed();
138 function noAudioOrVideoRequested() {
139 // If not specified, video is not requested.
140 tabCapture.capture({audio: false}, function(stream) {
141 chrome.test.assertTrue(!stream);
142 chrome.test.succeed();