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

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

Issue 1224643008: Add a fake cast extension for testing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Add license Created 5 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
5 var backgroundSetup = {}
6
7 // If all required activity information is available, then this will return an
8 // activity structure; otherwise, it will return null. This lets us
9 // unconditionally assign to the 'activity' field in a JSON object.
10 tryCreateActivity_ = function(id, title, tabId) {
11 if (id === undefined || title === undefined || tabId === undefined)
12 return null;
13
14 return {
15 "id": id,
16 "title": title,
17 "tabId": tabId
18 };
19 }
20
21 var receiversActivities = [];
22 // Add a new receiver. |activityTitle| and |activityTabId| are optional
23 // parameters.
24 addReceiver = function(id, receiverName, activityTitle, activityTabId) {
25 receiversActivities.push({
26 "activity": tryCreateActivity_(id, activityTitle, activityTabId),
27 "receiver": {
28 "id": id,
29 "name": receiverName
30 }
31 });
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
41 return receiversActivities;
42 }
43
44 var stopMirroringReason = "";
45 var stopMirroringCalled = false;
46 wasStopMirroringCalledWithUserStop = function() {
47 return stopMirroringCalled && stopMirroringReason == 'user-stop';
48 }
49 // Required API method.
50 stopMirroring = function(reason) {
51 if (this !== backgroundSetup)
52 throw 'this !== backgroundSetup';
53
54 stopMirroringReason = reason;
55 stopMirroringCalled = true;
56
57 var foundActivity = false;
58 for (item of receiversActivities) {
59 if (item.activity != null) {
60 item.activity = null;
61 foundActivity = true;
62 }
63 }
64 if (foundActivity === false)
65 throw 'stopMirroring called when there was nothing being mirrored'
66 }
67
68 var launchTabId = 1;
69 var launchTabTitle = "Fake Cast";
70 var launchDesktopMirroringReceiverId = "";
71 getLaunchDesktopMirroringReceiverId = function() {
72 return launchDesktopMirroringReceiverId;
73 }
74 // Required API method.
75 launchDesktopMirroring = function(receiverId) {
76 if (this !== backgroundSetup)
77 throw 'this !== backgroundSetup';
78
79 launchDesktopMirroringReceiverId = receiverId;
80
81 for (item of receiversActivities) {
82 if (item.receiver.id == receiverId) {
83 item.activity =
84 tryCreateActivity_(receiverId, launchTabId, launchTabTitle);
85 break;
86 }
87 }
88 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tab_capture/tab_capture_api.cc ('k') | chrome/test/data/extensions/tray_cast/manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698