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
38
gaia/apps/system/test/unit/fxa_test/fxa_error_overlay_test.js
Executable file
38
gaia/apps/system/test/unit/fxa_test/fxa_error_overlay_test.js
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
/* global FxaModuleErrorOverlay */
|
||||
'use strict';
|
||||
|
||||
require('/shared/js/utilities.js');
|
||||
requireApp('system/fxa/js/fxam_error_overlay.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
suite('FxA Module Error Overlay', function() {
|
||||
var overlay, title, message;
|
||||
suiteSetup(function() {
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
overlay = document.querySelector('#fxa-error-overlay');
|
||||
title = document.querySelector('#fxa-error-title');
|
||||
message = document.querySelector('#fxa-error-msg');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
document.body.innerHTML = '';
|
||||
overlay = null;
|
||||
title = null;
|
||||
message = null;
|
||||
});
|
||||
|
||||
test('show', function() {
|
||||
var customTitleL10nId = 'l10nId1';
|
||||
var customTextL10nId = 'l10nId2';
|
||||
FxaModuleErrorOverlay.show(customTitleL10nId, customTextL10nId);
|
||||
|
||||
assert.equal(title.getAttribute('data-l10n-id'), customTitleL10nId);
|
||||
assert.equal(message.getAttribute('data-l10n-id'), customTextL10nId);
|
||||
assert.ok(overlay.classList.contains('show'));
|
||||
});
|
||||
|
||||
test('hide', function() {
|
||||
FxaModuleErrorOverlay.hide();
|
||||
assert.isFalse(overlay.classList.contains('show'));
|
||||
});
|
||||
});
|
||||
76
gaia/apps/system/test/unit/fxa_test/fxam_errors_test.js
Executable file
76
gaia/apps/system/test/unit/fxa_test/fxam_errors_test.js
Executable file
|
|
@ -0,0 +1,76 @@
|
|||
/* global FxaModuleErrors, MockL10n */
|
||||
'use strict';
|
||||
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
requireApp('system/fxa/js/fxam_errors.js');
|
||||
|
||||
suite('Error manager', function() {
|
||||
var errorsObject = {
|
||||
CONNECTION_ERROR: {
|
||||
title: 'fxa-connection-error-title',
|
||||
message: 'fxa-connection-error-message'
|
||||
},
|
||||
RESET_PASSWORD_ERROR: {
|
||||
title: 'fxa-reset-password-error-title',
|
||||
message: 'fxa-reset-password-error-message'
|
||||
},
|
||||
INVALID_EMAIL: {
|
||||
title: 'fxa-invalid-email-title',
|
||||
message: 'fxa-invalid-email-message'
|
||||
},
|
||||
INVALID_PASSWORD: {
|
||||
title: 'fxa-invalid-password-title',
|
||||
message: 'fxa-invalid-password-message'
|
||||
},
|
||||
COPPA_ERROR: {
|
||||
title: 'fxa-coppa-failure-error-title',
|
||||
message: 'fxa-coppa-failure-error-message3'
|
||||
},
|
||||
COPPA_FTU_ERROR: {
|
||||
title: 'fxa-coppa-failure-error-title',
|
||||
message: 'fxa-coppa-ftu-error-message'
|
||||
},
|
||||
OFFLINE: {
|
||||
title: 'fxa-offline-error-title',
|
||||
message: 'fxa-offline-error-message'
|
||||
},
|
||||
UNKNOWN: {
|
||||
title: 'fxa-unknown-error-title',
|
||||
message: 'fxa-unknown-error-message'
|
||||
}
|
||||
};
|
||||
var response;
|
||||
var realL10n;
|
||||
suiteSetup(function() {
|
||||
realL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozL10n = realL10n;
|
||||
});
|
||||
|
||||
|
||||
setup(function() {
|
||||
response = {};
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
response = null;
|
||||
});
|
||||
|
||||
Object.keys(errorsObject).forEach(function(key) {
|
||||
test('Test ' + key, function() {
|
||||
response.error = key;
|
||||
var resp = FxaModuleErrors.responseToParams(response);
|
||||
|
||||
var message = errorsObject[key].message;
|
||||
|
||||
assert.deepEqual(resp, {
|
||||
title: errorsObject[key].title,
|
||||
message: message
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
34
gaia/apps/system/test/unit/fxa_test/fxam_overlay_test.js
Executable file
34
gaia/apps/system/test/unit/fxa_test/fxam_overlay_test.js
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
/* global FxaModuleOverlay */
|
||||
'use strict';
|
||||
|
||||
require('/shared/js/utilities.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_module.js');
|
||||
requireApp('system/fxa/js/fxam_overlay.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
suite('FxA Module overlay', function() {
|
||||
var overlay;
|
||||
suiteSetup(function() {
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
overlay = document.querySelector('#fxa-overlay');
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
document.body.innerHTML = '';
|
||||
overlay = null;
|
||||
});
|
||||
|
||||
test('show', function() {
|
||||
var customL10nId = 'l10nId1';
|
||||
FxaModuleOverlay.show(customL10nId);
|
||||
var messageContainer = document.querySelector('#fxa-overlay-msg');
|
||||
assert.equal(messageContainer.getAttribute('data-l10n-id'), customL10nId);
|
||||
assert.ok(overlay.classList.contains('show'));
|
||||
});
|
||||
|
||||
test('hide', function() {
|
||||
FxaModuleOverlay.hide();
|
||||
assert.isFalse(overlay.classList.contains('show'));
|
||||
});
|
||||
});
|
||||
14
gaia/apps/system/test/unit/fxa_test/load_element_helper.js
Executable file
14
gaia/apps/system/test/unit/fxa_test/load_element_helper.js
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
'use strict';
|
||||
/* exported LoadElementHelper */
|
||||
|
||||
require('/shared/js/html_imports.js');
|
||||
|
||||
var LoadElementHelper = {
|
||||
load: function(element) {
|
||||
var importHook = document.createElement('link');
|
||||
importHook.setAttribute('rel', 'import');
|
||||
importHook.setAttribute('href', '/fxa/elements/' + element);
|
||||
document.head.appendChild(importHook);
|
||||
}
|
||||
};
|
||||
|
||||
11
gaia/apps/system/test/unit/fxa_test/mock_fxam_errors.js
Executable file
11
gaia/apps/system/test/unit/fxa_test/mock_fxam_errors.js
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
'use strict';
|
||||
/* exported MockFxaModuleErrors */
|
||||
|
||||
var MockFxaModuleErrors = {
|
||||
responseToParams: function(response) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
61
gaia/apps/system/test/unit/fxa_test/mock_fxam_server_request.js
Executable file
61
gaia/apps/system/test/unit/fxa_test/mock_fxam_server_request.js
Executable file
|
|
@ -0,0 +1,61 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
'use strict';
|
||||
/* exported MockFxModuleServerRequest */
|
||||
|
||||
var MockFxModuleServerRequest = {
|
||||
error: false,
|
||||
registered: false,
|
||||
authenticated: false,
|
||||
accountCreated: false,
|
||||
resetSuccess: false,
|
||||
checkEmail: function(email, onsuccess, onerror) {
|
||||
if (!this.error) {
|
||||
setTimeout(function() {
|
||||
var params = {
|
||||
registered: this.registered
|
||||
};
|
||||
onsuccess && onsuccess(params);
|
||||
}.bind(this));
|
||||
} else {
|
||||
onerror && onerror();
|
||||
}
|
||||
},
|
||||
signIn: function(email, password, onsuccess, onerror) {
|
||||
if (!this.error) {
|
||||
setTimeout(function() {
|
||||
var params = {
|
||||
authenticated: this.authenticated
|
||||
};
|
||||
onsuccess && onsuccess(params);
|
||||
}.bind(this));
|
||||
} else {
|
||||
onerror && onerror();
|
||||
}
|
||||
},
|
||||
signUp: function(email, password, onsuccess, onerror) {
|
||||
if (!this.error) {
|
||||
setTimeout(function() {
|
||||
var params = {
|
||||
accountCreated: this.accountCreated
|
||||
};
|
||||
onsuccess && onsuccess(params);
|
||||
}.bind(this));
|
||||
} else {
|
||||
onerror && onerror();
|
||||
}
|
||||
},
|
||||
requestPasswordReset: function(email, onsuccess, onerror) {
|
||||
if (!this.error) {
|
||||
setTimeout(function() {
|
||||
var params = {
|
||||
success: this.resetSuccess
|
||||
};
|
||||
onsuccess && onsuccess(params);
|
||||
}.bind(this));
|
||||
} else {
|
||||
onerror && onerror();
|
||||
}
|
||||
}
|
||||
};
|
||||
42
gaia/apps/system/test/unit/fxa_test/mock_fxam_ui.js
Executable file
42
gaia/apps/system/test/unit/fxa_test/mock_fxam_ui.js
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
|
||||
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
|
||||
|
||||
'use strict';
|
||||
/* exported MockFxaModuleUI */
|
||||
|
||||
var MockFxaModuleUI = {
|
||||
maxSteps: null,
|
||||
init: function(flow) {
|
||||
|
||||
},
|
||||
setMaxSteps: function(num) {
|
||||
|
||||
},
|
||||
increaseMaxStepsBy: function(num) {
|
||||
},
|
||||
loadScreen: function(params) {
|
||||
|
||||
},
|
||||
_animate: function(from, to, back, callback) {
|
||||
|
||||
},
|
||||
_inTransition: function(elem) {
|
||||
|
||||
},
|
||||
progress: function(value) {
|
||||
|
||||
},
|
||||
setNextText: function(l10n) {
|
||||
|
||||
},
|
||||
disableNextButton: function() {
|
||||
|
||||
},
|
||||
enableNextButton: function() {
|
||||
|
||||
},
|
||||
disableDoneButton: function() {
|
||||
},
|
||||
enableDoneButton: function() {
|
||||
}
|
||||
};
|
||||
155
gaia/apps/system/test/unit/fxa_test/screens/fxam_coppa_test.js
Executable file
155
gaia/apps/system/test/unit/fxa_test/screens/fxam_coppa_test.js
Executable file
|
|
@ -0,0 +1,155 @@
|
|||
'use strict';
|
||||
|
||||
/* global MocksHelper, MockL10n, LoadElementHelper, HtmlImports, FxaModuleUI,
|
||||
FxaModuleCoppa, FxaModuleErrorOverlay, FxaModuleStates */
|
||||
|
||||
// Helper for loading the elements
|
||||
requireApp('/system/test/unit/fxa_test/load_element_helper.js');
|
||||
|
||||
// Real code
|
||||
require('/shared/js/utilities.js');
|
||||
requireApp('system/fxa/js/fxam_module.js');
|
||||
requireApp('system/fxa/js/fxam_states.js');
|
||||
requireApp('system/fxa/js/fxam_manager.js');
|
||||
requireApp('system/fxa/js/fxam_navigation.js');
|
||||
requireApp('system/fxa/js/fxam_overlay.js');
|
||||
requireApp('system/fxa/js/fxam_error_overlay.js');
|
||||
|
||||
// Mockuped code
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_ui.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_server_request.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_errors.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
// Code to test
|
||||
requireApp('system/fxa/js/screens/fxam_coppa.js');
|
||||
|
||||
var mocksHelperForCoppaModule = new MocksHelper([
|
||||
'FxaModuleUI',
|
||||
'FxModuleServerRequest',
|
||||
'FxaModuleErrors',
|
||||
'LazyLoader'
|
||||
]);
|
||||
|
||||
suite('Screen: COPPA', function() {
|
||||
var realL10n;
|
||||
suiteSetup(function(done) {
|
||||
realL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
|
||||
mocksHelperForCoppaModule.suiteSetup();
|
||||
// Load real HTML
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
// Load element to test
|
||||
LoadElementHelper.load('fxa-coppa.html');
|
||||
// Import the element and execute the right init
|
||||
HtmlImports.populate(function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
mocksHelperForCoppaModule.suiteTeardown();
|
||||
});
|
||||
|
||||
suite(' > Initial state', function() {
|
||||
var fxamUIEnableSpy;
|
||||
var fxamUIIncStepsSpy;
|
||||
setup(function() {
|
||||
fxamUIEnableSpy = this.sinon.spy(FxaModuleUI, 'enableNextButton');
|
||||
fxamUIIncStepsSpy = this.sinon.spy(FxaModuleUI, 'increaseMaxStepsBy');
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fxamUIEnableSpy = null;
|
||||
fxamUIIncStepsSpy = null;
|
||||
});
|
||||
|
||||
test(' > FxaModuleUI not called', function(done) {
|
||||
assert.isFalse(fxamUIEnableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIIncStepsSpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > Initiated state', function() {
|
||||
var fxamUIEnableSpy;
|
||||
var fxamUIIncStepsSpy;
|
||||
setup(function() {
|
||||
fxamUIEnableSpy = this.sinon.spy(FxaModuleUI, 'enableNextButton');
|
||||
fxamUIIncStepsSpy = this.sinon.spy(FxaModuleUI, 'increaseMaxStepsBy');
|
||||
FxaModuleCoppa.init();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fxamUIEnableSpy = null;
|
||||
fxamUIIncStepsSpy = null;
|
||||
});
|
||||
|
||||
test(' > FxaModuleUI called', function(done) {
|
||||
assert.isFalse(fxamUIEnableSpy.calledOnce);
|
||||
assert.ok(fxamUIIncStepsSpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
|
||||
test(' > We only populate the age selection element once', function() {
|
||||
var fxaAgeSelect = document.getElementById('fxa-age-select');
|
||||
var selectLength = fxaAgeSelect.length;
|
||||
FxaModuleCoppa.init();
|
||||
assert.equal(selectLength, fxaAgeSelect.length);
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > COPPA error', function() {
|
||||
var fxaAgeSelect;
|
||||
var showErrorOverlaySpy;
|
||||
var showErrorResponse;
|
||||
setup(function() {
|
||||
fxaAgeSelect = document.getElementById('fxa-age-select');
|
||||
showErrorOverlaySpy = this.sinon.spy(FxaModuleErrorOverlay, 'show');
|
||||
showErrorResponse = this.sinon.spy(FxaModuleCoppa, 'showErrorResponse');
|
||||
fxaAgeSelect.value = new Date().getFullYear();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fxaAgeSelect = null;
|
||||
showErrorOverlaySpy = null;
|
||||
showErrorResponse = null;
|
||||
});
|
||||
|
||||
test(' > COPPA error shown', function(done) {
|
||||
FxaModuleCoppa.onNext(function() { });
|
||||
setTimeout(function() {
|
||||
assert.ok(showErrorOverlaySpy.calledOnce);
|
||||
assert.ok(showErrorResponse.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > COPPA success', function() {
|
||||
var fxaAgeSelect;
|
||||
var MINIMUM_AGE = 13;
|
||||
setup(function() {
|
||||
fxaAgeSelect = document.getElementById('fxa-age-select');
|
||||
fxaAgeSelect.value = new Date().getFullYear() - MINIMUM_AGE;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fxaAgeSelect = null;
|
||||
});
|
||||
|
||||
test(' > COPPA success', function(done) {
|
||||
FxaModuleCoppa.onNext(function(a) {
|
||||
assert.deepEqual(a, FxaModuleStates.SET_PASSWORD);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
305
gaia/apps/system/test/unit/fxa_test/screens/fxam_enter_email_test.js
Executable file
305
gaia/apps/system/test/unit/fxa_test/screens/fxam_enter_email_test.js
Executable file
|
|
@ -0,0 +1,305 @@
|
|||
/* global FxaModuleEnterEmail, FxaModuleErrorOverlay, FxaModuleOverlay,
|
||||
FxModuleServerRequest, FxaModuleStates, FxaModuleUI,
|
||||
HtmlImports, LoadElementHelper, MocksHelper, MockL10n */
|
||||
'use strict';
|
||||
|
||||
// Helper for loading the elements
|
||||
requireApp('/system/test/unit/fxa_test/load_element_helper.js');
|
||||
|
||||
// Real code
|
||||
require('/shared/js/utilities.js');
|
||||
requireApp('system/fxa/js/fxam_module.js');
|
||||
requireApp('system/fxa/js/fxam_states.js');
|
||||
requireApp('system/fxa/js/fxam_manager.js');
|
||||
requireApp('system/fxa/js/fxam_overlay.js');
|
||||
requireApp('system/js/browser_frame.js');
|
||||
requireApp('system/js/entry_sheet.js');
|
||||
requireApp('system/fxa/js/fxam_error_overlay.js');
|
||||
|
||||
// Mockuped code
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_ui.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_ui.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_server_request.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_server_request.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_errors.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_errors.js');
|
||||
|
||||
require('/shared/js/lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
// Code to test
|
||||
requireApp('system/fxa/js/screens/fxam_enter_email.js');
|
||||
|
||||
var mocksHelperForEmailModule = new MocksHelper([
|
||||
'LazyLoader',
|
||||
'FxaModuleUI',
|
||||
'FxModuleServerRequest',
|
||||
'FxaModuleErrors'
|
||||
]);
|
||||
|
||||
suite('Screen: Enter email', function() {
|
||||
var realL10n;
|
||||
suiteSetup(function(done) {
|
||||
realL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
// we have to special-case the l10n stub for the fxa-notice element
|
||||
var l10nStub = sinon.stub(navigator.mozL10n, 'get');
|
||||
var noticeStr = 'By proceeding, I agree to the {{ tos }} and {{ pn }} ' +
|
||||
'Firefox cloud services';
|
||||
l10nStub.withArgs('fxa-notice')
|
||||
.returns(noticeStr);
|
||||
|
||||
mocksHelperForEmailModule.suiteSetup();
|
||||
// Load real HTML
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
// Load element to test
|
||||
LoadElementHelper.load('fxa-email.html');
|
||||
// Import the element and execute the right init
|
||||
HtmlImports.populate(function() {
|
||||
FxaModuleEnterEmail.init();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
mocksHelperForEmailModule.suiteTeardown();
|
||||
});
|
||||
|
||||
suite(' > External links EntrySheet ', function() {
|
||||
var privacyLink, termsLink, showErrorOverlaySpy, clickEvent,
|
||||
closeEntrySheetSpy, mockEntrySheet;
|
||||
|
||||
setup(function() {
|
||||
privacyLink = document.getElementById('fxa-privacy');
|
||||
termsLink = document.getElementById('fxa-terms');
|
||||
showErrorOverlaySpy = this.sinon.spy(FxaModuleErrorOverlay, 'show');
|
||||
clickEvent = new MouseEvent('click', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
view: window
|
||||
});
|
||||
closeEntrySheetSpy = sinon.spy();
|
||||
mockEntrySheet = {close: closeEntrySheetSpy};
|
||||
FxaModuleEnterEmail.entrySheet = mockEntrySheet;
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
FxaModuleErrorOverlay.show.restore();
|
||||
privacyLink = termsLink = showErrorOverlaySpy = clickEvent = null;
|
||||
FxaModuleEnterEmail.entrySheet = null;
|
||||
});
|
||||
|
||||
test(' > Should not be shown if navigator.onLine is false', function() {
|
||||
var realOnLine = Object.getOwnPropertyDescriptor(navigator, 'onLine');
|
||||
Object.defineProperty(navigator, 'onLine', {
|
||||
configurable: true,
|
||||
get: function() {
|
||||
return false;
|
||||
},
|
||||
set: function() {}
|
||||
});
|
||||
var showErrorSpy = this.sinon.spy(FxaModuleEnterEmail,
|
||||
'showErrorResponse');
|
||||
privacyLink.dispatchEvent(clickEvent);
|
||||
termsLink.dispatchEvent(clickEvent);
|
||||
assert.ok(showErrorSpy.calledTwice);
|
||||
FxaModuleEnterEmail.showErrorResponse.restore();
|
||||
realOnLine ? Object.defineProperty(navigator, 'onLine', realOnLine) :
|
||||
delete navigator.onLine;
|
||||
});
|
||||
|
||||
test(' > Should be dismissed on "home" event', function() {
|
||||
window.dispatchEvent(new CustomEvent('home'));
|
||||
assert.ok(closeEntrySheetSpy.calledOnce);
|
||||
assert.isNull(FxaModuleEnterEmail.entrySheet);
|
||||
});
|
||||
|
||||
test(' > Should be dismissed on "holdhome" event', function() {
|
||||
window.dispatchEvent(new CustomEvent('holdhome'));
|
||||
assert.ok(closeEntrySheetSpy.calledOnce);
|
||||
assert.isNull(FxaModuleEnterEmail.entrySheet);
|
||||
});
|
||||
|
||||
test(' > Should be dismissed on "activityrequesting" event', function() {
|
||||
window.dispatchEvent(new CustomEvent('activityrequesting'));
|
||||
assert.ok(closeEntrySheetSpy.calledOnce);
|
||||
assert.isNull(FxaModuleEnterEmail.entrySheet);
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > email input ', function() {
|
||||
var emailInput;
|
||||
var fxamUIDisableSpy, fxamUIEnableSpy;
|
||||
var inputEvent;
|
||||
setup(function() {
|
||||
emailInput = document.getElementById('fxa-email-input');
|
||||
fxamUIDisableSpy = this.sinon.spy(FxaModuleUI, 'disableNextButton');
|
||||
fxamUIEnableSpy = this.sinon.spy(FxaModuleUI, 'enableNextButton');
|
||||
inputEvent = new CustomEvent(
|
||||
'input',
|
||||
{
|
||||
bubbles: true
|
||||
}
|
||||
);
|
||||
mocksHelperForEmailModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
emailInput = null;
|
||||
fxamUIDisableSpy = null;
|
||||
fxamUIEnableSpy = null;
|
||||
mocksHelperForEmailModule.teardown();
|
||||
});
|
||||
|
||||
test(' > Disabled button at the beginning', function() {
|
||||
emailInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIDisableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIEnableSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Enable when ready', function() {
|
||||
emailInput.value = 'validemail@mozilla.es';
|
||||
emailInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIDisableSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Changes in the email input is tracked properly', function() {
|
||||
emailInput.value = 'validemail@mozilla.es';
|
||||
emailInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.called);
|
||||
assert.isFalse(fxamUIDisableSpy.calledOnce);
|
||||
|
||||
// Change the value on the fly
|
||||
emailInput.value = 'validemailmozilla.es';
|
||||
emailInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
assert.ok(fxamUIDisableSpy.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > onNext ', function() {
|
||||
var showOverlaySpy, showErrorOverlaySpy, hideOverlaySpy;
|
||||
setup(function() {
|
||||
showErrorOverlaySpy = this.sinon.spy(FxaModuleErrorOverlay, 'show');
|
||||
showOverlaySpy = this.sinon.spy(FxaModuleOverlay, 'show');
|
||||
hideOverlaySpy = this.sinon.spy(FxaModuleOverlay, 'hide');
|
||||
mocksHelperForEmailModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
showErrorOverlaySpy = null;
|
||||
showOverlaySpy = null;
|
||||
hideOverlaySpy = null;
|
||||
mocksHelperForEmailModule.teardown();
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.registered = false;
|
||||
});
|
||||
|
||||
test(' > Overlay shown', function(done) {
|
||||
FxaModuleEnterEmail.onNext(function() {
|
||||
assert.ok(showOverlaySpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > checkEmail called', function() {
|
||||
var checkEmailSpy;
|
||||
setup(function() {
|
||||
checkEmailSpy = this.sinon.spy(FxModuleServerRequest, 'checkEmail');
|
||||
mocksHelperForEmailModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
checkEmailSpy = null;
|
||||
mocksHelperForEmailModule.teardown();
|
||||
});
|
||||
|
||||
test(' > Check email', function(done) {
|
||||
FxaModuleEnterEmail.onNext(function() {
|
||||
assert.ok(checkEmailSpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test(' > Network error', function() {
|
||||
FxModuleServerRequest.error = true;
|
||||
FxaModuleEnterEmail.onNext(function() {});
|
||||
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.ok(showErrorOverlaySpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Email registered (Sign IN)', function(done) {
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.registered = true;
|
||||
FxaModuleEnterEmail.onNext(function(params) {
|
||||
assert.equal(params, FxaModuleStates.ENTER_PASSWORD);
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.isFalse(showErrorOverlaySpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test(' > Email NOT registered (Sign UP)', function(done) {
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.registered = false;
|
||||
FxaModuleEnterEmail.onNext(function(params) {
|
||||
assert.equal(params, FxaModuleStates.COPPA);
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.isFalse(showErrorOverlaySpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test(' > Email NOT registered inside FTU (Sign UP)', function(done) {
|
||||
FxaModuleEnterEmail.isFTU = true;
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.registered = false;
|
||||
FxaModuleEnterEmail.onNext(function(params) {
|
||||
assert.equal(params, FxaModuleStates.SET_PASSWORD);
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.isFalse(showErrorOverlaySpy.calledOnce);
|
||||
FxaModuleEnterEmail.isFTU = null;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
suite(' > onBack ', function() {
|
||||
var fxamUIEnableSpy;
|
||||
setup(function() {
|
||||
fxamUIEnableSpy = this.sinon.spy(FxaModuleUI, 'enableNextButton');
|
||||
mocksHelperForEmailModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
fxamUIEnableSpy = null;
|
||||
mocksHelperForEmailModule.teardown();
|
||||
});
|
||||
|
||||
test(' > Enable "next" button when going back', function() {
|
||||
FxaModuleEnterEmail.onBack();
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
246
gaia/apps/system/test/unit/fxa_test/screens/fxam_enter_password_test.js
Executable file
246
gaia/apps/system/test/unit/fxa_test/screens/fxam_enter_password_test.js
Executable file
|
|
@ -0,0 +1,246 @@
|
|||
/* global FxaModuleEnterPassword, FxaModuleErrorOverlay, FxaModuleOverlay,
|
||||
FxaModuleUI, FxModuleServerRequest, FxaModuleStates,
|
||||
HtmlImports, LoadElementHelper, MocksHelper, MockL10n */
|
||||
'use strict';
|
||||
|
||||
// Helper for loading the elements
|
||||
requireApp('/system/test/unit/fxa_test/load_element_helper.js');
|
||||
|
||||
// Real code
|
||||
require('/shared/js/utilities.js');
|
||||
requireApp('system/fxa/js/fxam_module.js');
|
||||
requireApp('system/fxa/js/fxam_states.js');
|
||||
requireApp('system/fxa/js/fxam_manager.js');
|
||||
requireApp('system/fxa/js/fxam_overlay.js');
|
||||
requireApp('system/fxa/js/fxam_error_overlay.js');
|
||||
|
||||
// Mockuped code
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_ui.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_ui.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_server_request.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_server_request.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_errors.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_errors.js');
|
||||
|
||||
requireApp('/system/test/unit/mock_ftu_launcher.js');
|
||||
|
||||
require('/shared/js/lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
// Code to test
|
||||
requireApp('system/fxa/js/screens/fxam_enter_password.js');
|
||||
|
||||
var mocksHelperForEnterPasswordModule = new MocksHelper([
|
||||
'LazyLoader',
|
||||
'FxaModuleUI',
|
||||
'FxModuleServerRequest',
|
||||
'FxaModuleErrors',
|
||||
'FtuLauncher'
|
||||
]);
|
||||
|
||||
suite('Screen: Enter password', function() {
|
||||
var realL10n;
|
||||
suiteSetup(function(done) {
|
||||
realL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
|
||||
mocksHelperForEnterPasswordModule.suiteSetup();
|
||||
// Load real HTML
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
// Load element to test
|
||||
LoadElementHelper.load('fxa-enter-password.html');
|
||||
// Import the element
|
||||
HtmlImports.populate(done);
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
mocksHelperForEnterPasswordModule.suiteTeardown();
|
||||
});
|
||||
|
||||
// extracted to allow isFTU option to be passed into Module.init
|
||||
var passwordInput, forgotPasswordEl;
|
||||
var fxamUIDisableSpy, fxamUIEnableSpy, showErrorOverlaySpy, resetSpy;
|
||||
var inputEvent, clickEvent;
|
||||
function initFixtures(options) {
|
||||
/* jshint validthis: true */
|
||||
FxaModuleEnterPassword.init(options);
|
||||
passwordInput = document.getElementById('fxa-pw-input');
|
||||
fxamUIDisableSpy = this.sinon.spy(FxaModuleUI, 'disableNextButton');
|
||||
fxamUIEnableSpy = this.sinon.spy(FxaModuleUI, 'enableNextButton');
|
||||
showErrorOverlaySpy = this.sinon.spy(FxaModuleErrorOverlay, 'show');
|
||||
resetSpy = this.sinon.spy(FxModuleServerRequest, 'requestPasswordReset');
|
||||
forgotPasswordEl = document.getElementById('fxa-forgot-password');
|
||||
inputEvent = new CustomEvent(
|
||||
'input',
|
||||
{
|
||||
bubbles: true
|
||||
}
|
||||
);
|
||||
clickEvent = new CustomEvent(
|
||||
'click',
|
||||
{
|
||||
bubbles: true
|
||||
}
|
||||
);
|
||||
mocksHelperForEnterPasswordModule.setup();
|
||||
}
|
||||
|
||||
function destroyFixtures() {
|
||||
passwordInput = null;
|
||||
forgotPasswordEl = null;
|
||||
fxamUIDisableSpy = null;
|
||||
fxamUIEnableSpy = null;
|
||||
showErrorOverlaySpy = null;
|
||||
resetSpy = null;
|
||||
mocksHelperForEnterPasswordModule.teardown();
|
||||
FxModuleServerRequest.resetSuccess = false;
|
||||
}
|
||||
|
||||
suite(' > FTU password input ', function() {
|
||||
setup(function() {
|
||||
initFixtures.call(this, {
|
||||
isftu: true,
|
||||
email: 'dummy@account'
|
||||
});
|
||||
});
|
||||
teardown(destroyFixtures);
|
||||
|
||||
test(' > Forgot password link shows error overlay when in FTU', function() {
|
||||
forgotPasswordEl.dispatchEvent(clickEvent);
|
||||
assert.ok(showErrorOverlaySpy.calledOnce);
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > password input ', function() {
|
||||
|
||||
setup(function() {
|
||||
initFixtures.call(this, {
|
||||
email: 'dummy@account'
|
||||
});
|
||||
});
|
||||
teardown(destroyFixtures);
|
||||
|
||||
test(' > Disabled button at the beginning', function() {
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIDisableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIEnableSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Enable when ready', function() {
|
||||
passwordInput.value = 'myawesomepassword';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIDisableSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Forgot password link opens web flow when not in FTU', function() {
|
||||
FxModuleServerRequest.resetSuccess = true;
|
||||
forgotPasswordEl.dispatchEvent(clickEvent);
|
||||
assert.ok(resetSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Changes in the password input are tracked properly', function() {
|
||||
passwordInput.value = 'longpassword';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.called);
|
||||
assert.isFalse(fxamUIDisableSpy.calledOnce);
|
||||
|
||||
// Change the value on the fly
|
||||
passwordInput.value = 'short';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
assert.ok(fxamUIDisableSpy.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > onNext ', function() {
|
||||
var showOverlaySpy, showErrorOverlaySpy, hideOverlaySpy;
|
||||
setup(function() {
|
||||
showErrorOverlaySpy = this.sinon.spy(FxaModuleErrorOverlay, 'show');
|
||||
showOverlaySpy = this.sinon.spy(FxaModuleOverlay, 'show');
|
||||
hideOverlaySpy = this.sinon.spy(FxaModuleOverlay, 'hide');
|
||||
mocksHelperForEnterPasswordModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
showErrorOverlaySpy = null;
|
||||
showOverlaySpy = null;
|
||||
hideOverlaySpy = null;
|
||||
mocksHelperForEnterPasswordModule.teardown();
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.registered = false;
|
||||
});
|
||||
|
||||
test(' > Overlay shown', function(done) {
|
||||
FxaModuleEnterPassword.onNext(function() {
|
||||
assert.ok(showOverlaySpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > signIn called', function() {
|
||||
var signInSpy;
|
||||
setup(function() {
|
||||
signInSpy =
|
||||
this.sinon.spy(FxModuleServerRequest, 'signIn');
|
||||
mocksHelperForEnterPasswordModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
signInSpy = null;
|
||||
mocksHelperForEnterPasswordModule.teardown();
|
||||
});
|
||||
|
||||
test(' > Check password', function(done) {
|
||||
FxaModuleEnterPassword.onNext(function() {
|
||||
assert.ok(signInSpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test(' > Sign in error', function() {
|
||||
FxModuleServerRequest.error = true;
|
||||
FxaModuleEnterPassword.onNext(function() {});
|
||||
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.ok(showErrorOverlaySpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Existing user confirmed', function(done) {
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.authenticated = true;
|
||||
FxaModuleEnterPassword.onNext(function(params) {
|
||||
assert.equal(params, FxaModuleStates.SIGNIN_SUCCESS);
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.isFalse(showErrorOverlaySpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test(' > Existing user, but not confirmed', function(done) {
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.authenticated = false;
|
||||
FxaModuleEnterPassword.onNext(function(params) {
|
||||
assert.equal(params, FxaModuleStates.SIGNUP_SUCCESS);
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.isFalse(showErrorOverlaySpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
182
gaia/apps/system/test/unit/fxa_test/screens/fxam_refresh_auth_test.js
Executable file
182
gaia/apps/system/test/unit/fxa_test/screens/fxam_refresh_auth_test.js
Executable file
|
|
@ -0,0 +1,182 @@
|
|||
/* global FxaModuleErrorOverlay, FxaModuleOverlay, FxaModuleRefreshAuth,
|
||||
FxModuleServerRequest, FxaModuleUI, HtmlImports, LoadElementHelper,
|
||||
MocksHelper, MockL10n */
|
||||
'use strict';
|
||||
|
||||
// Helper for loading the elements
|
||||
requireApp('/system/test/unit/fxa_test/load_element_helper.js');
|
||||
|
||||
// Real code
|
||||
require('/shared/js/utilities.js');
|
||||
requireApp('system/fxa/js/fxam_module.js');
|
||||
requireApp('system/fxa/js/fxam_states.js');
|
||||
requireApp('system/fxa/js/fxam_manager.js');
|
||||
requireApp('system/fxa/js/fxam_overlay.js');
|
||||
requireApp('system/fxa/js/fxam_error_overlay.js');
|
||||
|
||||
// Mockuped code
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_ui.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_ui.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_server_request.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_server_request.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_errors.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_errors.js');
|
||||
|
||||
require('/shared/js/lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
// Code to test
|
||||
requireApp('system/fxa/js/screens/fxam_refresh_auth.js');
|
||||
|
||||
var mocksHelperForRefreshAuthModule = new MocksHelper([
|
||||
'LazyLoader',
|
||||
'FxaModuleUI',
|
||||
'FxModuleServerRequest',
|
||||
'FxaModuleErrors'
|
||||
]);
|
||||
|
||||
suite('Screen: Enter password', function() {
|
||||
var realL10n;
|
||||
suiteSetup(function(done) {
|
||||
realL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
|
||||
mocksHelperForRefreshAuthModule.suiteSetup();
|
||||
// Load real HTML
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
// Load element to test
|
||||
LoadElementHelper.load('fxa-refresh-auth.html');
|
||||
// Import the element and execute the right init
|
||||
HtmlImports.populate(function() {
|
||||
FxaModuleRefreshAuth.init();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
mocksHelperForRefreshAuthModule.suiteTeardown();
|
||||
});
|
||||
|
||||
suite(' > password input ', function() {
|
||||
var passwordInput;
|
||||
var fxamUIDisableSpy, fxamUIEnableSpy;
|
||||
var inputEvent;
|
||||
setup(function() {
|
||||
passwordInput = document.getElementById('fxa-pw-input-refresh');
|
||||
fxamUIDisableSpy = this.sinon.spy(FxaModuleUI, 'disableDoneButton');
|
||||
fxamUIEnableSpy = this.sinon.spy(FxaModuleUI, 'enableDoneButton');
|
||||
inputEvent = new CustomEvent('input', {
|
||||
bubbles: true
|
||||
});
|
||||
mocksHelperForRefreshAuthModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
passwordInput = null;
|
||||
fxamUIDisableSpy = null;
|
||||
fxamUIEnableSpy = null;
|
||||
mocksHelperForRefreshAuthModule.teardown();
|
||||
});
|
||||
|
||||
test(' > Disabled button at the beginning', function() {
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIDisableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIEnableSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Enable when ready', function() {
|
||||
passwordInput.value = 'myawesomepassword';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIDisableSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Changes in the password input are tracked properly', function() {
|
||||
passwordInput.value = 'longpassword';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.called);
|
||||
assert.isFalse(fxamUIDisableSpy.calledOnce);
|
||||
|
||||
// Change the value on the fly
|
||||
passwordInput.value = 'short';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
assert.ok(fxamUIDisableSpy.called);
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > onDone ', function() {
|
||||
var showOverlaySpy, showErrorOverlaySpy, hideOverlaySpy;
|
||||
setup(function() {
|
||||
showErrorOverlaySpy = this.sinon.spy(FxaModuleErrorOverlay, 'show');
|
||||
showOverlaySpy = this.sinon.spy(FxaModuleOverlay, 'show');
|
||||
hideOverlaySpy = this.sinon.spy(FxaModuleOverlay, 'hide');
|
||||
mocksHelperForRefreshAuthModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
showErrorOverlaySpy = null;
|
||||
showOverlaySpy = null;
|
||||
hideOverlaySpy = null;
|
||||
mocksHelperForRefreshAuthModule.teardown();
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.registered = false;
|
||||
});
|
||||
|
||||
test(' > Overlay shown', function(done) {
|
||||
FxaModuleRefreshAuth.onDone(function() {
|
||||
assert.ok(showOverlaySpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suite(' > signIn called', function() {
|
||||
var signInSpy;
|
||||
setup(function() {
|
||||
signInSpy =
|
||||
this.sinon.spy(FxModuleServerRequest, 'signIn');
|
||||
mocksHelperForRefreshAuthModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
signInSpy = null;
|
||||
mocksHelperForRefreshAuthModule.teardown();
|
||||
});
|
||||
|
||||
test(' > Check password', function(done) {
|
||||
FxaModuleRefreshAuth.onDone(function() {
|
||||
assert.ok(signInSpy.calledOnce);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test(' > Sign in error', function() {
|
||||
FxModuleServerRequest.error = true;
|
||||
FxaModuleRefreshAuth.onDone(function() {});
|
||||
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.ok(showErrorOverlaySpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Existing user confirmed', function(done) {
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.authenticated = true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
177
gaia/apps/system/test/unit/fxa_test/screens/fxam_set_password_test.js
Executable file
177
gaia/apps/system/test/unit/fxa_test/screens/fxam_set_password_test.js
Executable file
|
|
@ -0,0 +1,177 @@
|
|||
/* global FxaModuleErrorOverlay, FxaModuleOverlay, FxaModuleUI,
|
||||
FxaModuleSetPassword, FxModuleServerRequest, FxaModuleStates,
|
||||
HtmlImports, LoadElementHelper, MocksHelper, MockL10n */
|
||||
'use strict';
|
||||
|
||||
// Helper for loading the elements
|
||||
requireApp('/system/test/unit/fxa_test/load_element_helper.js');
|
||||
|
||||
// Real code
|
||||
require('/shared/js/utilities.js');
|
||||
requireApp('system/fxa/js/fxam_module.js');
|
||||
requireApp('system/fxa/js/fxam_states.js');
|
||||
requireApp('system/fxa/js/fxam_manager.js');
|
||||
requireApp('system/fxa/js/fxam_overlay.js');
|
||||
requireApp('system/fxa/js/fxam_error_overlay.js');
|
||||
|
||||
// Mockuped code
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_ui.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_ui.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_server_request.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_server_request.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_errors.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_errors.js');
|
||||
|
||||
require('/shared/js/lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
// Code to test
|
||||
requireApp('system/fxa/js/screens/fxam_set_password.js');
|
||||
|
||||
var mocksHelperForSetPasswordModule = new MocksHelper([
|
||||
'LazyLoader',
|
||||
'FxaModuleUI',
|
||||
'FxModuleServerRequest',
|
||||
'FxaModuleErrors'
|
||||
]);
|
||||
|
||||
suite('Screen: Set password', function() {
|
||||
var realL10n;
|
||||
suiteSetup(function(done) {
|
||||
realL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
|
||||
mocksHelperForSetPasswordModule.suiteSetup();
|
||||
// Load real HTML
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
// Load element to test
|
||||
LoadElementHelper.load('fxa-set-password.html');
|
||||
// Import the element and execute the right init
|
||||
HtmlImports.populate(function() {
|
||||
FxaModuleSetPassword.init();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
mocksHelperForSetPasswordModule.suiteTeardown();
|
||||
});
|
||||
|
||||
suite(' > password input ', function() {
|
||||
var passwordInput;
|
||||
var fxamUIDisableSpy, fxamUIEnableSpy;
|
||||
var inputEvent;
|
||||
setup(function() {
|
||||
passwordInput = document.getElementById('fxa-pw-set-input');
|
||||
fxamUIDisableSpy = this.sinon.spy(FxaModuleUI, 'disableNextButton');
|
||||
fxamUIEnableSpy = this.sinon.spy(FxaModuleUI, 'enableNextButton');
|
||||
inputEvent = new CustomEvent(
|
||||
'input',
|
||||
{
|
||||
bubbles: true
|
||||
}
|
||||
);
|
||||
mocksHelperForSetPasswordModule.setup();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
passwordInput = null;
|
||||
fxamUIDisableSpy = null;
|
||||
fxamUIEnableSpy = null;
|
||||
mocksHelperForSetPasswordModule.teardown();
|
||||
});
|
||||
|
||||
test(' > Disabled button at the beginning', function() {
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
assert.ok(true);
|
||||
|
||||
assert.ok(fxamUIDisableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIEnableSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Enable when ready', function() {
|
||||
passwordInput.value = 'myawesomepassword';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
assert.isFalse(fxamUIDisableSpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Changes in the password input are tracked properly', function() {
|
||||
passwordInput.value = 'longpassword';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.called);
|
||||
assert.isFalse(fxamUIDisableSpy.calledOnce);
|
||||
|
||||
// Change the value on the fly
|
||||
passwordInput.value = 'short';
|
||||
passwordInput.dispatchEvent(inputEvent);
|
||||
|
||||
assert.ok(fxamUIEnableSpy.calledOnce);
|
||||
assert.ok(fxamUIDisableSpy.called);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite(' > onNext ', function() {
|
||||
var showOverlaySpy, showErrorOverlaySpy, hideOverlaySpy;
|
||||
setup(function() {
|
||||
showErrorOverlaySpy = this.sinon.spy(FxaModuleErrorOverlay, 'show');
|
||||
showOverlaySpy = this.sinon.spy(FxaModuleOverlay, 'show');
|
||||
hideOverlaySpy = this.sinon.spy(FxaModuleOverlay, 'hide');
|
||||
mocksHelperForSetPasswordModule.setup();
|
||||
|
||||
this.sinon.useFakeTimers();
|
||||
});
|
||||
|
||||
teardown(function() {
|
||||
showErrorOverlaySpy = null;
|
||||
showOverlaySpy = null;
|
||||
hideOverlaySpy = null;
|
||||
mocksHelperForSetPasswordModule.teardown();
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.registered = false;
|
||||
});
|
||||
|
||||
test(' > Overlay shown', function() {
|
||||
FxaModuleSetPassword.onNext();
|
||||
assert.ok(showOverlaySpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Sign up called', function() {
|
||||
this.sinon.stub(FxModuleServerRequest, 'signUp');
|
||||
FxaModuleSetPassword.onNext();
|
||||
sinon.assert.called(FxModuleServerRequest.signUp);
|
||||
});
|
||||
|
||||
test(' > Sign up error', function() {
|
||||
FxModuleServerRequest.error = true;
|
||||
FxaModuleSetPassword.onNext();
|
||||
|
||||
assert.ok(hideOverlaySpy.calledOnce);
|
||||
assert.ok(showErrorOverlaySpy.calledOnce);
|
||||
});
|
||||
|
||||
test(' > Sign up working', function() {
|
||||
FxModuleServerRequest.error = false;
|
||||
FxModuleServerRequest.accountCreated = true;
|
||||
var nextStep = sinon.stub();
|
||||
FxaModuleSetPassword.onNext(nextStep);
|
||||
this.sinon.clock.tick(); // FxModuleServerRequest mock uses setTimeout
|
||||
|
||||
sinon.assert.calledWith(nextStep, FxaModuleStates.SIGNUP_SUCCESS);
|
||||
sinon.assert.calledOnce(hideOverlaySpy);
|
||||
sinon.assert.notCalled(showErrorOverlaySpy);
|
||||
});
|
||||
});
|
||||
});
|
||||
65
gaia/apps/system/test/unit/fxa_test/screens/fxam_signin_success_test.js
Executable file
65
gaia/apps/system/test/unit/fxa_test/screens/fxam_signin_success_test.js
Executable file
|
|
@ -0,0 +1,65 @@
|
|||
/* global FxaModuleSigninSuccess, FxaModuleStates,
|
||||
HtmlImports, LoadElementHelper, MocksHelper, MockL10n */
|
||||
'use strict';
|
||||
|
||||
// Helper for loading the elements
|
||||
requireApp('/system/test/unit/fxa_test/load_element_helper.js');
|
||||
|
||||
// Real code
|
||||
require('/shared/js/utilities.js');
|
||||
requireApp('system/fxa/js/fxam_module.js');
|
||||
requireApp('system/fxa/js/fxam_states.js');
|
||||
|
||||
// Mockuped code
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_ui.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_ui.js');
|
||||
|
||||
require('/shared/js/lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
// Code to test
|
||||
requireApp('system/fxa/js/screens/fxam_signin_success.js');
|
||||
|
||||
var mocksHelperForSigninSuccess = new MocksHelper([
|
||||
'LazyLoader',
|
||||
'FxaModuleUI'
|
||||
]);
|
||||
|
||||
suite('Screen: Signin Success', function() {
|
||||
var realL10n;
|
||||
suiteSetup(function(done) {
|
||||
realL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
|
||||
mocksHelperForSigninSuccess.suiteSetup();
|
||||
// Load real HTML
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
// Load element to test
|
||||
LoadElementHelper.load('fxa-signin-success.html');
|
||||
// Import the element and execute the right init
|
||||
HtmlImports.populate(function() {
|
||||
FxaModuleSigninSuccess.init();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
mocksHelperForSigninSuccess.suiteTeardown();
|
||||
});
|
||||
|
||||
|
||||
suite(' > onNext ', function() {
|
||||
test(' > go to DONE Step', function() {
|
||||
FxaModuleSigninSuccess.onNext(function(nextState) {
|
||||
assert.equal(nextState, FxaModuleStates.DONE);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
81
gaia/apps/system/test/unit/fxa_test/screens/fxam_signup_success_test.js
Executable file
81
gaia/apps/system/test/unit/fxa_test/screens/fxam_signup_success_test.js
Executable file
|
|
@ -0,0 +1,81 @@
|
|||
/* global FxaModuleSignupSuccess, FxaModuleStates,
|
||||
HtmlImports, LoadElementHelper, MocksHelper, MockL10n */
|
||||
'use strict';
|
||||
|
||||
// Helper for loading the elements
|
||||
requireApp('/system/test/unit/fxa_test/load_element_helper.js');
|
||||
|
||||
// Real code
|
||||
require('/shared/js/utilities.js');
|
||||
requireApp('system/fxa/js/fxam_module.js');
|
||||
requireApp('system/fxa/js/fxam_states.js');
|
||||
|
||||
// Mockuped code
|
||||
require('/shared/test/unit/mocks/mock_l10n.js');
|
||||
|
||||
requireApp('system/fxa/js/fxam_ui.js');
|
||||
requireApp('/system/test/unit/fxa_test/mock_fxam_ui.js');
|
||||
|
||||
require('/shared/js/lazy_loader.js');
|
||||
require('/shared/test/unit/mocks/mock_lazy_loader.js');
|
||||
|
||||
require('/shared/test/unit/mocks/mocks_helper.js');
|
||||
require('/shared/test/unit/load_body_html_helper.js');
|
||||
|
||||
// Code to test
|
||||
requireApp('system/fxa/js/screens/fxam_signup_success.js');
|
||||
|
||||
var mocksHelperForSignupSuccess = new MocksHelper([
|
||||
'LazyLoader',
|
||||
'FxaModuleUI'
|
||||
]);
|
||||
|
||||
suite('Screen: Signup Success', function() {
|
||||
var emailTest = 'testuser@testuser.com';
|
||||
var realL10n;
|
||||
suiteSetup(function(done) {
|
||||
realL10n = navigator.mozL10n;
|
||||
navigator.mozL10n = MockL10n;
|
||||
var l10nStub = sinon.stub(navigator.mozL10n, 'get');
|
||||
l10nStub.withArgs('fxa-will-send-email2')
|
||||
.returns('Will send email to {{email}}');
|
||||
|
||||
mocksHelperForSignupSuccess.suiteSetup();
|
||||
// Load real HTML
|
||||
loadBodyHTML('/fxa/fxa_module.html');
|
||||
// Load element to test
|
||||
LoadElementHelper.load('fxa-signup-success.html');
|
||||
// Import the element and execute the right init
|
||||
HtmlImports.populate(function() {
|
||||
FxaModuleSignupSuccess.init({
|
||||
email: emailTest
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
suiteTeardown(function() {
|
||||
navigator.mozL10n.get.restore();
|
||||
navigator.mozL10n = realL10n;
|
||||
document.body.innerHTML = '';
|
||||
mocksHelperForSignupSuccess.suiteTeardown();
|
||||
});
|
||||
|
||||
|
||||
suite(' > init ', function() {
|
||||
test(' > email shown properly', function() {
|
||||
assert.equal(
|
||||
FxaModuleSignupSuccess.fxaWillSendEmail.getAttribute('data-l10n-id'),
|
||||
'fxa-will-send-email2');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
suite(' > onNext ', function() {
|
||||
test(' > go to DONE Step', function() {
|
||||
FxaModuleSignupSuccess.onNext(function(nextState) {
|
||||
assert.equal(nextState, FxaModuleStates.DONE);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue