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

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: 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 var backgroundSetup = {}
2
3 // If all required activity information is available, then this will return an
4 // activity structure; otherwise, it will return null. This lets us
5 // unconditionally assign to the 'activity' field in a JSON object.
6 tryCreateActivity_ = function(id, title, tabId) {
7 if (id === undefined || title === undefined || tabId === undefined)
8 return null;
9
10 return {
11 "id": id,
12 "title": title,
13 "tabId": tabId
14 };
15 }
16
17 var receiversActivities = [];
18 // Add a new receiver. |activityTitle| and |activityTabId| are optional
19 // parameters.
20 addReceiver = function(id, receiverName, activityTitle, activityTabId) {
21 receiversActivities.push({
22 "activity": tryCreateActivity_(id, activityTitle, activityTabId),
23 "receiver": {
24 "id": id,
25 "name": receiverName
26 }
27 });
28 }
29 // Required API method.
30 getMirrorCapableReceiversAndActivities = function() {
31 // For all of the API methods, we verify that |this| points to
32 // backgroundSetup. In the actual extension, the API methods are
33 // also free-standing but they are really class methods on backgroundSetup.
34 if (this !== backgroundSetup)
35 throw 'this !== backgroundSetup';
36
37 return receiversActivities;
38 }
39
40 var stopMirroringReason = "";
41 var stopMirroringCalled = false;
42 wasStopMirroringCalledWithUserStop = function() {
43 return stopMirroringCalled && stopMirroringReason == 'user-stop';
44 }
45 // Required API method.
46 stopMirroring = function(reason) {
47 if (this !== backgroundSetup)
48 throw 'this !== backgroundSetup';
49
50 stopMirroringReason = reason;
51 stopMirroringCalled = true;
52
53 var foundActivity = false;
54 for (item of receiversActivities) {
55 if (item.activity != null) {
56 item.activity = null;
57 foundActivity = true;
58 }
59 }
60 if (foundActivity === false)
61 throw 'stopMirroring called when there was nothing being mirrored'
62 }
63
64 var launchTabId = 1;
65 var launchTabTitle = "Fake Cast";
66 var launchDesktopMirroringReceiverId = "";
67 getLaunchDesktopMirroringReceiverId = function() {
68 return launchDesktopMirroringReceiverId;
69 }
70 // Required API method.
71 launchDesktopMirroring = function(receiverId) {
72 if (this !== backgroundSetup)
73 throw 'this !== backgroundSetup';
74
75 launchDesktopMirroringReceiverId = receiverId;
76
77 for (item of receiversActivities) {
78 if (item.receiver.id == receiverId) {
79 item.activity =
80 tryCreateActivity_(receiverId, launchTabId, launchTabTitle);
81 break;
82 }
83 }
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698