Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** @fileoverview Runs polymer appearance font settings elements. */ | 5 /** @fileoverview Runs polymer appearance font settings elements. */ |
| 6 | 6 |
| 7 cr.define('settings_appearance', function() { | 7 cr.define('settings_appearance', function() { |
| 8 /** | 8 /** |
| 9 * A test version of AppearanceBrowserProxy. | 9 * A test version of AppearanceBrowserProxy. |
| 10 * | 10 * |
| 11 * @constructor | 11 * @constructor |
| 12 * @implements {settings.AppearanceBrowserProxy} | 12 * @implements {settings.AppearanceBrowserProxy} |
| 13 * @extends {settings.TestBrowserProxy} | 13 * @extends {settings.TestBrowserProxy} |
| 14 */ | 14 */ |
| 15 var TestAppearanceBrowserProxy = function() { | 15 var TestAppearanceBrowserProxy = function() { |
| 16 settings.TestBrowserProxy.call(this, [ | 16 settings.TestBrowserProxy.call(this, [ |
| 17 'getThemeInfo', | 17 'getThemeInfo', |
| 18 'isSupervised', | |
| 18 'openWallpaperManager', | 19 'openWallpaperManager', |
| 19 'useDefaultTheme', | 20 'useDefaultTheme', |
| 20 'useSystemTheme', | 21 'useSystemTheme', |
| 21 ]); | 22 ]); |
| 22 }; | 23 }; |
| 23 | 24 |
| 24 TestAppearanceBrowserProxy.prototype = { | 25 TestAppearanceBrowserProxy.prototype = { |
| 25 __proto__: settings.TestBrowserProxy.prototype, | 26 __proto__: settings.TestBrowserProxy.prototype, |
| 26 | 27 |
| 28 /** @private */ | |
| 29 isSupervised_: false, | |
| 30 | |
| 27 /** @override */ | 31 /** @override */ |
| 28 getThemeInfo: function(themeId) { | 32 getThemeInfo: function(themeId) { |
| 29 this.methodCalled('getThemeInfo', themeId); | 33 this.methodCalled('getThemeInfo', themeId); |
| 30 return Promise.resolve({name: 'Sports car red'}); | 34 return Promise.resolve({name: 'Sports car red'}); |
| 31 }, | 35 }, |
| 32 | 36 |
| 33 /** @override */ | 37 /** @override */ |
| 38 isSupervised: function() { | |
| 39 this.methodCalled('isSupervised'); | |
| 40 return this.isSupervised_; | |
| 41 }, | |
| 42 | |
| 43 /** @override */ | |
| 34 openWallpaperManager: function() { | 44 openWallpaperManager: function() { |
| 35 this.methodCalled('openWallpaperManager'); | 45 this.methodCalled('openWallpaperManager'); |
| 36 }, | 46 }, |
| 37 | 47 |
| 38 /** @override */ | 48 /** @override */ |
| 39 useDefaultTheme: function() { | 49 useDefaultTheme: function() { |
| 40 this.methodCalled('useDefaultTheme'); | 50 this.methodCalled('useDefaultTheme'); |
| 41 }, | 51 }, |
| 42 | 52 |
| 43 /** @override */ | 53 /** @override */ |
| 44 useSystemTheme: function() { | 54 useSystemTheme: function() { |
| 45 this.methodCalled('useSystemTheme'); | 55 this.methodCalled('useSystemTheme'); |
| 46 }, | 56 }, |
| 57 | |
| 58 /** @param {boolean} Whether the user is supervised */ | |
| 59 setIsSupervised: function(isSupervised) { | |
| 60 this.isSupervised_ = isSupervised; | |
| 61 }, | |
| 47 }; | 62 }; |
| 48 | 63 |
| 49 /** | 64 /** |
| 50 * A test version of FontsBrowserProxy. | 65 * A test version of FontsBrowserProxy. |
| 51 * | 66 * |
| 52 * @constructor | 67 * @constructor |
| 53 * @implements {settings.FontsBrowserProxy} | 68 * @implements {settings.FontsBrowserProxy} |
| 54 * @extends {settings.TestBrowserProxy} | 69 * @extends {settings.TestBrowserProxy} |
| 55 */ | 70 */ |
| 56 var TestFontsBrowserProxy = function() { | 71 var TestFontsBrowserProxy = function() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 appearanceBrowserProxy = new TestAppearanceBrowserProxy(); | 113 appearanceBrowserProxy = new TestAppearanceBrowserProxy(); |
| 99 settings.AppearanceBrowserProxyImpl.instance_ = appearanceBrowserProxy; | 114 settings.AppearanceBrowserProxyImpl.instance_ = appearanceBrowserProxy; |
| 100 | 115 |
| 101 PolymerTest.clearBody(); | 116 PolymerTest.clearBody(); |
| 102 | 117 |
| 103 appearancePage = document.createElement('settings-appearance-page'); | 118 appearancePage = document.createElement('settings-appearance-page'); |
| 104 appearancePage.set('prefs', { | 119 appearancePage.set('prefs', { |
| 105 extensions: { | 120 extensions: { |
| 106 theme: { | 121 theme: { |
| 107 id: { | 122 id: { |
| 108 value: 'asdf', | 123 value: '', |
| 109 }, | 124 }, |
| 110 use_system: { | 125 use_system: { |
| 111 value: false, | 126 value: false, |
| 112 }, | 127 }, |
| 113 }, | 128 }, |
| 114 }, | 129 }, |
| 115 }); | 130 }); |
| 116 document.body.appendChild(appearancePage); | 131 document.body.appendChild(appearancePage); |
| 117 Polymer.dom.flush(); | 132 Polymer.dom.flush(); |
| 118 }); | 133 }); |
| 119 | 134 |
| 120 teardown(function() { appearancePage.remove(); }); | 135 teardown(function() { appearancePage.remove(); }); |
| 121 | 136 |
| 122 if (cr.isChromeOS) { | 137 if (cr.isChromeOS) { |
| 123 test('wallpaperManager', function() { | 138 test('wallpaperManager', function() { |
| 124 var button = appearancePage.$.wallpaperButton; | 139 var button = appearancePage.$.wallpaperButton; |
| 125 assertTrue(!!button); | 140 assertTrue(!!button); |
| 126 MockInteractions.tap(button); | 141 MockInteractions.tap(button); |
| 127 return appearanceBrowserProxy.whenCalled('openWallpaperManager'); | 142 return appearanceBrowserProxy.whenCalled('openWallpaperManager'); |
| 128 }); | 143 }); |
| 129 } else { | 144 } else { |
| 130 test('noWallpaperManager', function() { | 145 test('noWallpaperManager', function() { |
| 131 // The wallpaper button should not be present. | 146 // The wallpaper button should not be present. |
| 132 var button = appearancePage.$.wallpaperButton; | 147 var button = appearancePage.$.wallpaperButton; |
| 133 assertFalse(!!button); | 148 assertFalse(!!button); |
| 134 }); | 149 }); |
| 135 } | 150 } |
| 136 | 151 |
| 137 test('useDefaultTheme', function() { | 152 test('useDefaultTheme', function() { |
| 153 assertFalse(!!appearancePage.get('prefs.extensions.theme.id.value')); | |
| 154 assertFalse(appearancePage.useSystemTheme_); | |
|
dpapad
2016/10/18 19:18:00
Is there any way to avoid referring to private sta
Dan Beam
2016/10/18 19:27:44
the pref only exists on linux
dpapad
2016/10/18 19:37:27
Ok. Can we split the the default and system themes
Dan Beam
2016/10/18 21:50:25
Done.
| |
| 155 // No custom nor system theme in use; the "RESET TO DEFAULT" or "USE | |
| 156 // CLASSIC" should be hidden. | |
| 157 assertFalse(!!appearancePage.$$('#useDefault')); | |
| 158 | |
| 159 appearancePage.useSystemTheme_ = true; | |
| 160 Polymer.dom.flush(); | |
| 161 // The system theme only currently exists on Linux, but the code is | |
| 162 // cross-platform. If the system theme is in use, "USE CLASSIC" should | |
| 163 // show. | |
| 164 assertTrue(!!appearancePage.$$('#useDefault')); | |
| 165 | |
| 166 appearancePage.useSystemTheme_ = false; | |
| 167 appearancePage.set('prefs.extensions.theme.id.value', 'fake theme id'); | |
| 168 Polymer.dom.flush(); | |
| 169 | |
| 170 // With a custom theme installed, "USE CLASSIC"/"RESET" should show. | |
| 138 var button = appearancePage.$$('#useDefault'); | 171 var button = appearancePage.$$('#useDefault'); |
| 139 assertTrue(!!button); | 172 assertTrue(!!button); |
| 173 | |
| 140 MockInteractions.tap(button); | 174 MockInteractions.tap(button); |
| 141 return appearanceBrowserProxy.whenCalled('useDefaultTheme'); | 175 return appearanceBrowserProxy.whenCalled('useDefaultTheme'); |
| 142 }); | 176 }); |
| 143 | 177 |
| 144 if (cr.isLinux && !cr.isChromeOS) { | 178 if (cr.isLinux && !cr.isChromeOS) { |
| 145 test('useSystemTheme', function() { | 179 test('useSystemTheme', function() { |
| 180 assertFalse(!!appearancePage.get('prefs.extensions.theme.id.value')); | |
| 181 appearancePage.useSystemTheme_ = true; | |
|
dpapad
2016/10/18 19:37:27
This tests only runs on Linux and therefore the pr
Dan Beam
2016/10/18 21:50:25
Done.
| |
| 182 Polymer.dom.flush(); | |
| 183 // The "USE GTK+" button shouldn't be showing if it's already in use. | |
| 184 assertFalse(!!appearancePage.$$('#useSystem')); | |
| 185 | |
| 186 appearanceBrowserProxy.setIsSupervised(true); | |
| 187 appearancePage.useSystemTheme_ = false; | |
| 188 Polymer.dom.flush(); | |
| 189 // Supervised users have their own theme and can't use GTK+ theme. | |
| 190 assertFalse(!!appearancePage.$$('#useDefault')); | |
| 191 assertFalse(!!appearancePage.$$('#useSystem')); | |
| 192 // If there's no "USE" buttons, the container should be hidden. | |
| 193 assertTrue(appearancePage.$$('.secondary-action').hidden); | |
| 194 | |
| 195 appearanceBrowserProxy.setIsSupervised(false); | |
| 196 appearancePage.set('prefs.extensions.theme.id.value', 'fake theme'); | |
| 197 Polymer.dom.flush(); | |
| 198 // If there's "USE" buttons again, the container should be visible. | |
| 199 assertTrue(!!appearancePage.$$('#useDefault')); | |
| 200 assertFalse(appearancePage.$$('.secondary-action').hidden); | |
| 201 | |
| 146 var button = appearancePage.$$('#useSystem'); | 202 var button = appearancePage.$$('#useSystem'); |
| 147 assertTrue(!!button); | 203 assertTrue(!!button); |
| 204 | |
| 148 MockInteractions.tap(button); | 205 MockInteractions.tap(button); |
| 149 return appearanceBrowserProxy.whenCalled('useSystemTheme'); | 206 return appearanceBrowserProxy.whenCalled('useSystemTheme'); |
| 150 }); | 207 }); |
| 151 } | 208 } |
| 152 }); | 209 }); |
| 153 } | 210 } |
| 154 | 211 |
| 155 function registerAppearanceFontSettingsBrowserTest() { | 212 function registerAppearanceFontSettingsBrowserTest() { |
| 156 var fontsPage = null; | 213 var fontsPage = null; |
| 157 | 214 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 186 }); | 243 }); |
| 187 } | 244 } |
| 188 | 245 |
| 189 return { | 246 return { |
| 190 registerTests: function() { | 247 registerTests: function() { |
| 191 registerAppearanceFontSettingsBrowserTest(); | 248 registerAppearanceFontSettingsBrowserTest(); |
| 192 registerAppearanceSettingsBrowserTest(); | 249 registerAppearanceSettingsBrowserTest(); |
| 193 }, | 250 }, |
| 194 }; | 251 }; |
| 195 }); | 252 }); |
| OLD | NEW |