Index: chrome/test/data/webui/settings/settings_main_navigation_test.js |
diff --git a/chrome/test/data/webui/settings/settings_main_navigation_test.js b/chrome/test/data/webui/settings/settings_main_navigation_test.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..26bcb501540bf820937f602bf6974ddc42ea692b |
--- /dev/null |
+++ b/chrome/test/data/webui/settings/settings_main_navigation_test.js |
@@ -0,0 +1,133 @@ |
+// Copyright 2016 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. |
+ |
+cr.define('settings_main_navigation_test', function() { |
+ function registerTests() { |
+ suite('settings-main navigation', function() { |
+ var container = null; |
+ var settingsPrefs = null; |
+ var settingsMain = null; |
+ |
+ function hideAdvanced() { |
+ if (!settingsMain.showPages_.advanced) |
+ return false; |
+ |
+ var advancedToggle = settingsMain.$$('#advancedToggle'); |
+ assertTrue(!!advancedToggle); |
+ |
+ MockInteractions.tap(advancedToggle); |
+ Polymer.dom.flush(); |
+ |
+ assertFalse(settingsMain.showPages_.advanced); |
+ assertEquals(0, settingsMain.$$('settings-advanced-page').offsetHeight); |
+ return true; |
+ } |
+ |
+ suiteSetup(function() { |
+ // Remove body spacing. |
+ document.body.style.margin = '0'; |
+ |
+ // Speed up transitions. |
+ settings.animation.Timing.DURATION = 50; |
+ |
+ settingsPrefs = document.createElement('settings-prefs'); |
+ return CrSettingsPrefs.initialized; |
+ }); |
+ |
+ setup(function(done) { |
+ // Set up the settings-main container so sections show normally. |
+ container = document.createElement('div'); |
+ container.style.position = 'absolute'; |
+ |
+ settings.navigateTo(settings.Route.BASIC); |
+ |
+ settingsMain = document.createElement('settings-main'); |
+ settingsMain.prefs = settingsPrefs.prefs; |
+ |
+ document.body.appendChild(container); |
+ container.appendChild(settingsMain); |
+ |
+ // Wait a long time so sections get initialized after responses from |
+ // Chrome. Guaranteed to flake or your money back. |
+ setTimeout(done, 500); |
+ }); |
+ |
+ teardown(function() { |
+ container.remove(); |
+ }); |
+ |
+ suiteTeardown(function() { |
+ document.body.style = ''; |
+ }); |
+ |
+ test('navigating between basic and advanced', function() { |
+ // Advanced page should start collapsed. |
+ assertFalse(hideAdvanced()); |
+ |
+ settings.navigateTo(settings.Route.PRIVACY); |
+ Polymer.dom.flush(); |
+ assertTrue(settingsMain.showPages_.advanced); |
+ |
+ // Navigating to a Basic page should not collapse Advanced. |
+ settings.navigateTo(settings.Route.PEOPLE); |
+ Polymer.dom.flush(); |
+ assertTrue(settingsMain.showPages_.advanced); |
+ |
+ // We can hide Advanced from an Advanced route. |
+ settings.navigateTo(settings.Route.PRIVACY); |
+ Polymer.dom.flush(); |
+ assertTrue(hideAdvanced()); |
+ |
+ // Navigating to another Advanced section expands it again. |
+ settings.navigateTo(settings.Route.LANGUAGES); |
+ Polymer.dom.flush(); |
+ assertTrue(settingsMain.showPages_.advanced); |
+ }); |
+ |
+ test('scroll and overscroll', function(done) { |
+ // Find the last section in Basic. |
+ var basic = settingsMain.$$('settings-basic-page'); |
+ var basicSections = basic.root.querySelectorAll('settings-section'); |
+ var lastSection = basicSections[basicSections.length - 1]; |
+ var lastSectionRoute = |
+ settings.getRouteForPath('/' + lastSection.section); |
+ |
+ // Sanity check: the last section is not the first. |
+ assertGT(lastSection.getBoundingClientRect().top, 0); |
+ |
+ // Navigating to the last section shows it at the top of the page. |
+ settings.navigateTo(lastSectionRoute); |
+ Polymer.dom.flush(); |
+ assertEquals(0, lastSection.getBoundingClientRect().top); |
+ |
+ setTimeout(function() { |
+ // ...and keeps it there. |
+ assertEquals(0, lastSection.getBoundingClientRect().top); |
+ done(); |
+ |
+ // Open a subpage. |
+ settings.navigateTo(settings.Route.MANAGE_PROFILE); |
+ setTimeout(function() { |
+ // Sections are hidden. |
+ assertEquals(0, lastSection.offsetHeight); |
+ |
+ // Navigate to the last section, which should close the subpage and |
+ // scroll down. |
+ settings.navigeTo(lastSectionRoute); |
+ setTimeout(function() { |
+ assertGT(lastSection.offsetHeight, 0); |
+ assertEquals(0, lastSectionRoute.getBoundingClientRect().top); |
+ |
+ done(); |
+ }, 2 * settings.animation.Timing.DURATION); |
+ }, 2 * settings.animation.Timing.DURATION); |
+ }, 2 * settings.animation.Timing.DURATION); |
+ }); |
+ }); |
+ } |
+ |
+ return { |
+ registerTests: registerTests, |
+ }; |
+}); |