OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 cr.define('settings_main_navigation_test', function() { |
| 6 function registerTests() { |
| 7 suite('settings-main navigation', function() { |
| 8 var container = null; |
| 9 var settingsPrefs = null; |
| 10 var settingsMain = null; |
| 11 |
| 12 function hideAdvanced() { |
| 13 if (!settingsMain.showPages_.advanced) |
| 14 return false; |
| 15 |
| 16 var advancedToggle = settingsMain.$$('#advancedToggle'); |
| 17 assertTrue(!!advancedToggle); |
| 18 |
| 19 MockInteractions.tap(advancedToggle); |
| 20 Polymer.dom.flush(); |
| 21 |
| 22 assertFalse(settingsMain.showPages_.advanced); |
| 23 assertEquals(0, settingsMain.$$('settings-advanced-page').offsetHeight); |
| 24 return true; |
| 25 } |
| 26 |
| 27 suiteSetup(function() { |
| 28 // Remove body spacing. |
| 29 document.body.style.margin = '0'; |
| 30 |
| 31 // Speed up transitions. |
| 32 settings.animation.Timing.DURATION = 50; |
| 33 |
| 34 settingsPrefs = document.createElement('settings-prefs'); |
| 35 return CrSettingsPrefs.initialized; |
| 36 }); |
| 37 |
| 38 setup(function(done) { |
| 39 // Set up the settings-main container so sections show normally. |
| 40 container = document.createElement('div'); |
| 41 container.style.position = 'absolute'; |
| 42 |
| 43 settings.navigateTo(settings.Route.BASIC); |
| 44 |
| 45 settingsMain = document.createElement('settings-main'); |
| 46 settingsMain.prefs = settingsPrefs.prefs; |
| 47 |
| 48 document.body.appendChild(container); |
| 49 container.appendChild(settingsMain); |
| 50 |
| 51 // Wait a long time so sections get initialized after responses from |
| 52 // Chrome. Guaranteed to flake or your money back. |
| 53 setTimeout(done, 500); |
| 54 }); |
| 55 |
| 56 teardown(function() { |
| 57 container.remove(); |
| 58 }); |
| 59 |
| 60 suiteTeardown(function() { |
| 61 document.body.style = ''; |
| 62 }); |
| 63 |
| 64 test('navigating between basic and advanced', function() { |
| 65 // Advanced page should start collapsed. |
| 66 assertFalse(hideAdvanced()); |
| 67 |
| 68 settings.navigateTo(settings.Route.PRIVACY); |
| 69 Polymer.dom.flush(); |
| 70 assertTrue(settingsMain.showPages_.advanced); |
| 71 |
| 72 // Navigating to a Basic page should not collapse Advanced. |
| 73 settings.navigateTo(settings.Route.PEOPLE); |
| 74 Polymer.dom.flush(); |
| 75 assertTrue(settingsMain.showPages_.advanced); |
| 76 |
| 77 // We can hide Advanced from an Advanced route. |
| 78 settings.navigateTo(settings.Route.PRIVACY); |
| 79 Polymer.dom.flush(); |
| 80 assertTrue(hideAdvanced()); |
| 81 |
| 82 // Navigating to another Advanced section expands it again. |
| 83 settings.navigateTo(settings.Route.LANGUAGES); |
| 84 Polymer.dom.flush(); |
| 85 assertTrue(settingsMain.showPages_.advanced); |
| 86 }); |
| 87 |
| 88 test('scroll and overscroll', function(done) { |
| 89 // Find the last section in Basic. |
| 90 var basic = settingsMain.$$('settings-basic-page'); |
| 91 var basicSections = basic.root.querySelectorAll('settings-section'); |
| 92 var lastSection = basicSections[basicSections.length - 1]; |
| 93 var lastSectionRoute = |
| 94 settings.getRouteForPath('/' + lastSection.section); |
| 95 |
| 96 // Sanity check: the last section is not the first. |
| 97 assertGT(lastSection.getBoundingClientRect().top, 0); |
| 98 |
| 99 // Navigating to the last section shows it at the top of the page. |
| 100 settings.navigateTo(lastSectionRoute); |
| 101 Polymer.dom.flush(); |
| 102 assertEquals(0, lastSection.getBoundingClientRect().top); |
| 103 |
| 104 setTimeout(function() { |
| 105 // ...and keeps it there. |
| 106 assertEquals(0, lastSection.getBoundingClientRect().top); |
| 107 done(); |
| 108 |
| 109 // Open a subpage. |
| 110 settings.navigateTo(settings.Route.MANAGE_PROFILE); |
| 111 setTimeout(function() { |
| 112 // Sections are hidden. |
| 113 assertEquals(0, lastSection.offsetHeight); |
| 114 |
| 115 // Navigate to the last section, which should close the subpage and |
| 116 // scroll down. |
| 117 settings.navigeTo(lastSectionRoute); |
| 118 setTimeout(function() { |
| 119 assertGT(lastSection.offsetHeight, 0); |
| 120 assertEquals(0, lastSectionRoute.getBoundingClientRect().top); |
| 121 |
| 122 done(); |
| 123 }, 2 * settings.animation.Timing.DURATION); |
| 124 }, 2 * settings.animation.Timing.DURATION); |
| 125 }, 2 * settings.animation.Timing.DURATION); |
| 126 }); |
| 127 }); |
| 128 } |
| 129 |
| 130 return { |
| 131 registerTests: registerTests, |
| 132 }; |
| 133 }); |
OLD | NEW |