Commit 83a6b41e authored by rbpotter's avatar rbpotter Committed by Commit Bot

Settings: Migrate more routing related tests to Polymer 3

Bug: 1026426
Change-Id: I4cee85cb67f6944fcf88e35138529b4c8f1937f0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2135052Reviewed-by: default avatardpapad <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756143}
parent 1e103bbd
...@@ -1982,7 +1982,7 @@ CrSettingsRouteTest.prototype = { ...@@ -1982,7 +1982,7 @@ CrSettingsRouteTest.prototype = {
}; };
TEST_F('CrSettingsRouteTest', 'All', function() { TEST_F('CrSettingsRouteTest', 'All', function() {
mocha.run(); runMochaSuite('route');
}); });
/** /**
...@@ -1992,7 +1992,7 @@ TEST_F('CrSettingsRouteTest', 'All', function() { ...@@ -1992,7 +1992,7 @@ TEST_F('CrSettingsRouteTest', 'All', function() {
function CrSettingsNonExistentRouteTest() {} function CrSettingsNonExistentRouteTest() {}
CrSettingsNonExistentRouteTest.prototype = { CrSettingsNonExistentRouteTest.prototype = {
__proto__: CrSettingsBrowserTest.prototype, __proto__: CrSettingsRouteTest.prototype,
/** @override */ /** @override */
browsePreload: 'chrome://settings/non/existent/route', browsePreload: 'chrome://settings/non/existent/route',
...@@ -2005,15 +2005,7 @@ GEN('#else'); ...@@ -2005,15 +2005,7 @@ GEN('#else');
GEN('#define MAYBE_NonExistentRoute NonExistentRoute'); GEN('#define MAYBE_NonExistentRoute NonExistentRoute');
GEN('#endif'); GEN('#endif');
TEST_F('CrSettingsNonExistentRouteTest', 'MAYBE_NonExistentRoute', function() { TEST_F('CrSettingsNonExistentRouteTest', 'MAYBE_NonExistentRoute', function() {
suite('NonExistentRoutes', function() { runMochaSuite('NonExistentRoute');
test('redirect to basic', function() {
assertEquals(
settings.routes.BASIC,
settings.Router.getInstance().getCurrentRoute());
assertEquals('/', location.pathname);
});
});
mocha.run();
}); });
/** /**
...@@ -2023,56 +2015,14 @@ TEST_F('CrSettingsNonExistentRouteTest', 'MAYBE_NonExistentRoute', function() { ...@@ -2023,56 +2015,14 @@ TEST_F('CrSettingsNonExistentRouteTest', 'MAYBE_NonExistentRoute', function() {
function CrSettingsRouteDynamicParametersTest() {} function CrSettingsRouteDynamicParametersTest() {}
CrSettingsRouteDynamicParametersTest.prototype = { CrSettingsRouteDynamicParametersTest.prototype = {
__proto__: CrSettingsBrowserTest.prototype, __proto__: CrSettingsRouteTest.prototype,
/** @override */ /** @override */
browsePreload: 'chrome://settings/search?guid=a%2Fb&foo=42', browsePreload: 'chrome://settings/search?guid=a%2Fb&foo=42',
}; };
TEST_F('CrSettingsRouteDynamicParametersTest', 'All', function() { TEST_F('CrSettingsRouteDynamicParametersTest', 'All', function() {
suite('DynamicParameters', function() { runMochaSuite('DynamicParameters');
test('get parameters from URL and navigation', function(done) {
assertEquals(
settings.routes.SEARCH,
settings.Router.getInstance().getCurrentRoute());
assertEquals(
'a/b',
settings.Router.getInstance().getQueryParameters().get('guid'));
assertEquals(
'42', settings.Router.getInstance().getQueryParameters().get('foo'));
const params = new URLSearchParams();
params.set('bar', 'b=z');
params.set('biz', '3');
settings.Router.getInstance().navigateTo(
settings.routes.SEARCH_ENGINES, params);
assertEquals(
settings.routes.SEARCH_ENGINES,
settings.Router.getInstance().getCurrentRoute());
assertEquals(
'b=z', settings.Router.getInstance().getQueryParameters().get('bar'));
assertEquals(
'3', settings.Router.getInstance().getQueryParameters().get('biz'));
assertEquals('?bar=b%3Dz&biz=3', window.location.search);
window.addEventListener('popstate', function(event) {
assertEquals(
'/search', settings.Router.getInstance().getCurrentRoute().path);
assertEquals(
settings.routes.SEARCH,
settings.Router.getInstance().getCurrentRoute());
assertEquals(
'a/b',
settings.Router.getInstance().getQueryParameters().get('guid'));
assertEquals(
'42',
settings.Router.getInstance().getQueryParameters().get('foo'));
done();
});
window.history.back();
});
});
mocha.run();
}); });
/** /**
......
...@@ -354,6 +354,34 @@ TEST_F( ...@@ -354,6 +354,34 @@ TEST_F(
runMochaSuite('HappinessTrackingSurveys'); runMochaSuite('HappinessTrackingSurveys');
}); });
// eslint-disable-next-line no-var
var CrSettingsRouteV3Test = class extends CrSettingsV3BrowserTest {
/** @override */
get browsePreload() {
return 'chrome://settings/test_loader.html?module=settings/route_tests.m.js';
}
};
TEST_F('CrSettingsRouteV3Test', 'Basic', function() {
runMochaSuite('route');
});
TEST_F('CrSettingsRouteV3Test', 'DynamicParameters', function() {
runMochaSuite('DynamicParameters');
});
// Copied from Polymer 2 test:
// Failing on ChromiumOS dbg. https://crbug.com/709442
GEN('#if (defined(OS_WIN) || defined(OS_CHROMEOS)) && !defined(NDEBUG)');
GEN('#define MAYBE_NonExistentRoute DISABLED_NonExistentRoute');
GEN('#else');
GEN('#define MAYBE_NonExistentRoute NonExistentRoute');
GEN('#endif');
TEST_F('CrSettingsRouteV3Test', 'MAYBE_NonExistentRoute', function() {
runMochaSuite('NonExistentRoute');
});
[['AllSites', 'all_sites_tests.m.js'], [['AllSites', 'all_sites_tests.m.js'],
['AppearanceFontsPage', 'appearance_fonts_page_test.m.js'], ['AppearanceFontsPage', 'appearance_fonts_page_test.m.js'],
['AppearancePage', 'appearance_page_test.m.js'], ['AppearancePage', 'appearance_page_test.m.js'],
...@@ -386,7 +414,6 @@ TEST_F( ...@@ -386,7 +414,6 @@ TEST_F(
['RecentSitePermissions', 'recent_site_permissions_test.m.js'], ['RecentSitePermissions', 'recent_site_permissions_test.m.js'],
['ResetPage', 'reset_page_test.m.js'], ['ResetPage', 'reset_page_test.m.js'],
['ResetProfileBanner', 'reset_profile_banner_test.m.js'], ['ResetProfileBanner', 'reset_profile_banner_test.m.js'],
['Route', 'route_tests.m.js'],
['SearchEngines', 'search_engines_page_test.m.js'], ['SearchEngines', 'search_engines_page_test.m.js'],
['SearchPage', 'search_page_test.m.js'], ['SearchPage', 'search_page_test.m.js'],
['Search', 'search_settings_test.m.js'], ['Search', 'search_settings_test.m.js'],
......
...@@ -262,3 +262,74 @@ suite('route', function() { ...@@ -262,3 +262,74 @@ suite('route', function() {
settings.routes.LANGUAGES.getAbsolutePath()); settings.routes.LANGUAGES.getAbsolutePath());
}); });
}); });
suite('DynamicParameters', function() {
setup(function() {
// TODO(https://crbug.com/1026426): Remove conditional when Polymer 2 tests
// are no longer run.
if (window.location.pathname === '/test_loader.html') {
PolymerTest.clearBody();
window.history.replaceState({}, '', 'search?guid=a%2Fb&foo=42');
const settingsUi = document.createElement('settings-ui');
document.body.appendChild(settingsUi);
}
});
test('get parameters from URL and navigation', function(done) {
assertEquals(
settings.routes.SEARCH,
settings.Router.getInstance().getCurrentRoute());
assertEquals(
'a/b', settings.Router.getInstance().getQueryParameters().get('guid'));
assertEquals(
'42', settings.Router.getInstance().getQueryParameters().get('foo'));
const params = new URLSearchParams();
params.set('bar', 'b=z');
params.set('biz', '3');
settings.Router.getInstance().navigateTo(
settings.routes.SEARCH_ENGINES, params);
assertEquals(
settings.routes.SEARCH_ENGINES,
settings.Router.getInstance().getCurrentRoute());
assertEquals(
'b=z', settings.Router.getInstance().getQueryParameters().get('bar'));
assertEquals(
'3', settings.Router.getInstance().getQueryParameters().get('biz'));
assertEquals('?bar=b%3Dz&biz=3', window.location.search);
window.addEventListener('popstate', function(event) {
assertEquals(
'/search', settings.Router.getInstance().getCurrentRoute().path);
assertEquals(
settings.routes.SEARCH,
settings.Router.getInstance().getCurrentRoute());
assertEquals(
'a/b',
settings.Router.getInstance().getQueryParameters().get('guid'));
assertEquals(
'42', settings.Router.getInstance().getQueryParameters().get('foo'));
done();
});
window.history.back();
});
});
suite('NonExistentRoute', function() {
setup(function() {
// TODO(https://crbug.com/1026426): Remove conditional when Polymer 2 tests
// are no longer run.
if (window.location.pathname === '/test_loader.html') {
PolymerTest.clearBody();
window.history.replaceState({}, '', 'non/existent/route');
const settingsUi = document.createElement('settings-ui');
document.body.appendChild(settingsUi);
}
});
test('redirect to basic', function() {
assertEquals(
settings.routes.BASIC, settings.Router.getInstance().getCurrentRoute());
assertEquals('/', location.pathname);
});
});
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