Commit fc230cd5 authored by Scott Chen's avatar Scott Chen Committed by Commit Bot

Nux Onboarding: add set-as-default status checking test.

Tests possible scenarios of the default status response.

Bug: 881937
Change-Id: Ic19152b53a81571794fd82f0ce2bd6bed978cf0f
Reviewed-on: https://chromium-review.googlesource.com/c/1327525
Commit-Queue: Scott Chen <scottchen@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608535}
parent 0125d830
......@@ -64,6 +64,7 @@ OnboardingWelcomeWelcomeAppTest = class extends OnboardingWelcomeBrowserTest {
return super.extraLibraries.concat([
'../settings/test_util.js',
'welcome_app_test.js',
'test_bookmark_proxy.js',
'test_welcome_browser_proxy.js',
'test_nux_set_as_default_proxy.js',
]);
......
......@@ -7,6 +7,7 @@ class TestBookmarkProxy extends TestBrowserProxy {
constructor() {
super([
'addBookmark',
'isBookmarkBarShown',
'removeBookmark',
'toggleBookmarkBar',
]);
......@@ -20,6 +21,14 @@ class TestBookmarkProxy extends TestBrowserProxy {
callback({id: this.fakeBookmarkId++});
}
/** @override */
isBookmarkBarShown() {
this.methodCalled('isBookmarkBarShown');
// TODO(scottchen): make changable to test both true/false cases.
return Promise.resolve(true);
}
/** @override */
removeBookmark(id) {
this.methodCalled('removeBookmark', id);
......
......@@ -50,6 +50,10 @@ cr.define('onboarding_welcome_app_test', function() {
testSetAsDefaultProxy = new TestNuxSetAsDefaultProxy();
nux.NuxSetAsDefaultProxyImpl.instance_ = testSetAsDefaultProxy;
// Not used in test, but setting to test proxy anyway, in order to prevent
// calls to backend.
nux.BookmarkProxyImpl.instance_ = new TestBookmarkProxy();
resetTestElement();
});
......@@ -110,5 +114,81 @@ cr.define('onboarding_welcome_app_test', function() {
// welcome_app should try to go to NTP.
return testWelcomeBrowserProxy.whenCalled('goToNewTabPage');
});
test('default-status check resolves with correct value', function() {
/**
* @param {!nux.DefaultBrowserInfo} status
* @param {boolean} expectedDefaultExists
* @return {!Promise}
*/
function checkDefaultStatusResolveValue(status, expectedDefaultExists) {
testSetAsDefaultProxy.setDefaultStatus(status);
resetTestElement();
// Use the new-user route to test if nux-set-as-default module gets
// initialized.
welcome.navigateTo(welcome.Routes.NEW_USER, 1);
return test_util.waitForRender(testElement).then(() => {
// Use the existence of the nux-set-as-default as indication of
// whether or not the promise is resolved with the expected result.
assertEquals(
expectedDefaultExists, !!testElement.$$('nux-set-as-default'));
});
}
return checkDefaultStatusResolveValue(
{
// Allowed to set as default, and not default yet.
isDefault: false,
canBeDefault: true,
isDisabledByPolicy: false,
isUnknownError: false,
},
true)
.then(() => {
return checkDefaultStatusResolveValue(
{
// Allowed to set as default, but already default.
isDefault: true,
canBeDefault: true,
isDisabledByPolicy: false,
isUnknownError: false,
},
false);
})
.then(() => {
return checkDefaultStatusResolveValue(
{
// Not default yet, but this chrome install cannot be default.
isDefault: false,
canBeDefault: false,
isDisabledByPolicy: false,
isUnknownError: false,
},
false);
})
.then(() => {
return checkDefaultStatusResolveValue(
{
// Not default yet, but setting default is disabled by policy.
isDefault: false,
canBeDefault: true,
isDisabledByPolicy: true,
isUnknownError: false,
},
false);
})
.then(() => {
return checkDefaultStatusResolveValue(
{
// Not default yet, but there is some unknown error.
isDefault: false,
canBeDefault: true,
isDisabledByPolicy: false,
isUnknownError: true,
},
false);
});
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment