Commit 420e3aa3 authored by Danan S's avatar Danan S Committed by Commit Bot

Fix bug where initial online screen wasn't shown.

It wasn't shown because the online screen is the default currentScreen
value.

Bug: 1123218,1143409
Change-Id: I6f881115a0ae9e9f38c8cd17bd9fbad8c4ed0cc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505942
Commit-Queue: Dan S <danan@chromium.org>
Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823373}
parent 71b5f243
......@@ -16,7 +16,7 @@ import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bun
import {EduCoexistenceBrowserProxyImpl} from './edu_coexistence_browser_proxy.js';
/** @enum {string} */
const Screens = {
export const Screens = {
ONLINE_FLOW: 'edu-coexistence-ui',
ERROR: 'edu-coexistence-error',
OFFLINE: 'edu-coexistence-offline',
......@@ -72,6 +72,16 @@ Polymer({
.switchView(this.currentScreen_);
},
/**
* @param {boolean} isOnline Whether or not the browser is online.
* @private
*/
setInitialScreen_(isOnline) {
this.currentScreen_ = isOnline ? Screens.ONLINE_FLOW : Screens.OFFLINE;
/** @type {CrViewManagerElement} */ (this.$.viewManager)
.switchView(this.currentScreen_);
},
/** @override */
ready() {
window.addEventListener('online', () => {
......@@ -85,9 +95,7 @@ Polymer({
this.switchToScreen_(Screens.OFFLINE);
}
});
this.switchToScreen_(
navigator.onLine ? Screens.ONLINE_FLOW : Screens.OFFLINE);
this.setInitialScreen_(navigator.onLine);
},
});
......@@ -135,6 +135,7 @@ if (include_js_tests) {
"../../../browser/ui/webui/chromeos/certificate_manager_dialog_browsertest.js",
"../chromeos/oobe_webui_browsertest.js",
"chromeos/account_manager/account_manager_browsertest.js",
"chromeos/edu_coexistence/edu_coexistence_browsertest.js",
"chromeos/edu_login/edu_login_browsertest.js",
"chromeos/gaia_action_buttons/gaia_action_buttons_browsertest.js",
"cr_components/chromeos/cr_components_chromeos_browsertest.js",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'chrome://chrome-signin/edu_coexistence_app.js';
import {Screens} from 'chrome://chrome-signin/edu_coexistence_app.js';
import {EduCoexistenceBrowserProxyImpl} from 'chrome://chrome-signin/edu_coexistence_browser_proxy.js';
import {AuthMode, AuthParams} from 'chrome://chrome-signin/gaia_auth_host/authenticator.m.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {webUIListenerCallback} from 'chrome://resources/js/cr.m.js';
import {NativeEventTarget as EventTarget} from 'chrome://resources/js/cr/event_target.m.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {getFakeAccountsList, TestEduCoexistenceBrowserProxy} from './edu_coexistence_test_util.js';
window.edu_coexistence_app_tests = {};
edu_coexistence_app_tests.suiteName = 'EduCoexistenceAppTest';
/** @enum {string} */
edu_coexistence_app_tests.TestNames = {
InitOnline: 'Init in the online state',
InitOffline: 'Init in the offline state',
ShowOffline: 'Show offline',
ShowOnline: 'Show online',
ShowError: 'Show error',
DontSwitchViewIfDisplayingError: 'No view switch after error',
};
suite(edu_coexistence_app_tests.suiteName, function() {
let appComponent;
let testBrowserProxy;
setup(function() {
testBrowserProxy = new TestEduCoexistenceBrowserProxy();
EduCoexistenceBrowserProxyImpl.instance_ = testBrowserProxy;
testBrowserProxy.setInitializeEduArgsResponse(async function() {
return {
url: 'https://foo.example.com/supervision/coexistence/intro',
hl: 'en-US',
sourceUi: 'oobe',
clientId: 'test-client-id',
clientVersion: ' test-client-version',
eduCoexistenceId: ' test-edu-coexistence-id',
platformVersion: ' test-platform-version',
releaseChannel: 'test-release-channel',
deviceId: 'test-device-id',
};
});
PolymerTest.clearBody();
appComponent = document.createElement('edu-coexistence-app');
document.body.appendChild(appComponent);
flush();
});
test(assert(edu_coexistence_app_tests.TestNames.InitOnline), function() {
appComponent.setInitialScreen_(true /** online **/);
assertEquals(appComponent.currentScreen_, Screens.ONLINE_FLOW);
});
test(assert(edu_coexistence_app_tests.TestNames.InitOffline), function() {
appComponent.setInitialScreen_(false /** online **/);
assertEquals(appComponent.currentScreen_, Screens.OFFLINE);
});
test(assert(edu_coexistence_app_tests.TestNames.ShowOffline), function() {
appComponent.setInitialScreen_(true /** online **/);
assertEquals(appComponent.currentScreen_, Screens.ONLINE_FLOW);
window.dispatchEvent(new Event('offline'));
assertEquals(appComponent.currentScreen_, Screens.OFFLINE);
});
test(assert(edu_coexistence_app_tests.TestNames.ShowOnline), function() {
appComponent.setInitialScreen_(false /** online **/);
assertEquals(appComponent.currentScreen_, Screens.OFFLINE);
window.dispatchEvent(new Event('online'));
assertEquals(appComponent.currentScreen_, Screens.ONLINE_FLOW);
});
test(assert(edu_coexistence_app_tests.TestNames.ShowError), function() {
appComponent.setInitialScreen_(true /** online **/);
assertEquals(appComponent.currentScreen_, Screens.ONLINE_FLOW);
appComponent.fire('go-error');
assertEquals(appComponent.currentScreen_, Screens.ERROR);
});
test(
assert(
edu_coexistence_app_tests.TestNames.DontSwitchViewIfDisplayingError),
function() {
appComponent.fire('go-error');
assertEquals(appComponent.currentScreen_, Screens.ERROR);
window.dispatchEvent(new Event('offline'));
// Should still show error screen.
assertEquals(appComponent.currentScreen_, Screens.ERROR);
window.dispatchEvent(new Event('online'));
// Should still show error screen.
assertEquals(appComponent.currentScreen_, Screens.ERROR);
});
});
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/** @fileoverview Runs the EDU Coexistence flow tests. */
GEN_INCLUDE(['//chrome/test/data/webui/polymer_browser_test_base.js']);
GEN('#include "content/public/test/browser_test.h"');
const EduCoexistenceTest = class extends PolymerTest {
/** @override */
get browsePreload() {
throw 'this is abstract and should be overridden by subclasses';
}
get suiteName() {
throw 'this is abstract and should be overridden by subclasses';
}
/** @override */
get extraLibraries() {
return [
'//third_party/mocha/mocha.js',
'//chrome/test/data/webui/mocha_adapter.js',
];
}
/** @param {string} testName The name of the test to run. */
runMochaTest(testName) {
runMochaTest(this.suiteName, testName);
}
};
var EduCoexistenceAppTest = class extends EduCoexistenceTest {
/** @override */
get browsePreload() {
return 'chrome://chrome-signin/test_loader.html?module=' +
'chromeos/edu_coexistence/edu_coexistence_app_test.js';
}
/** @override */
get suiteName() {
return edu_coexistence_app_tests.suiteName;
}
};
TEST_F('EduCoexistenceAppTest', 'InitOnline', function() {
this.runMochaTest(edu_coexistence_app_tests.TestNames.InitOnline);
});
TEST_F('EduCoexistenceAppTest', 'InitOffline', function() {
this.runMochaTest(edu_coexistence_app_tests.TestNames.InitOffline);
});
TEST_F('EduCoexistenceAppTest', 'ShowOffline', function() {
this.runMochaTest(edu_coexistence_app_tests.TestNames.ShowOffline);
});
TEST_F('EduCoexistenceAppTest', 'ShowOnline', function() {
this.runMochaTest(edu_coexistence_app_tests.TestNames.ShowOnline);
});
TEST_F('EduCoexistenceAppTest', 'ShowError', function() {
this.runMochaTest(edu_coexistence_app_tests.TestNames.ShowError);
});
TEST_F('EduCoexistenceAppTest', 'DontSwitchViewIfDisplayingError', function() {
this.runMochaTest(
edu_coexistence_app_tests.TestNames.DontSwitchViewIfDisplayingError);
});
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {TestBrowserProxy} from '../../test_browser_proxy.m.js';
/** @return {!Array<string>} */
export function getFakeAccountsList() {
return ['test@gmail.com', 'test2@gmail.com', 'test3@gmail.com'];
}
/** @implements {EduCoexistenceBrowserProxy} */
export class TestEduCoexistenceBrowserProxy extends TestBrowserProxy {
constructor() {
super([
'initializeLogin',
'initializeEduArgs',
'completeLogin',
'getAccounts',
'consentValid',
'consentLogged',
'dialogClose',
'error',
]);
}
/** @override */
initializeLogin() {
this.methodCalled('initializeLogin');
}
/** @override */
initializeEduArgs() {
this.methodCalled('initializeEduArgs');
return this.initializeEduArgsResponse_ ? this.initializeEduArgsResponse_() :
Promise.resolve({});
}
/** @param {function} initializeEduArgsResponse */
setInitializeEduArgsResponse(initializeEduArgsResponse) {
this.initializeEduArgsResponse_ = initializeEduArgsResponse;
}
/** @override */
completeLogin(credentials, eduLoginParams) {
this.methodCalled('completeLogin', [credentials, eduLoginParams]);
}
/** @override */
getAccounts() {
this.methodCalled('getAccounts');
return Promise.resolve(getFakeAccountsList());
}
/** @override */
consentLogged(account, eduCoexistenceTosVersion) {
this.methodCalled('consentLogged', account, eduCoexistenceTosVersion);
return this.consentLoggedResponse_();
}
/** @param {function} consentLoggedResponse */
setConsentLoggedResponse(consentLoggedResponse) {
this.consentLoggedResponse_ = consentLoggedResponse;
}
/** @override */
dialogClose() {
this.methodCalled('dialogClose');
}
/** @override */
error() {
this.methodCalled('error');
}
}
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