Chromium Code Reviews| Index: chrome/test/data/extensions/tray_cast/background.js |
| diff --git a/chrome/test/data/extensions/tray_cast/background.js b/chrome/test/data/extensions/tray_cast/background.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a80f5c2255cdd031b67fa81af21d86441107962e |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/tray_cast/background.js |
| @@ -0,0 +1,72 @@ |
| +var backgroundSetup = {} |
| + |
| +tryCreateActivity = function(id, title, tabId) { |
|
achuithb
2015/07/09 21:40:10
Add a function comment
jdufault
2015/07/09 23:09:06
Done.
|
| + if (id === undefined || title === undefined || tabId === undefined) |
| + return null; |
| + |
| + return { |
| + "id": id, |
| + "title": title, |
| + "tabId": tabId |
| + }; |
| +} |
| + |
| +var receiversActivities = []; |
| +// Add a new receiver. |activityTitle| and |activityTabId| are optional |
| +// parameters. |
| +addReceiver = function(id, receiverName, activityTitle, activityTabId) { |
| + receiversActivities.push({ |
| + "activity": tryCreateActivity(id, activityTitle, activityTabId), |
| + "receiver": { |
| + "id": id, |
| + "name": receiverName |
| + } |
| + }); |
| +} |
| +// Required API method. |
| +getMirrorCapableReceiversAndActivities = function() { |
| + if (this !== backgroundSetup) |
|
achuithb
2015/07/09 21:40:10
What's this about? Add a comment
jdufault
2015/07/09 23:09:06
Done.
|
| + throw 'this !== backgroundSetup'; |
| + |
| + return receiversActivities; |
| +} |
| + |
| +var stopMirroringReason = ""; |
| +var stopMirroringCalled = false; |
| +wasStopMirroringCalledWithUserStop = function() { |
|
achuithb
2015/07/09 21:40:10
function comment
jdufault
2015/07/09 23:09:06
It'd be something along the lines of "Returns true
|
| + return stopMirroringCalled && stopMirroringReason == 'user-stop'; |
| +} |
| +// Required API method. |
| +stopMirroring = function(reason) { |
| + if (this !== backgroundSetup) |
| + throw 'this !== backgroundSetup'; |
| + |
| + stopMirroringReason = reason; |
| + stopMirroringCalled = true; |
| + for (item of receiversActivities) { |
| + if (item.activity != null) |
|
achuithb
2015/07/09 21:40:10
Is it necessary to add any checks here that at lea
jdufault
2015/07/09 23:09:06
Sure, I can do that. It will help verify that stop
|
| + item.activity = null; |
| + } |
| +} |
| + |
| +var launchTabId = 1; |
| +var launchTabTitle = "Fake Cast"; |
| +var launchDesktopMirroringReceiverId = ""; |
| +getLaunchDesktopMirroringReceiverId = function() { |
| + return launchDesktopMirroringReceiverId; |
| +} |
| +// Required API method. |
| +launchDesktopMirroring = function(receiverId) { |
| + if (this !== backgroundSetup) |
| + throw 'this !== backgroundSetup'; |
| + |
| + launchDesktopMirroringReceiverId = receiverId; |
| + |
| + for (item of receiversActivities) { |
| + if (item.receiver.id == receiverId) { |
|
achuithb
2015/07/09 21:40:10
Is it necessary to add any extra checks here to en
jdufault
2015/07/09 23:09:06
I'm not sure what value this will add. The testing
|
| + item.activity = |
| + tryCreateActivity(receiverId, launchTabId, launchTabTitle); |
| + break; |
| + } |
| + } |
| +} |