Skip to content

Commit

Permalink
Replace usages of Historian.hasBroadcastOrigin()
Browse files Browse the repository at this point in the history
  • Loading branch information
dhurrell committed Dec 11, 2018
1 parent 627b648 commit 3064420
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
42 changes: 42 additions & 0 deletions static/script-tests/tests/application-exit.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,46 @@
}
);
};

this.ApplicationExitTest.prototype.testHasBroadcastOriginWithNoBroadcastUrlParameterReturnsFalse = function(queue) {
queuedApplicationInit(
queue,
'lib/mockapplication',
[
'antie/devices/browserdevice'
],
function(application, BrowserDevice) {
// Configure BrowserDevice.getWindowLocation() to return canned data
this.sandbox.stub(BrowserDevice.prototype, 'getWindowLocation', function() {
return {
href: 'http://www.test.com/',
search: '?'
};
});

assertFalse(application.hasBroadcastOrigin());
}
);
};

this.ApplicationExitTest.prototype.testHasBroadcastOriginWithNoBroadcastUrlParameterReturnsFalse = function(queue) {
queuedApplicationInit(
queue,
'lib/mockapplication',
[
'antie/devices/browserdevice'
],
function(application, BrowserDevice) {
// Configure BrowserDevice.getWindowLocation() to return canned data
this.sandbox.stub(BrowserDevice.prototype, 'getWindowLocation', function() {
return {
href: 'http://www.test.com/?broadcast=true',
search: '?broadcast=true'
};
});

assert(application.hasBroadcastOrigin());
}
);
};
}());
12 changes: 11 additions & 1 deletion static/script/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,23 @@ define('antie/application',
return this.getDevice().getHistorian().hasHistory();
},

/**
* Returns a Boolean value to indicate whether the application has a parameter in its URL indicating
* it was launched with broadcast trust. Use isBroadcastSourceSupported() on {@link antie.devices.Device}
* to see whether a broadcast API is also available for your device.
* @returns {Boolean} True if the URL query contains a broadcast=true entry.
*/
hasBroadcastOrigin: function () {
return this.getCurrentAppURLParameters().broadcast === 'true';
},

/**
* Exits the application by using the configured exit strategy for the device, even if there is a parent TAL
* application in the history stack. Will exit to broadcast if the first TAL application was launched from
* broadcast and a broadcast exit modifier is loaded.
*/
exit: function exit () {
if (this.getDevice().getHistorian().hasBroadcastOrigin()) {
if (this.hasBroadcastOrigin()) {
this.getDevice().exitToBroadcast();
} else {
this.getDevice().exit();
Expand Down
2 changes: 1 addition & 1 deletion static/script/devices/broadcastsource/astrasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ define(
});

Device.prototype.isBroadcastSourceSupported = function() {
return RuntimeContext.getCurrentApplication().getCurrentAppURLParameters().broadcast === 'true';
return RuntimeContext.getCurrentApplication().hasBroadcastOrigin();
};

/**
Expand Down
2 changes: 1 addition & 1 deletion static/script/devices/broadcastsource/hbbtvsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ define(
});

Device.prototype.isBroadcastSourceSupported = function() {
return RuntimeContext.getCurrentApplication().getCurrentAppURLParameters().broadcast === 'true';
return RuntimeContext.getCurrentApplication().hasBroadcastOrigin();
};

/**
Expand Down

0 comments on commit 3064420

Please sign in to comment.