blob: d7918c6b92ebb127efbe068701c6abcaffe12963 [file] [log] [blame]
// 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.
/**
* @implements {settings.AmbientModeBrowserProxy}
*/
class TestAmbientModeBrowserProxy extends TestBrowserProxy {
constructor() {
super([
'onAmbientModePageReady',
'onTopicSourceSelectedChanged',
]);
}
/** @override */
onAmbientModePageReady() {
this.methodCalled('onAmbientModePageReady');
}
/** @override */
onTopicSourceSelectedChanged(selected) {
this.methodCalled('onTopicSourceSelectedChanged', selected);
}
}
suite('AmbientModeHandler', function() {
/** @type {SettingsAmbientModePageElement} */
let page = null;
/** @type {?TestAmbientModeBrowserProxy} */
let browserProxy = null;
suiteSetup(function() {});
setup(function() {
browserProxy = new TestAmbientModeBrowserProxy();
settings.AmbientModeBrowserProxyImpl.instance_ = browserProxy;
PolymerTest.clearBody();
const prefElement = document.createElement('settings-prefs');
document.body.appendChild(prefElement);
return CrSettingsPrefs.initialized.then(function() {
page = document.createElement('settings-ambient-mode-page');
page.prefs = prefElement.prefs;
document.body.appendChild(page);
Polymer.dom.flush();
});
});
teardown(function() {
page.remove();
});
test('toggleAmbientMode', function() {
const button = page.$$('#ambientModeEnable');
assertTrue(!!button);
assertFalse(button.disabled);
// The button's state is set by the pref value.
const enabled = page.getPref('settings.ambient_mode.enabled.value');
assertEquals(enabled, button.checked);
// Click the button will toggle the pref value.
button.click();
Polymer.dom.flush();
const enabled_toggled = page.getPref('settings.ambient_mode.enabled.value');
assertEquals(enabled_toggled, button.checked);
assertEquals(enabled, !enabled_toggled);
// Click again will toggle the pref value.
button.click();
Polymer.dom.flush();
const enabled_toggled_twice =
page.getPref('settings.ambient_mode.enabled.value');
assertEquals(enabled_toggled_twice, button.checked);
assertEquals(enabled, enabled_toggled_twice);
});
test('hasTopicSourceItems', function() {
const topicSourceListElement = page.$$('topic-source-list');
const ironList = topicSourceListElement.$$('iron-list');
const topicSourceItems = ironList.querySelectorAll('topic-source-item');
assertEquals(2, topicSourceItems.length);
});
});