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

Side by Side Diff: chrome/test/data/extensions/tray_cast/background.js

Issue 1287023010: Browser tests for the ChromeOS chromecast system tray item. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Fix compile error on CrOS bot Created 5 years, 4 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
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/data/extensions/tray_cast/manifest.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 backgroundSetup = {} 5 var backgroundSetup = {}
6 6
7 // If all required activity information is available, then this will return an 7 // If all required activity information is available, then this will return an
8 // activity structure; otherwise, it will return null. This lets us 8 // activity structure; otherwise, it will return null. This lets us
9 // unconditionally assign to the 'activity' field in a JSON object. 9 // unconditionally assign to the 'activity' field in a JSON object.
10 tryCreateActivity_ = function(id, title, tabId) { 10 tryCreateActivity_ = function(id, title, tabId) {
11 if (id === undefined || title === undefined || tabId === undefined) 11 if (id === undefined || title === undefined || tabId === undefined)
12 return null; 12 return null;
13 13
14 return { 14 return {
15 "id": id, 15 'id': id,
16 "title": title, 16 'title': title,
17 "tabId": tabId 17 'tabId': tabId
18 }; 18 };
19 } 19 }
20 20
21 var receiversActivities = []; 21 var receiversActivities = [];
22 var sendDevices = function() {
23 chrome.cast.devicesPrivate.updateDevices(receiversActivities);
24 }
25 chrome.cast.devicesPrivate.updateDevicesRequested.addListener(sendDevices);
26
22 // Add a new receiver. |activityTitle| and |activityTabId| are optional 27 // Add a new receiver. |activityTitle| and |activityTabId| are optional
23 // parameters. 28 // parameters.
24 addReceiver = function(id, receiverName, activityTitle, activityTabId) { 29 var addReceiver = function(id, receiverName, activityTitle, activityTabId) {
25 receiversActivities.push({ 30 receiversActivities.push({
26 "activity": tryCreateActivity_(id, activityTitle, activityTabId), 31 'receiver': {
27 "receiver": { 32 'id': id,
28 "id": id, 33 'name': receiverName
29 "name": receiverName 34 },
30 } 35 'activity': tryCreateActivity_(id, activityTitle, activityTabId)
31 }); 36 });
32 }
33 // Required API method.
34 getMirrorCapableReceiversAndActivities = function() {
35 // For all of the API methods, we verify that |this| points to
36 // backgroundSetup. In the actual extension, the API methods are
37 // also free-standing but they are really class methods on backgroundSetup.
38 if (this !== backgroundSetup)
39 throw 'this !== backgroundSetup';
40 37
41 return receiversActivities; 38 sendDevices();
42 } 39 }
43 40
44 var stopMirroringReason = "";
45 var stopMirroringCalled = false; 41 var stopMirroringCalled = false;
46 wasStopMirroringCalledWithUserStop = function() { 42 chrome.cast.devicesPrivate.stopCast.addListener(function(reason) {
47 return stopMirroringCalled && stopMirroringReason == 'user-stop'; 43 if (reason !== 'user-stop')
48 } 44 throw 'expected reason to be "user-stop"';
49 // Required API method.
50 stopMirroring = function(reason) {
51 if (this !== backgroundSetup)
52 throw 'this !== backgroundSetup';
53
54 stopMirroringReason = reason;
55 stopMirroringCalled = true;
56 45
57 var foundActivity = false; 46 var foundActivity = false;
58 for (item of receiversActivities) { 47 for (item of receiversActivities) {
59 if (item.activity != null) { 48 if (item.activity != null) {
60 item.activity = null; 49 item.activity = null;
61 foundActivity = true; 50 foundActivity = true;
62 } 51 }
63 } 52 }
64 if (foundActivity === false) 53 if (foundActivity === false)
65 throw 'stopMirroring called when there was nothing being mirrored' 54 throw 'stopMirroring called when there was nothing being mirrored'
66 }
67 55
68 var launchTabId = 1; 56 stopMirroringCalled = true;
69 var launchTabTitle = "Fake Cast"; 57 sendDevices();
70 var launchDesktopMirroringReceiverId = ""; 58 });
71 getLaunchDesktopMirroringReceiverId = function() {
72 return launchDesktopMirroringReceiverId;
73 }
74 // Required API method.
75 launchDesktopMirroring = function(receiverId) {
76 if (this !== backgroundSetup)
77 throw 'this !== backgroundSetup';
78 59
60
61 var launchDesktopMirroringReceiverId = '';
62 chrome.cast.devicesPrivate.startCast.addListener(function(receiverId) {
79 launchDesktopMirroringReceiverId = receiverId; 63 launchDesktopMirroringReceiverId = receiverId;
80 64
65 var tabTitle = 'Tab Title';
66 var tabId = 1;
67
81 for (item of receiversActivities) { 68 for (item of receiversActivities) {
82 if (item.receiver.id == receiverId) { 69 if (item.receiver.id == receiverId) {
83 item.activity = 70 item.activity = tryCreateActivity_(receiverId, tabTitle, tabId);
84 tryCreateActivity_(receiverId, launchTabId, launchTabTitle);
85 break; 71 break;
86 } 72 }
87 } 73 }
88 } 74
75 sendDevices();
76 });
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/test/data/extensions/tray_cast/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698