Skip to content

Commit

Permalink
PS3Base changes (#450)
Browse files Browse the repository at this point in the history
* Add stub tests for all ps3base methods
* Add ps3base system event test using example accessfunction
* Convert any system events into message events using window.postEvent
  • Loading branch information
johnbeech authored May 31, 2017
1 parent 50b4985 commit a89ec29
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 18 deletions.
87 changes: 69 additions & 18 deletions static/script-tests/tests/devices/ps3basetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,72 @@
*/

require(
[
'antie/devices/ps3base',
],
function (PS3Base) {
'use strict';

describe('antie.devices.PS3Base', function () {
var device;

beforeEach(function () {
device = new PS3Base(antie.framework.deviceConfiguration);
});

it('should expose nativeCallback as a method', function () {
expect(typeof device.nativeCallback).toEqual('function');
});
})
});
[
'antie/devices/ps3base',
'antie/devices/data/nativejson'
],
function (PS3Base) {
'use strict';

describe('antie.devices.PS3Base', function () {
var device;

// accessfunction is the way playstation sends system events from the WebMAF to the DOM
function example_accessfunction(json) {
// See: https://github.com/bbc/tal-page-strategies/blob/master/playstation3/body
device.nativeCallback(JSON.stringify(json));
}

beforeEach(function () {
device = new PS3Base(antie.framework.deviceConfiguration);
});

it('should respond to a registered system event', function (done) {
device.addNativeEventListener('externalParameter', function (data) {
expect(data.command).toEqual('externalParameter');
expect(data.value).toEqual('some data');
done();
});
example_accessfunction({
command: 'externalParameter',
value: 'some data'
});
});

it('should expose nativeCallback as a method', function () {
expect(typeof device.nativeCallback).toEqual('function');
});

it('should expose addNativeEventListener as a method', function () {
expect(typeof device.addNativeEventListener).toEqual('function');
});

it('should expose removeNativeEventListener as a method', function () {
expect(typeof device.removeNativeEventListener).toEqual('function');
});

it('should expose nativeCommand as a method', function () {
expect(typeof device.nativeCommand).toEqual('function');
});

it('should expose loadAuthenticatedURL as a method', function () {
expect(typeof device.loadAuthenticatedURL).toEqual('function');
});

it('should expose isHDEnabled as a method', function () {
expect(typeof device.isHDEnabled).toEqual('function');
});

it('should convert any system events into message events using window.postEvent', function (done) {
window.addEventListener('message', function(event) {
expect(event.data.command).toEqual('externalParameter');
expect(event.data.value).toEqual('some data');
done();
});
example_accessfunction({
command: 'externalParameter',
value: 'some data'
});
});
});
});
4 changes: 4 additions & 0 deletions static/script/devices/ps3base.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ define(
break;
}
}

if (typeof window.postMessage === 'function') {
window.postMessage(data, '*');
}
},
addNativeEventListener: function(name, callback) {
var callbacks;
Expand Down

0 comments on commit a89ec29

Please sign in to comment.