| 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 var THEME_ID_PREF = 'prefs.extensions.theme.id.value'; |
| 138 var button = appearancePage.$$('#useDefault'); | |
| 139 assertTrue(!!button); | |
| 140 MockInteractions.tap(button); | |
| 141 return appearanceBrowserProxy.whenCalled('useDefaultTheme'); | |
| 142 }); | |
| 143 | 153 |
| 144 if (cr.isLinux && !cr.isChromeOS) { | 154 if (cr.isLinux && !cr.isChromeOS) { |
| 145 test('useSystemTheme', function() { | 155 var USE_SYSTEM_PREF = 'prefs.extensions.theme.use_system.value'; |
| 156 |
| 157 test('useDefaultThemeLinux', function() { |
| 158 assertFalse(!!appearancePage.get(THEME_ID_PREF)); |
| 159 assertFalse(appearancePage.get(USE_SYSTEM_PREF)); |
| 160 // No custom nor system theme in use; "USE CLASSIC" should be hidden. |
| 161 assertFalse(!!appearancePage.$$('#useDefault')); |
| 162 |
| 163 appearancePage.set(USE_SYSTEM_PREF, true); |
| 164 Polymer.dom.flush(); |
| 165 // If the system theme is in use, "USE CLASSIC" should show. |
| 166 assertTrue(!!appearancePage.$$('#useDefault')); |
| 167 |
| 168 appearancePage.set(USE_SYSTEM_PREF, false); |
| 169 appearancePage.set(THEME_ID_PREF, 'fake theme id'); |
| 170 Polymer.dom.flush(); |
| 171 |
| 172 // With a custom theme installed, "USE CLASSIC" should show. |
| 173 var button = appearancePage.$$('#useDefault'); |
| 174 assertTrue(!!button); |
| 175 |
| 176 MockInteractions.tap(button); |
| 177 return appearanceBrowserProxy.whenCalled('useDefaultTheme'); |
| 178 }); |
| 179 |
| 180 test('useSystemThemeLinux', function() { |
| 181 assertFalse(!!appearancePage.get(THEME_ID_PREF)); |
| 182 appearancePage.set(USE_SYSTEM_PREF, true); |
| 183 Polymer.dom.flush(); |
| 184 // The "USE GTK+" button shouldn't be showing if it's already in use. |
| 185 assertFalse(!!appearancePage.$$('#useSystem')); |
| 186 |
| 187 appearanceBrowserProxy.setIsSupervised(true); |
| 188 appearancePage.set(USE_SYSTEM_PREF, false); |
| 189 Polymer.dom.flush(); |
| 190 // Supervised users have their own theme and can't use GTK+ theme. |
| 191 assertFalse(!!appearancePage.$$('#useDefault')); |
| 192 assertFalse(!!appearancePage.$$('#useSystem')); |
| 193 // If there's no "USE" buttons, the container should be hidden. |
| 194 assertTrue(appearancePage.$$('.secondary-action').hidden); |
| 195 |
| 196 appearanceBrowserProxy.setIsSupervised(false); |
| 197 appearancePage.set(THEME_ID_PREF, 'fake theme id'); |
| 198 Polymer.dom.flush(); |
| 199 // If there's "USE" buttons again, the container should be visible. |
| 200 assertTrue(!!appearancePage.$$('#useDefault')); |
| 201 assertFalse(appearancePage.$$('.secondary-action').hidden); |
| 202 |
| 146 var button = appearancePage.$$('#useSystem'); | 203 var button = appearancePage.$$('#useSystem'); |
| 147 assertTrue(!!button); | 204 assertTrue(!!button); |
| 205 |
| 148 MockInteractions.tap(button); | 206 MockInteractions.tap(button); |
| 149 return appearanceBrowserProxy.whenCalled('useSystemTheme'); | 207 return appearanceBrowserProxy.whenCalled('useSystemTheme'); |
| 150 }); | 208 }); |
| 209 } else { |
| 210 test('useDefaultTheme', function() { |
| 211 assertFalse(!!appearancePage.get(THEME_ID_PREF)); |
| 212 assertFalse(!!appearancePage.$$('#useDefault')); |
| 213 |
| 214 appearancePage.set(THEME_ID_PREF, 'fake theme id'); |
| 215 Polymer.dom.flush(); |
| 216 |
| 217 // With a custom theme installed, "RESET TO DEFAULT" should show. |
| 218 var button = appearancePage.$$('#useDefault'); |
| 219 assertTrue(!!button); |
| 220 |
| 221 MockInteractions.tap(button); |
| 222 return appearanceBrowserProxy.whenCalled('useDefaultTheme'); |
| 223 }); |
| 151 } | 224 } |
| 152 }); | 225 }); |
| 153 } | 226 } |
| 154 | 227 |
| 155 function registerAppearanceFontSettingsBrowserTest() { | 228 function registerAppearanceFontSettingsBrowserTest() { |
| 156 var fontsPage = null; | 229 var fontsPage = null; |
| 157 | 230 |
| 158 /** @type {?TestFontsBrowserProxy} */ | 231 /** @type {?TestFontsBrowserProxy} */ |
| 159 var fontsBrowserProxy = null; | 232 var fontsBrowserProxy = null; |
| 160 | 233 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 186 }); | 259 }); |
| 187 } | 260 } |
| 188 | 261 |
| 189 return { | 262 return { |
| 190 registerTests: function() { | 263 registerTests: function() { |
| 191 registerAppearanceFontSettingsBrowserTest(); | 264 registerAppearanceFontSettingsBrowserTest(); |
| 192 registerAppearanceSettingsBrowserTest(); | 265 registerAppearanceSettingsBrowserTest(); |
| 193 }, | 266 }, |
| 194 }; | 267 }; |
| 195 }); | 268 }); |
| OLD | NEW |