Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
92
gaia/apps/bluetooth/test/unit/views/cannot_transfer_dialog_test.js
Executable file
92
gaia/apps/bluetooth/test/unit/views/cannot_transfer_dialog_test.js
Executable file
|
|
@ -0,0 +1,92 @@
|
|||
'use strict';
|
||||
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
suite('Bluetooth app > CannotTransferDialog ', function() {
|
||||
var CannotTransferDialog;
|
||||
|
||||
suiteSetup(function(done) {
|
||||
|
||||
loadBodyHTML('./_transfer.html');
|
||||
|
||||
var module = [
|
||||
'views/cannot_transfer_dialog'
|
||||
];
|
||||
var map = {};
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
requireCtx(module, function(cannotTransferDialog) {
|
||||
CannotTransferDialog = cannotTransferDialog;
|
||||
done();
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
suite('init > ', function() {
|
||||
test('dialog, confirm button should be defined after init() ', function() {
|
||||
assert.equal(CannotTransferDialog.dialog,
|
||||
document.getElementById('alert-view'));
|
||||
assert.equal(CannotTransferDialog.confirmBtn,
|
||||
document.getElementById('alert-button-ok'));
|
||||
});
|
||||
});
|
||||
|
||||
suite('showConfirm > ', function() {
|
||||
setup(function() {
|
||||
CannotTransferDialog.dialog.hidden = true;
|
||||
this.sinon.stub(CannotTransferDialog, 'close');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
CannotTransferDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('dialog should be show after showConfirm() called ', function() {
|
||||
CannotTransferDialog.showConfirm();
|
||||
assert.isFalse(CannotTransferDialog.dialog.hidden);
|
||||
});
|
||||
|
||||
test('close() be called and resovle promise after a user clicked ' +
|
||||
'confirm button in cannot transfer dialog ', function(done) {
|
||||
CannotTransferDialog.showConfirm().then(() => {
|
||||
assert.ok(true);
|
||||
}, () => {
|
||||
// reject case
|
||||
}).then(done, done);
|
||||
CannotTransferDialog.confirmBtn.onclick();
|
||||
assert.isTrue(CannotTransferDialog.close.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('isVisible > ', function() {
|
||||
setup(function() {
|
||||
CannotTransferDialog.dialog.hidden = false;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
CannotTransferDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('getting the value of visible should be true ' +
|
||||
'after isVisible() is called ', function() {
|
||||
assert.isTrue(CannotTransferDialog.isVisible);
|
||||
});
|
||||
});
|
||||
|
||||
suite('close > ', function() {
|
||||
setup(function() {
|
||||
CannotTransferDialog.dialog.hidden = false;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
CannotTransferDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('dialog should be hidden after close() is called ', function() {
|
||||
CannotTransferDialog.close();
|
||||
assert.isTrue(CannotTransferDialog.dialog.hidden);
|
||||
});
|
||||
});
|
||||
});
|
||||
310
gaia/apps/bluetooth/test/unit/views/device_picker_panel_test.js
Executable file
310
gaia/apps/bluetooth/test/unit/views/device_picker_panel_test.js
Executable file
|
|
@ -0,0 +1,310 @@
|
|||
/* global MockL10n */
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
|
||||
suite('DevicePickerPanel', function() {
|
||||
var realL10n;
|
||||
var devicePickerPanel;
|
||||
var btContext;
|
||||
var btTemplateFactory;
|
||||
var listView;
|
||||
|
||||
suiteSetup(function() {
|
||||
realL10n = window.navigator.mozL10n;
|
||||
window.navigator.mozL10n = MockL10n;
|
||||
|
||||
loadBodyHTML('./_transfer.html');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
window.navigator.mozL10n = realL10n;
|
||||
});
|
||||
|
||||
setup(function(done) {
|
||||
var modules = [
|
||||
'modules/bluetooth/bluetooth_context',
|
||||
'views/bt_template_factory',
|
||||
'modules/mvvm/list_view',
|
||||
'views/device_picker_panel'
|
||||
];
|
||||
|
||||
var map = {
|
||||
'*': {
|
||||
'modules/bluetooth/bluetooth_context': 'MockBluetoothContext',
|
||||
'modules/mvvm/list_view': 'MockListView'
|
||||
}
|
||||
};
|
||||
|
||||
this.MockBluetoothContext = {
|
||||
observe: function() {},
|
||||
getPairedDevices: function() {},
|
||||
getRemoteDevices: function() {},
|
||||
hasPairedDevice: false,
|
||||
state: 'disabled',
|
||||
discovering: false,
|
||||
startDiscovery: function() {return Promise.resolve();},
|
||||
pair: function() {}
|
||||
};
|
||||
|
||||
define('MockBluetoothContext', function() {
|
||||
return this.MockBluetoothContext;
|
||||
}.bind(this));
|
||||
|
||||
this.MockListView = function MockListView() {
|
||||
return {};
|
||||
};
|
||||
|
||||
define('MockListView', function() {
|
||||
return this.MockListView;
|
||||
}.bind(this));
|
||||
|
||||
testRequire(modules, map, function(BluetoothContext, BtTemplateFactory,
|
||||
ListView, DevicePickerPanel) {
|
||||
btContext = BluetoothContext;
|
||||
btTemplateFactory = BtTemplateFactory;
|
||||
listView = ListView;
|
||||
devicePickerPanel = DevicePickerPanel;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite('_Init > ', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(devicePickerPanel._elements.header.headerActionClose,
|
||||
'addEventListener');
|
||||
this.sinon.stub(devicePickerPanel._elements.search.searchButton,
|
||||
'addEventListener');
|
||||
devicePickerPanel._pairedDevicesListView = null;
|
||||
devicePickerPanel._foundDevicesListView = null;
|
||||
this.sinon.stub(devicePickerPanel, '_initItemsState');
|
||||
this.sinon.stub(btContext, 'startDiscovery').returns(Promise.resolve());
|
||||
});
|
||||
|
||||
test('The close button of header should be regedit action callback, ' +
|
||||
'search button should be regedit onclick callback, ' +
|
||||
'paired/found list view should be defined, ' +
|
||||
'_initItemsState() should be called ' +
|
||||
'BtContext.startDiscovery() should be called ', function() {
|
||||
devicePickerPanel._init();
|
||||
// close button
|
||||
assert.equal(
|
||||
devicePickerPanel._elements.header.headerActionClose.
|
||||
addEventListener.args[0][0], 'action');
|
||||
assert.isDefined(
|
||||
devicePickerPanel._elements.header.headerActionClose.
|
||||
addEventListener.args[0][1]);
|
||||
// search button
|
||||
assert.equal(
|
||||
devicePickerPanel._elements.search.searchButton.
|
||||
addEventListener.args[0][0], 'click');
|
||||
assert.isDefined(
|
||||
devicePickerPanel._elements.search.searchButton.
|
||||
addEventListener.args[0][1]);
|
||||
// paired/found list view
|
||||
assert.isDefined(devicePickerPanel._pairedDevicesListView);
|
||||
assert.isDefined(devicePickerPanel._foundDevicesListView);
|
||||
assert.isTrue(devicePickerPanel._initItemsState.called);
|
||||
assert.isTrue(btContext.startDiscovery.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('_initItemsState > ', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(btContext, 'observe');
|
||||
this.sinon.stub(devicePickerPanel, '_updatePairedDevicesHeader');
|
||||
this.sinon.stub(devicePickerPanel, '_updatePairedDevicesList');
|
||||
this.sinon.stub(devicePickerPanel, '_updateFoundDevicesList');
|
||||
this.sinon.stub(devicePickerPanel, '_updateSearchItem');
|
||||
this.sinon.stub(devicePickerPanel, '_updateSearchingItem');
|
||||
});
|
||||
|
||||
test('btContext.hasPairedDevice should be observed with callback, ' +
|
||||
'btContext.state should be observed with callback, ' +
|
||||
'btContext.discovering should be observed with callback, ' +
|
||||
'paired device header, paired/found device list, ' +
|
||||
'search/searching item should be updated.. ', function() {
|
||||
devicePickerPanel._initItemsState();
|
||||
// paired device header
|
||||
assert.equal(btContext.observe.args[0][0], 'hasPairedDevice');
|
||||
assert.isDefined(btContext.observe.args[0][1]);
|
||||
assert.isTrue(devicePickerPanel._updatePairedDevicesHeader.called);
|
||||
// paired device list
|
||||
assert.equal(btContext.observe.args[1][0], 'state');
|
||||
assert.isDefined(btContext.observe.args[1][1]);
|
||||
assert.isTrue(devicePickerPanel._updatePairedDevicesList.called);
|
||||
// found device list
|
||||
assert.equal(btContext.observe.args[2][0], 'state');
|
||||
assert.isDefined(btContext.observe.args[2][1]);
|
||||
assert.isTrue(devicePickerPanel._updateFoundDevicesList.called);
|
||||
// search item
|
||||
assert.equal(btContext.observe.args[3][0], 'state');
|
||||
assert.isDefined(btContext.observe.args[3][1]);
|
||||
assert.isTrue(devicePickerPanel._updateSearchItem.called);
|
||||
// searching item
|
||||
assert.equal(btContext.observe.args[4][0], 'discovering');
|
||||
assert.isDefined(btContext.observe.args[4][1]);
|
||||
assert.isTrue(devicePickerPanel._updateSearchingItem.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('_onHeaderActionCloseClick > ', function() {
|
||||
var expectedEvent = {
|
||||
type: 'cancelSelection'
|
||||
};
|
||||
setup(function() {
|
||||
this.sinon.stub(devicePickerPanel, '_emitEvent');
|
||||
});
|
||||
|
||||
test('_emitEvent() should be called with event, type = "cancelSelection" ' +
|
||||
'while _onHeaderActionCloseClick() be called ', function() {
|
||||
devicePickerPanel._onHeaderActionCloseClick();
|
||||
assert.isTrue(devicePickerPanel._emitEvent.calledWith(expectedEvent));
|
||||
});
|
||||
});
|
||||
|
||||
suite('_onSearchButtonClick > ', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(btContext, 'startDiscovery').returns(Promise.resolve());
|
||||
});
|
||||
|
||||
test('btContext.startDiscovery() should be called while ' +
|
||||
'search button is clicked ', function() {
|
||||
devicePickerPanel._onSearchButtonClick();
|
||||
assert.isTrue(btContext.startDiscovery.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('_onPairedDeviceItemClick > ', function() {
|
||||
var mockDeviceItem, expectedEvent;
|
||||
setup(function() {
|
||||
mockDeviceItem = {
|
||||
address: 'AA:BB:CC:00:11:22'
|
||||
};
|
||||
expectedEvent = {
|
||||
type: 'devicePicked',
|
||||
detail: {
|
||||
address: mockDeviceItem.address
|
||||
}
|
||||
};
|
||||
this.sinon.stub(devicePickerPanel, '_emitEvent');
|
||||
});
|
||||
|
||||
test('_emitEvent() should be called with event, type = "devicePicked" ' +
|
||||
'while _onPairedDeviceItemClick() be called with device item ',
|
||||
function() {
|
||||
devicePickerPanel._onPairedDeviceItemClick(mockDeviceItem);
|
||||
assert.isTrue(devicePickerPanel._emitEvent.calledWith(expectedEvent));
|
||||
});
|
||||
});
|
||||
|
||||
suite('_onFoundDeviceItemClick > ', function() {
|
||||
var mockDeviceItem, mockPairPromise;
|
||||
suite('btContext.pair() with resolve > ', function() {
|
||||
var expectedEvent;
|
||||
setup(function() {
|
||||
mockDeviceItem = {
|
||||
address: 'AA:BB:CC:00:11:22',
|
||||
paired: false
|
||||
};
|
||||
expectedEvent = {
|
||||
type: 'devicePicked',
|
||||
detail: {
|
||||
address: mockDeviceItem.address
|
||||
}
|
||||
};
|
||||
mockPairPromise = Promise.resolve();
|
||||
this.sinon.stub(btContext, 'pair').returns(mockPairPromise);
|
||||
this.sinon.stub(devicePickerPanel, '_emitEvent');
|
||||
this.sinon.stub(devicePickerPanel, '_alertPairFailedErrorMessage');
|
||||
});
|
||||
|
||||
test('the "paired" property of device item should be set "pairing", ' +
|
||||
'_emitEvent() should be called with event, type = "devicePicked," ' +
|
||||
'_alertPairFailedErrorMessage() should not be called ' +
|
||||
'while _onFoundDeviceItemClick() be called with device item ',
|
||||
function(done) {
|
||||
devicePickerPanel._onFoundDeviceItemClick(mockDeviceItem);
|
||||
assert.equal(mockDeviceItem.paired, 'pairing');
|
||||
mockPairPromise.then(() => {
|
||||
assert.isTrue(devicePickerPanel._emitEvent.calledWith(expectedEvent));
|
||||
assert.isFalse(devicePickerPanel._alertPairFailedErrorMessage.called);
|
||||
}, () => {
|
||||
// reject case
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
|
||||
suite('btContext.pair() with reject > ', function() {
|
||||
setup(function() {
|
||||
mockDeviceItem = {
|
||||
address: 'AA:BB:CC:00:11:22',
|
||||
paired: false
|
||||
};
|
||||
mockPairPromise = Promise.reject();
|
||||
this.sinon.stub(btContext, 'pair').returns(mockPairPromise);
|
||||
this.sinon.stub(devicePickerPanel, '_emitEvent');
|
||||
this.sinon.stub(devicePickerPanel, '_alertPairFailedErrorMessage');
|
||||
});
|
||||
|
||||
test('the "paired" property of device item should be set "pairing", ' +
|
||||
'then the property will be set to false in pair rejected case, ' +
|
||||
'_emitEvent() should not be called, ' +
|
||||
'_alertPairFailedErrorMessage() should be called ' +
|
||||
'while _onFoundDeviceItemClick() be called with device item ',
|
||||
function(done) {
|
||||
devicePickerPanel._onFoundDeviceItemClick(mockDeviceItem);
|
||||
assert.equal(mockDeviceItem.paired, 'pairing');
|
||||
mockPairPromise.then(() => {
|
||||
// resolve case
|
||||
}, () => {
|
||||
assert.isFalse(mockDeviceItem.paired);
|
||||
assert.isFalse(devicePickerPanel._emitEvent.called);
|
||||
assert.isTrue(devicePickerPanel._alertPairFailedErrorMessage.called);
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('_alertPairFailedErrorMessage > ', function() {
|
||||
var mockErrorReason, expectedMsg;
|
||||
suite('no errorReason > ', function() {
|
||||
setup(function() {
|
||||
mockErrorReason = null;
|
||||
expectedMsg = 'error-pair-title';
|
||||
this.sinon.stub(window, 'alert');
|
||||
});
|
||||
|
||||
test('Show default message if there is no error reason ', function() {
|
||||
devicePickerPanel._alertPairFailedErrorMessage(mockErrorReason);
|
||||
assert.isTrue(window.alert.calledWith(expectedMsg));
|
||||
});
|
||||
});
|
||||
|
||||
suite('has errorReason "Authentication Failed" > ', function() {
|
||||
setup(function() {
|
||||
mockErrorReason = 'Authentication Failed';
|
||||
expectedMsg = 'error-pair-title' + '\n' + 'error-pair-pincode';
|
||||
this.sinon.stub(window, 'alert');
|
||||
});
|
||||
|
||||
test('Show message with pincode error if error reason is ' +
|
||||
'"Authentication Failed" ', function() {
|
||||
devicePickerPanel._alertPairFailedErrorMessage(mockErrorReason);
|
||||
assert.isTrue(window.alert.calledWith(expectedMsg));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('visible > ', function() {
|
||||
setup(function() {
|
||||
devicePickerPanel._elements.view.viewDevicePicker.hidden = true;
|
||||
});
|
||||
|
||||
test('device picker view should be set visible', function() {
|
||||
devicePickerPanel.visible = true;
|
||||
assert.isFalse(devicePickerPanel._elements.view.viewDevicePicker.hidden);
|
||||
});
|
||||
});
|
||||
});
|
||||
97
gaia/apps/bluetooth/test/unit/views/pair_expired_dialog_test.js
Executable file
97
gaia/apps/bluetooth/test/unit/views/pair_expired_dialog_test.js
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
/* global MockL10n */
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
|
||||
suite('Bluetooth app > PairExpiredDialog ', function() {
|
||||
var realL10n, PairExpiredDialog;
|
||||
|
||||
suiteSetup(function(done) {
|
||||
realL10n = window.navigator.mozL10n;
|
||||
window.navigator.mozL10n = MockL10n;
|
||||
|
||||
loadBodyHTML('./_message.html');
|
||||
|
||||
var module = [
|
||||
'views/pair_expired_dialog'
|
||||
];
|
||||
var map = {};
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
requireCtx(module, function(pairExpiredDialog) {
|
||||
PairExpiredDialog = pairExpiredDialog;
|
||||
done();
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
window.navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
suite('init > ', function() {
|
||||
test('dialog, confirm button should be defined after init() ', function() {
|
||||
assert.equal(PairExpiredDialog.dialog,
|
||||
document.getElementById('pairing-request-timeout'));
|
||||
assert.equal(PairExpiredDialog.confirmBtn,
|
||||
document.getElementById('incoming-pairing-timeout-confirm'));
|
||||
});
|
||||
});
|
||||
|
||||
suite('showConfirm > ', function() {
|
||||
var callback;
|
||||
setup(function() {
|
||||
callback = function() {/* do something.. */};
|
||||
PairExpiredDialog.dialog.hidden = true;
|
||||
this.sinon.stub(PairExpiredDialog, 'close');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
callback = null;
|
||||
PairExpiredDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('dialog should be show after showConfirm() called ', function() {
|
||||
PairExpiredDialog.showConfirm(callback);
|
||||
assert.isFalse(PairExpiredDialog.dialog.hidden);
|
||||
});
|
||||
|
||||
test('close() be called with callback function after a user clicked ' +
|
||||
'confirm button in pair expired dialog ', function() {
|
||||
PairExpiredDialog.showConfirm(callback);
|
||||
PairExpiredDialog.confirmBtn.onclick();
|
||||
assert.isTrue(PairExpiredDialog.close.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('isVisible > ', function() {
|
||||
setup(function() {
|
||||
PairExpiredDialog.dialog.hidden = false;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
PairExpiredDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('getting the value of visible should be true ' +
|
||||
'after isVisible() is called ', function() {
|
||||
assert.isTrue(PairExpiredDialog.isVisible);
|
||||
});
|
||||
});
|
||||
|
||||
suite('close > ', function() {
|
||||
setup(function() {
|
||||
PairExpiredDialog.dialog.hidden = false;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
PairExpiredDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('dialog should be hidden after close() is called, and the arg of ' +
|
||||
'callback should be excuted if it is given ', function() {
|
||||
PairExpiredDialog.close();
|
||||
assert.isTrue(PairExpiredDialog.dialog.hidden);
|
||||
});
|
||||
});
|
||||
});
|
||||
461
gaia/apps/bluetooth/test/unit/views/pair_view_test.js
Executable file
461
gaia/apps/bluetooth/test/unit/views/pair_view_test.js
Executable file
|
|
@ -0,0 +1,461 @@
|
|||
/* global MocksHelper, MockL10n, Pairview */
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
requireApp('bluetooth/test/unit/mock_pair_manager.js');
|
||||
|
||||
function switchReadOnlyProperty(originObject, propName, targetObj) {
|
||||
Object.defineProperty(originObject, propName, {
|
||||
configurable: true,
|
||||
get: function() { return targetObj; }
|
||||
});
|
||||
}
|
||||
|
||||
var mocksForPairviewHelper = new MocksHelper([
|
||||
'PairManager'
|
||||
]).init();
|
||||
|
||||
suite('Bluetooth app > Pairview ', function() {
|
||||
var realL10n;
|
||||
|
||||
mocksForPairviewHelper.attachTestHelpers();
|
||||
|
||||
suiteSetup(function(done) {
|
||||
realL10n = window.navigator.mozL10n;
|
||||
window.navigator.mozL10n = MockL10n;
|
||||
|
||||
loadBodyHTML('./_onpair.html');
|
||||
|
||||
requireApp('bluetooth/js/views/pair_view.js', done);
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
window.navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
suite('isFullAttentionMode > ', function() {
|
||||
var realWindowInnerHeight;
|
||||
suiteSetup(function() {
|
||||
realWindowInnerHeight = window.innerHeight;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
switchReadOnlyProperty(window, 'innerHeight', realWindowInnerHeight);
|
||||
});
|
||||
|
||||
suite('window.innerHeight is 200 > ', function() {
|
||||
setup(function() {
|
||||
switchReadOnlyProperty(window, 'innerHeight', 200);
|
||||
});
|
||||
|
||||
test('getting the mode of full attention should be false ' +
|
||||
'after isFullAttentionMode() is called ', function() {
|
||||
assert.isFalse(Pairview.isFullAttentionMode);
|
||||
});
|
||||
});
|
||||
|
||||
suite('window.innerHeight is 201 > ', function() {
|
||||
setup(function() {
|
||||
switchReadOnlyProperty(window, 'innerHeight', 201);
|
||||
});
|
||||
|
||||
test('getting the mode of full attention should be true ' +
|
||||
'after isFullAttentionMode() is called ', function() {
|
||||
assert.isTrue(Pairview.isFullAttentionMode);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('init > ', function() {
|
||||
var mockPairMethod, mockOptions;
|
||||
setup(function(done) {
|
||||
mockPairMethod = 'displaypasskey';
|
||||
mockOptions = {
|
||||
deviceName: 'device-01',
|
||||
handle: {
|
||||
passkey: 123456
|
||||
}
|
||||
};
|
||||
this.sinon.stub(Pairview, 'show');
|
||||
this.sinon.stub(Pairview, '_pairMethod');
|
||||
this.sinon.stub(Pairview, '_remoteDeviceName');
|
||||
this.sinon.stub(Pairview, '_passkey');
|
||||
Pairview.init(mockPairMethod, mockOptions);
|
||||
setTimeout(done);
|
||||
});
|
||||
|
||||
test('pairing info should be inited after init() ', function() {
|
||||
assert.equal(Pairview._pairMethod, mockPairMethod);
|
||||
assert.equal(Pairview._remoteDeviceName, mockOptions.deviceName);
|
||||
assert.equal(Pairview._passkey, 123456);
|
||||
});
|
||||
|
||||
test('pair view should be showing after mozL10n.once callback', function() {
|
||||
assert.isTrue(Pairview.show.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('show > pair method in three methods > ', function() {
|
||||
var realGetTruncated;
|
||||
var mockDeviceName = 'device-01';
|
||||
var mockPasskey = 123456;
|
||||
|
||||
setup(function() {
|
||||
realGetTruncated = window.getTruncated;
|
||||
window.getTruncated = this.sinon.stub();
|
||||
window.getTruncated.returns({
|
||||
addEventListener: this.sinon.stub()
|
||||
});
|
||||
});
|
||||
|
||||
suite('early return > ', function() {
|
||||
var realWindowInnerHeight;
|
||||
|
||||
setup(function() {
|
||||
realWindowInnerHeight = window.innerHeight;
|
||||
switchReadOnlyProperty(window, 'innerHeight', 200);
|
||||
this.sinon.stub(Pairview, 'close');
|
||||
Pairview.show();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
switchReadOnlyProperty(window, 'innerHeight', realWindowInnerHeight);
|
||||
});
|
||||
|
||||
test('isFullAttentionMode() should be false', function() {
|
||||
assert.isFalse(Pairview.isFullAttentionMode);
|
||||
});
|
||||
|
||||
test('close() should be called while attention sceen is not in full ' +
|
||||
'screen mode ', function() {
|
||||
assert.isTrue(Pairview.close.called);
|
||||
});
|
||||
|
||||
test('getTruncated() should not be called since early return',
|
||||
function() {
|
||||
assert.isFalse(window.getTruncated.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('confirmation, displaypasskey > ', function() {
|
||||
['confirmation', 'displaypasskey'].forEach((mockPairMethod) => {
|
||||
setup(function() {
|
||||
this.sinon.stub(Pairview, '_pairMethod', mockPairMethod);
|
||||
this.sinon.stub(Pairview, '_remoteDeviceName', mockDeviceName);
|
||||
this.sinon.stub(Pairview, '_passkey', mockPasskey);
|
||||
Pairview.show();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
Pairview.nameLabel.textContent = undefined;
|
||||
Pairview.pairview.hidden = true;
|
||||
Pairview.pairDescription.textContent = undefined;
|
||||
Pairview.passkey.textContent = undefined;
|
||||
Pairview.comfirmationItem.hidden = true;
|
||||
Pairview.pinInputItem.hidden = true;
|
||||
});
|
||||
|
||||
test('nameLabel should be defined after show() ', function() {
|
||||
assert.isDefined(Pairview.nameLabel.textContent);
|
||||
});
|
||||
test('view should not be hidden after show() ', function() {
|
||||
assert.isFalse(Pairview.pairview.hidden);
|
||||
});
|
||||
test('description should be defined after show() ', function() {
|
||||
assert.isDefined(Pairview.pairDescription.textContent);
|
||||
});
|
||||
test('passkey textContent should be displayed and ' +
|
||||
'same with pairing info from system message ', function() {
|
||||
assert.equal(Pairview.passkey.textContent, mockPasskey);
|
||||
});
|
||||
test('comfirmation method should not be hidden after show()',
|
||||
function() {
|
||||
assert.isFalse(Pairview.comfirmationItem.hidden);
|
||||
});
|
||||
test('pin input field should be hidden after show() ', function() {
|
||||
assert.isTrue(Pairview.pinInputItem.hidden);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('enterpincode > ', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(Pairview, '_pairMethod', 'enterpincode');
|
||||
this.sinon.stub(Pairview, '_remoteDeviceName', mockDeviceName);
|
||||
Pairview.show();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
Pairview.nameLabel.textContent = undefined;
|
||||
Pairview.pairview.hidden = true;
|
||||
Pairview.pairDescription.textContent = undefined;
|
||||
Pairview.comfirmationItem.hidden = true;
|
||||
Pairview.pinInputItem.hidden = true;
|
||||
});
|
||||
|
||||
test('nameLabel should be defined after show() ', function() {
|
||||
assert.isDefined(Pairview.nameLabel.textContent);
|
||||
});
|
||||
test('view should not be hidden after show() ', function() {
|
||||
assert.isFalse(Pairview.pairview.hidden);
|
||||
});
|
||||
test('description should be defined after show() ', function() {
|
||||
assert.isDefined(Pairview.pairDescription.textContent);
|
||||
});
|
||||
test('pin input field should not be hidden after show() ', function() {
|
||||
assert.isFalse(Pairview.pinInputItem.hidden);
|
||||
});
|
||||
test('comfirmation method should be hidden after show() ', function() {
|
||||
assert.isTrue(Pairview.comfirmationItem.hidden);
|
||||
});
|
||||
});
|
||||
|
||||
suite('consent > ', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(Pairview, '_pairMethod', 'consent');
|
||||
this.sinon.stub(Pairview, '_remoteDeviceName', mockDeviceName);
|
||||
Pairview.show();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
Pairview.nameLabel.textContent = undefined;
|
||||
Pairview.pairview.hidden = true;
|
||||
Pairview.pairDescription.textContent = undefined;
|
||||
Pairview.comfirmationItem.hidden = true;
|
||||
Pairview.pinInputItem.hidden = true;
|
||||
});
|
||||
|
||||
test('nameLabel should be defined after show() ', function() {
|
||||
assert.isDefined(Pairview.nameLabel.textContent);
|
||||
});
|
||||
test('view should not be hidden after show() ', function() {
|
||||
assert.isFalse(Pairview.pairview.hidden);
|
||||
});
|
||||
test('description should be defined after show() ', function() {
|
||||
assert.isDefined(Pairview.pairDescription.textContent);
|
||||
});
|
||||
test('comfirmation method should not be hidden after show()', function() {
|
||||
assert.isFalse(Pairview.comfirmationItem.hidden);
|
||||
});
|
||||
test('pin input field should be hidden after show() ', function() {
|
||||
assert.isTrue(Pairview.pinInputItem.hidden);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('handleEvent > ', function() {
|
||||
var fakePreventDefault = function() {/* do nothing here.. */};
|
||||
|
||||
var stubWindowClose;
|
||||
suiteSetup(function() {
|
||||
stubWindowClose = sinon.stub(window, 'close');
|
||||
Pairview.pairButton.disabled = false;
|
||||
Pairview.closeButton.disabled = false;
|
||||
Pairview.pairDescription.textContent = undefined;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
stubWindowClose.restore();
|
||||
Pairview.pairButton.disabled = false;
|
||||
Pairview.closeButton.disabled = false;
|
||||
Pairview.pairDescription.textContent = undefined;
|
||||
});
|
||||
|
||||
suite('click pair button > pair method: displaypasskey ', function() {
|
||||
setup(function() {
|
||||
this.sinon.stub(Pairview, '_pairMethod', 'displaypasskey');
|
||||
Pairview.handleEvent({target: {id: 'button-pair'},
|
||||
type: 'click',
|
||||
preventDefault: fakePreventDefault});
|
||||
});
|
||||
|
||||
test('description should be defined after clicked pair button',
|
||||
function() {
|
||||
assert.isDefined(Pairview.pairDescription.textContent);
|
||||
});
|
||||
test('pair button should be disabled after clicked event ', function() {
|
||||
assert.isTrue(Pairview.pairButton.disabled);
|
||||
});
|
||||
test('close button should be disabled after clicked event ', function() {
|
||||
assert.isTrue(Pairview.closeButton.disabled);
|
||||
});
|
||||
test('window should be closed after clicked event', function() {
|
||||
assert.isTrue(stubWindowClose.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('click pair button > pair method: enterpincode ', function() {
|
||||
var mockOptions, pincode = 'SixteenTxtLength';
|
||||
|
||||
setup(function() {
|
||||
this.sinon.stub(Pairview, '_pairMethod', 'enterpincode');
|
||||
Pairview.pinInput.value = pincode;
|
||||
mockOptions = {
|
||||
handle: {
|
||||
setPinCode: function() {return Promise.resolve();}
|
||||
}
|
||||
};
|
||||
this.sinon.spy(mockOptions.handle, 'setPinCode');
|
||||
this.sinon.stub(Pairview, '_options', mockOptions);
|
||||
Pairview.handleEvent({target: {id: 'button-pair'},
|
||||
type: 'click',
|
||||
preventDefault: fakePreventDefault});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
Pairview.pinInput.value = '';
|
||||
});
|
||||
|
||||
test('description should be defined after clicked pair button',
|
||||
function() {
|
||||
assert.isDefined(Pairview.pairDescription.textContent);
|
||||
});
|
||||
test('pair button should be disabled after clicked event ', function() {
|
||||
assert.isTrue(Pairview.pairButton.disabled);
|
||||
});
|
||||
test('close button should be disabled after clicked event ', function() {
|
||||
assert.isTrue(Pairview.closeButton.disabled);
|
||||
});
|
||||
test('set pin code should be set after clicked event', function() {
|
||||
assert.isTrue(Pairview._options.handle.setPinCode.calledWith(pincode));
|
||||
});
|
||||
test('window should be closed after setPinCode resolve ', function(done) {
|
||||
mockOptions.handle.setPinCode(pincode).then(() => {
|
||||
assert.isTrue(stubWindowClose.called);
|
||||
}, () => {
|
||||
// reject case
|
||||
assert.isTrue(false);
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
|
||||
suite('click pair button > pair method: confirmation, consent ',
|
||||
function() {
|
||||
var mockOptions;
|
||||
|
||||
['confirmation', 'consent'].forEach((mockPairMethod) => {
|
||||
setup(function() {
|
||||
this.sinon.stub(Pairview, '_pairMethod', mockPairMethod);
|
||||
mockOptions = {
|
||||
handle: {
|
||||
accept: function() {return Promise.resolve();}
|
||||
}
|
||||
};
|
||||
this.sinon.spy(mockOptions.handle, 'accept');
|
||||
this.sinon.stub(Pairview, '_options', mockOptions);
|
||||
Pairview.handleEvent({target: {id: 'button-pair'},
|
||||
type: 'click',
|
||||
preventDefault: fakePreventDefault});
|
||||
});
|
||||
|
||||
test('description should be defined after clicked pair button',
|
||||
function() {
|
||||
assert.isDefined(Pairview.pairDescription.textContent);
|
||||
});
|
||||
test('pair button should be disabled after clicked event ', function() {
|
||||
assert.isTrue(Pairview.pairButton.disabled);
|
||||
});
|
||||
test('close button should be disabled after clicked event', function() {
|
||||
assert.isTrue(Pairview.closeButton.disabled);
|
||||
});
|
||||
test('handle.accept should be set after clicked event', function() {
|
||||
assert.isTrue(Pairview._options.handle.accept.called);
|
||||
});
|
||||
test('window should be closed after accept resolve', function(done) {
|
||||
mockOptions.handle.accept().then(() => {
|
||||
assert.isTrue(stubWindowClose.called);
|
||||
}, () => {
|
||||
// reject case
|
||||
assert.isTrue(false);
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('click close button > ', function() {
|
||||
var pairviewCloseSpy, mockOptions;
|
||||
|
||||
setup(function() {
|
||||
pairviewCloseSpy = this.sinon.spy(Pairview, 'close');
|
||||
mockOptions = {
|
||||
handle: {
|
||||
reject: function() {return Promise.resolve();}
|
||||
}
|
||||
};
|
||||
this.sinon.spy(mockOptions.handle, 'reject');
|
||||
this.sinon.stub(Pairview, '_options', mockOptions);
|
||||
Pairview.handleEvent({target: {id: 'button-close'},
|
||||
type: 'click',
|
||||
preventDefault: fakePreventDefault});
|
||||
});
|
||||
|
||||
test('close() method should be called after clicked close ', function() {
|
||||
assert.isTrue(pairviewCloseSpy.called);
|
||||
});
|
||||
test('handle.reject should be set after clicked close ', function(done) {
|
||||
mockOptions.handle.reject().then(() => {
|
||||
assert.isTrue(stubWindowClose.called);
|
||||
}, () => {
|
||||
// reject case
|
||||
assert.isTrue(false);
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
|
||||
suite('received "resize" event > ', function() {
|
||||
var pairviewCloseSpy, mockOptions;
|
||||
|
||||
setup(function() {
|
||||
pairviewCloseSpy = this.sinon.spy(Pairview, 'close');
|
||||
mockOptions = {
|
||||
handle: {
|
||||
reject: function() {return Promise.resolve();}
|
||||
}
|
||||
};
|
||||
this.sinon.spy(mockOptions.handle, 'reject');
|
||||
this.sinon.stub(Pairview, '_options', mockOptions);
|
||||
switchReadOnlyProperty(window, 'innerHeight', 150);
|
||||
Pairview.handleEvent({target: {},
|
||||
type: 'resize',
|
||||
preventDefault: fakePreventDefault});
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
switchReadOnlyProperty(window, 'innerHeight', null);
|
||||
});
|
||||
|
||||
test('close() method should be called after clicked close ', function() {
|
||||
assert.isTrue(pairviewCloseSpy.called);
|
||||
});
|
||||
test('handle.reject should be set after clicked close ', function(done) {
|
||||
mockOptions.handle.reject().then(() => {
|
||||
assert.isTrue(stubWindowClose.called);
|
||||
}, () => {
|
||||
// reject case
|
||||
assert.isTrue(false);
|
||||
}).then(done, done);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite('closeInput > ', function() {
|
||||
var pairviewPinInputSpy;
|
||||
setup(function() {
|
||||
pairviewPinInputSpy = this.sinon.spy(Pairview.pinInput, 'blur');
|
||||
Pairview.pinInputItem.hidden = false;
|
||||
Pairview.closeInput();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
pairviewPinInputSpy.restore();
|
||||
Pairview.pinInputItem.hidden = true;
|
||||
});
|
||||
|
||||
test('pin input should be blurred after closeInput() ', function() {
|
||||
assert.isTrue(pairviewPinInputSpy.called);
|
||||
});
|
||||
});
|
||||
});
|
||||
113
gaia/apps/bluetooth/test/unit/views/turn_bluetooth_on_dialog_test.js
Executable file
113
gaia/apps/bluetooth/test/unit/views/turn_bluetooth_on_dialog_test.js
Executable file
|
|
@ -0,0 +1,113 @@
|
|||
'use strict';
|
||||
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
suite('Bluetooth app > TurnBluetoothOnDialog ', function() {
|
||||
var TurnBluetoothOnDialog;
|
||||
|
||||
suiteSetup(function(done) {
|
||||
|
||||
loadBodyHTML('./_transfer.html');
|
||||
|
||||
var module = [
|
||||
'views/turn_bluetooth_on_dialog'
|
||||
];
|
||||
var map = {};
|
||||
var requireCtx = testRequire([], map, function() {});
|
||||
requireCtx(module, function(turnBluetoothOnDialog) {
|
||||
TurnBluetoothOnDialog = turnBluetoothOnDialog;
|
||||
done();
|
||||
}.bind(this));
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
suite('init > ', function() {
|
||||
test('dialog, cancel/confirm button should be defined after init() ',
|
||||
function() {
|
||||
assert.equal(TurnBluetoothOnDialog.dialog,
|
||||
document.getElementById('enable-bluetooth-view'));
|
||||
assert.equal(TurnBluetoothOnDialog.cancelBtn,
|
||||
document.getElementById('enable-bluetooth-button-cancel'));
|
||||
assert.equal(TurnBluetoothOnDialog.confirmBtn,
|
||||
document.getElementById('enable-bluetooth-button-turn-on'));
|
||||
});
|
||||
});
|
||||
|
||||
suite('showConfirm > ', function() {
|
||||
var confirmedAction;
|
||||
setup(function() {
|
||||
confirmedAction = {
|
||||
cancel: 'cancel',
|
||||
confirm: 'confirm'
|
||||
};
|
||||
TurnBluetoothOnDialog.dialog.hidden = true;
|
||||
this.sinon.stub(TurnBluetoothOnDialog, 'close');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
TurnBluetoothOnDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('dialog should be show after showConfirm() called ', function() {
|
||||
TurnBluetoothOnDialog.showConfirm();
|
||||
assert.isFalse(TurnBluetoothOnDialog.dialog.hidden);
|
||||
});
|
||||
|
||||
test('close() be called and resovled promise with arg "cancel" after a ' +
|
||||
'user clicked cancel button in turn Bluetooth on dialog ',
|
||||
function(done) {
|
||||
TurnBluetoothOnDialog.showConfirm().then((result) => {
|
||||
assert.equal(result, confirmedAction.cancel);
|
||||
}, () => {
|
||||
// reject case
|
||||
}).then(done, done);
|
||||
TurnBluetoothOnDialog.cancelBtn.onclick();
|
||||
assert.isTrue(TurnBluetoothOnDialog.close.called);
|
||||
});
|
||||
|
||||
test('close() be called and resolved promise with arg "confirm" after a ' +
|
||||
'user clicked confirm button in turn Bluetooth on dialog ',
|
||||
function(done) {
|
||||
TurnBluetoothOnDialog.showConfirm().then((result) => {
|
||||
assert.equal(result, confirmedAction.confirm);
|
||||
}, () => {
|
||||
// reject case
|
||||
}).then(done, done);
|
||||
TurnBluetoothOnDialog.confirmBtn.onclick();
|
||||
assert.isTrue(TurnBluetoothOnDialog.close.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite('isVisible > ', function() {
|
||||
setup(function() {
|
||||
TurnBluetoothOnDialog.dialog.hidden = false;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
TurnBluetoothOnDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('getting the value of visible should be true ' +
|
||||
'after isVisible() is called ', function() {
|
||||
assert.isTrue(TurnBluetoothOnDialog.isVisible);
|
||||
});
|
||||
});
|
||||
|
||||
suite('close > ', function() {
|
||||
setup(function() {
|
||||
TurnBluetoothOnDialog.dialog.hidden = false;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
TurnBluetoothOnDialog.dialog.hidden = true;
|
||||
});
|
||||
|
||||
test('dialog should be hidden after close() is called ', function() {
|
||||
TurnBluetoothOnDialog.close();
|
||||
assert.isTrue(TurnBluetoothOnDialog.dialog.hidden);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue