Commit df1d1cf7 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Settings subpage test: remove unnecessary wrapper

This is in preparation for autogenerating tests for the Polymer 3
version of settings-subpage.

Bug: 1026426
Change-Id: I32b119cf18f8b7f7f1053621a81e10f65ffcbc8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2038491Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738690}
parent 77f13a8f
...@@ -2,120 +2,117 @@ ...@@ -2,120 +2,117 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
cr.define('settings_subpage', function() { suite('SettingsSubpage', function() {
suite('SettingsSubpage', function() { setup(function() {
setup(function() { const routes = {
const routes = { BASIC: new settings.Route('/'),
BASIC: new settings.Route('/'), };
}; routes.SEARCH = routes.BASIC.createSection('/search', 'search');
routes.SEARCH = routes.BASIC.createSection('/search', 'search'); routes.SEARCH_ENGINES = routes.SEARCH.createChild('/searchEngines');
routes.SEARCH_ENGINES = routes.SEARCH.createChild('/searchEngines'); routes.PEOPLE = routes.BASIC.createSection('/people', 'people');
routes.PEOPLE = routes.BASIC.createSection('/people', 'people'); routes.SYNC = routes.PEOPLE.createChild('/syncSetup');
routes.SYNC = routes.PEOPLE.createChild('/syncSetup'); routes.PRIVACY = routes.BASIC.createSection('/privacy', 'privacy');
routes.PRIVACY = routes.BASIC.createSection('/privacy', 'privacy'); routes.CERTIFICATES = routes.PRIVACY.createChild('/certificates');
routes.CERTIFICATES = routes.PRIVACY.createChild('/certificates');
settings.Router.resetInstanceForTesting(new settings.Router(routes));
settings.Router.resetInstanceForTesting(new settings.Router(routes)); settings.routes = routes;
settings.routes = routes; test_util.setupPopstateListener();
test_util.setupPopstateListener();
PolymerTest.clearBody();
PolymerTest.clearBody(); });
});
test('clear search (event)', function() { test('clear search (event)', function() {
const subpage = document.createElement('settings-subpage'); const subpage = document.createElement('settings-subpage');
// Having a searchLabel will create the cr-search-field. // Having a searchLabel will create the cr-search-field.
subpage.searchLabel = 'test'; subpage.searchLabel = 'test';
document.body.appendChild(subpage); document.body.appendChild(subpage);
Polymer.dom.flush(); Polymer.dom.flush();
const search = subpage.$$('cr-search-field'); const search = subpage.$$('cr-search-field');
assertTrue(!!search); assertTrue(!!search);
search.setValue('Hello'); search.setValue('Hello');
subpage.fire('clear-subpage-search'); subpage.fire('clear-subpage-search');
Polymer.dom.flush(); Polymer.dom.flush();
assertEquals('', search.getValue()); assertEquals('', search.getValue());
}); });
test('clear search (click)', async () => { test('clear search (click)', async () => {
const subpage = document.createElement('settings-subpage'); const subpage = document.createElement('settings-subpage');
// Having a searchLabel will create the cr-search-field. // Having a searchLabel will create the cr-search-field.
subpage.searchLabel = 'test'; subpage.searchLabel = 'test';
document.body.appendChild(subpage); document.body.appendChild(subpage);
Polymer.dom.flush(); Polymer.dom.flush();
const search = subpage.$$('cr-search-field'); const search = subpage.$$('cr-search-field');
assertTrue(!!search); assertTrue(!!search);
search.setValue('Hello'); search.setValue('Hello');
assertEquals(null, search.root.activeElement); assertEquals(null, search.root.activeElement);
search.$.clearSearch.click(); search.$.clearSearch.click();
await test_util.flushTasks(); await test_util.flushTasks();
assertEquals('', search.getValue()); assertEquals('', search.getValue());
assertEquals(search.$.searchInput, search.root.activeElement); assertEquals(search.$.searchInput, search.root.activeElement);
}); });
test('navigates to parent when there is no history', function() { test('navigates to parent when there is no history', function() {
// Pretend that we initially started on the CERTIFICATES route. // Pretend that we initially started on the CERTIFICATES route.
window.history.replaceState( window.history.replaceState(
undefined, '', settings.routes.CERTIFICATES.path); undefined, '', settings.routes.CERTIFICATES.path);
settings.Router.getInstance().initializeRouteFromUrl(); settings.Router.getInstance().initializeRouteFromUrl();
assertEquals( assertEquals(
settings.routes.CERTIFICATES, settings.routes.CERTIFICATES,
settings.Router.getInstance().getCurrentRoute()); settings.Router.getInstance().getCurrentRoute());
const subpage = document.createElement('settings-subpage');
document.body.appendChild(subpage);
subpage.$$('cr-icon-button').click();
assertEquals(
settings.routes.PRIVACY,
settings.Router.getInstance().getCurrentRoute());
});
const subpage = document.createElement('settings-subpage'); test('navigates to any route via window.back()', function(done) {
document.body.appendChild(subpage); settings.Router.getInstance().navigateTo(settings.routes.BASIC);
settings.Router.getInstance().navigateTo(settings.routes.SYNC);
assertEquals(
settings.routes.SYNC, settings.Router.getInstance().getCurrentRoute());
subpage.$$('cr-icon-button').click(); const subpage = document.createElement('settings-subpage');
assertEquals( document.body.appendChild(subpage);
settings.routes.PRIVACY,
settings.Router.getInstance().getCurrentRoute()); subpage.$$('cr-icon-button').click();
});
test('navigates to any route via window.back()', function(done) { window.addEventListener('popstate', function(event) {
settings.Router.getInstance().navigateTo(settings.routes.BASIC);
settings.Router.getInstance().navigateTo(settings.routes.SYNC);
assertEquals( assertEquals(
settings.routes.SYNC, settings.Router.getInstance().getRoutes().BASIC,
settings.Router.getInstance().getCurrentRoute()); settings.Router.getInstance().getCurrentRoute());
done();
const subpage = document.createElement('settings-subpage');
document.body.appendChild(subpage);
subpage.$$('cr-icon-button').click();
window.addEventListener('popstate', function(event) {
assertEquals(
settings.Router.getInstance().getRoutes().BASIC,
settings.Router.getInstance().getCurrentRoute());
done();
});
}); });
});
test('updates the title of the document when active', function() { test('updates the title of the document when active', function() {
const expectedTitle = 'My Subpage Title'; const expectedTitle = 'My Subpage Title';
settings.Router.getInstance().navigateTo(settings.routes.SEARCH); settings.Router.getInstance().navigateTo(settings.routes.SEARCH);
const subpage = document.createElement('settings-subpage'); const subpage = document.createElement('settings-subpage');
subpage.setAttribute('route-path', settings.routes.SEARCH_ENGINES.path); subpage.setAttribute('route-path', settings.routes.SEARCH_ENGINES.path);
subpage.setAttribute('page-title', expectedTitle); subpage.setAttribute('page-title', expectedTitle);
document.body.appendChild(subpage); document.body.appendChild(subpage);
settings.Router.getInstance().navigateTo(settings.routes.SEARCH_ENGINES); settings.Router.getInstance().navigateTo(settings.routes.SEARCH_ENGINES);
assertEquals( assertEquals(
document.title, document.title,
loadTimeData.getStringF('settingsAltPageTitle', expectedTitle)); loadTimeData.getStringF('settingsAltPageTitle', expectedTitle));
});
}); });
});
suite('SettingsSubpageSearch', function() { suite('SettingsSubpageSearch', function() {
test('host autofocus propagates to <cr-input>', function() { test('host autofocus propagates to <cr-input>', function() {
PolymerTest.clearBody(); PolymerTest.clearBody();
const element = document.createElement('cr-search-field'); const element = document.createElement('cr-search-field');
element.setAttribute('autofocus', true); element.setAttribute('autofocus', true);
document.body.appendChild(element); document.body.appendChild(element);
assertTrue(element.$$('cr-input').hasAttribute('autofocus')); assertTrue(element.$$('cr-input').hasAttribute('autofocus'));
element.removeAttribute('autofocus'); element.removeAttribute('autofocus');
assertFalse(element.$$('cr-input').hasAttribute('autofocus')); assertFalse(element.$$('cr-input').hasAttribute('autofocus'));
});
}); });
}); });
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