Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: chrome/test/data/webui/settings/appearance_page_test.js

Issue 2489723006: MD Settings: split appearance browser tests (Closed)
Patch Set: fonts page Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 /**
6 * @constructor
7 * @implements {settings.AppearanceBrowserProxy}
8 * @extends {settings.TestBrowserProxy}
9 */
10 var TestAppearanceBrowserProxy = function() {
11 settings.TestBrowserProxy.call(this, [
12 'getThemeInfo',
13 'isSupervised',
14 'openWallpaperManager',
15 'useDefaultTheme',
16 'useSystemTheme',
17 ]);
18 };
6 19
7 cr.define('settings_appearance', function() { 20 TestAppearanceBrowserProxy.prototype = {
8 /** 21 __proto__: settings.TestBrowserProxy.prototype,
9 * A test version of AppearanceBrowserProxy.
10 *
11 * @constructor
12 * @implements {settings.AppearanceBrowserProxy}
13 * @extends {settings.TestBrowserProxy}
14 */
15 var TestAppearanceBrowserProxy = function() {
16 settings.TestBrowserProxy.call(this, [
17 'getThemeInfo',
18 'isSupervised',
19 'openWallpaperManager',
20 'useDefaultTheme',
21 'useSystemTheme',
22 ]);
23 };
24 22
25 TestAppearanceBrowserProxy.prototype = { 23 /** @private */
26 __proto__: settings.TestBrowserProxy.prototype, 24 isSupervised_: false,
27 25
28 /** @private */ 26 /** @override */
29 isSupervised_: false, 27 getThemeInfo: function(themeId) {
28 this.methodCalled('getThemeInfo', themeId);
29 return Promise.resolve({name: 'Sports car red'});
30 },
30 31
31 /** @override */ 32 /** @override */
32 getThemeInfo: function(themeId) { 33 isSupervised: function() {
33 this.methodCalled('getThemeInfo', themeId); 34 this.methodCalled('isSupervised');
34 return Promise.resolve({name: 'Sports car red'}); 35 return this.isSupervised_;
35 }, 36 },
36 37
37 /** @override */ 38 /** @override */
38 isSupervised: function() { 39 openWallpaperManager: function() {
39 this.methodCalled('isSupervised'); 40 this.methodCalled('openWallpaperManager');
40 return this.isSupervised_; 41 },
41 },
42 42
43 /** @override */ 43 /** @override */
44 openWallpaperManager: function() { 44 useDefaultTheme: function() {
45 this.methodCalled('openWallpaperManager'); 45 this.methodCalled('useDefaultTheme');
46 }, 46 },
47 47
48 /** @override */ 48 /** @override */
49 useDefaultTheme: function() { 49 useSystemTheme: function() {
50 this.methodCalled('useDefaultTheme'); 50 this.methodCalled('useSystemTheme');
51 }, 51 },
52 52
53 /** @override */ 53 /** @param {boolean} Whether the user is supervised */
54 useSystemTheme: function() { 54 setIsSupervised: function(isSupervised) {
55 this.methodCalled('useSystemTheme'); 55 this.isSupervised_ = isSupervised;
56 }, 56 },
57 };
57 58
58 /** @param {boolean} Whether the user is supervised */ 59 var appearancePage = null;
59 setIsSupervised: function(isSupervised) {
60 this.isSupervised_ = isSupervised;
61 },
62 };
63 60
64 /** 61 /** @type {?TestAppearanceBrowserProxy} */
65 * A test version of FontsBrowserProxy. 62 var appearanceBrowserProxy = null;
66 *
67 * @constructor
68 * @implements {settings.FontsBrowserProxy}
69 * @extends {settings.TestBrowserProxy}
70 */
71 var TestFontsBrowserProxy = function() {
72 settings.TestBrowserProxy.call(this, [
73 'fetchFontsData',
74 'observeAdvancedFontExtensionAvailable',
75 'openAdvancedFontSettings',
76 ]);
77 63
78 /** @private {!FontsData} */ 64 suite('AppearanceHandler', function() {
79 this.fontsData_ = { 65 setup(function() {
80 'fontList': [['font name', 'alternate', 'ltr']], 66 appearanceBrowserProxy = new TestAppearanceBrowserProxy();
81 'encodingList': [['encoding name', 'alternate', 'ltr']], 67 settings.AppearanceBrowserProxyImpl.instance_ = appearanceBrowserProxy;
82 };
83 };
84 68
85 TestFontsBrowserProxy.prototype = { 69 PolymerTest.clearBody();
86 __proto__: settings.TestBrowserProxy.prototype,
87 70
88 /** @override */ 71 appearancePage = document.createElement('settings-appearance-page');
89 fetchFontsData: function() { 72 appearancePage.set('prefs', {
90 this.methodCalled('fetchFontsData'); 73 extensions: {
91 return Promise.resolve(this.fontsData_); 74 theme: {
92 }, 75 id: {
76 value: '',
77 },
78 use_system: {
79 value: false,
80 },
81 },
82 },
83 });
84 document.body.appendChild(appearancePage);
85 Polymer.dom.flush();
86 });
93 87
94 /** @override */ 88 teardown(function() { appearancePage.remove(); });
95 observeAdvancedFontExtensionAvailable: function() {
96 this.methodCalled('observeAdvancedFontExtensionAvailable');
97 },
98 89
99 /** @override */ 90 if (cr.isChromeOS) {
100 openAdvancedFontSettings: function() { 91 test('wallpaperManager', function() {
101 this.methodCalled('openAdvancedFontSettings'); 92 var button = appearancePage.$.wallpaperButton;
102 }, 93 assertTrue(!!button);
103 }; 94 MockInteractions.tap(button);
104 95 return appearanceBrowserProxy.whenCalled('openWallpaperManager');
105 function registerAppearanceSettingsBrowserTest() { 96 });
106 var appearancePage = null; 97 } else {
107 98 test('noWallpaperManager', function() {
108 /** @type {?TestAppearanceBrowserProxy} */ 99 // The wallpaper button should not be present.
109 var appearanceBrowserProxy = null; 100 var button = appearancePage.$.wallpaperButton;
110 101 assertFalse(!!button);
111 suite('AppearanceHandler', function() {
112 setup(function() {
113 appearanceBrowserProxy = new TestAppearanceBrowserProxy();
114 settings.AppearanceBrowserProxyImpl.instance_ = appearanceBrowserProxy;
115
116 PolymerTest.clearBody();
117
118 appearancePage = document.createElement('settings-appearance-page');
119 appearancePage.set('prefs', {
120 extensions: {
121 theme: {
122 id: {
123 value: '',
124 },
125 use_system: {
126 value: false,
127 },
128 },
129 },
130 });
131 document.body.appendChild(appearancePage);
132 Polymer.dom.flush();
133 });
134
135 teardown(function() { appearancePage.remove(); });
136
137 if (cr.isChromeOS) {
138 test('wallpaperManager', function() {
139 var button = appearancePage.$.wallpaperButton;
140 assertTrue(!!button);
141 MockInteractions.tap(button);
142 return appearanceBrowserProxy.whenCalled('openWallpaperManager');
143 });
144 } else {
145 test('noWallpaperManager', function() {
146 // The wallpaper button should not be present.
147 var button = appearancePage.$.wallpaperButton;
148 assertFalse(!!button);
149 });
150 }
151
152 var THEME_ID_PREF = 'prefs.extensions.theme.id.value';
153
154 if (cr.isLinux && !cr.isChromeOS) {
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
203 var button = appearancePage.$$('#useSystem');
204 assertTrue(!!button);
205
206 MockInteractions.tap(button);
207 return appearanceBrowserProxy.whenCalled('useSystemTheme');
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 });
224 }
225 }); 102 });
226 } 103 }
227 104
228 function registerAppearanceFontSettingsBrowserTest() { 105 var THEME_ID_PREF = 'prefs.extensions.theme.id.value';
229 var fontsPage = null;
230 106
231 /** @type {?TestFontsBrowserProxy} */ 107 if (cr.isLinux && !cr.isChromeOS) {
232 var fontsBrowserProxy = null; 108 var USE_SYSTEM_PREF = 'prefs.extensions.theme.use_system.value';
233 109
234 suite('AppearanceFontHandler', function() { 110 test('useDefaultThemeLinux', function() {
235 setup(function() { 111 assertFalse(!!appearancePage.get(THEME_ID_PREF));
236 fontsBrowserProxy = new TestFontsBrowserProxy(); 112 assertFalse(appearancePage.get(USE_SYSTEM_PREF));
237 settings.FontsBrowserProxyImpl.instance_ = fontsBrowserProxy; 113 // No custom nor system theme in use; "USE CLASSIC" should be hidden.
114 assertFalse(!!appearancePage.$$('#useDefault'));
238 115
239 PolymerTest.clearBody(); 116 appearancePage.set(USE_SYSTEM_PREF, true);
117 Polymer.dom.flush();
118 // If the system theme is in use, "USE CLASSIC" should show.
119 assertTrue(!!appearancePage.$$('#useDefault'));
240 120
241 fontsPage = document.createElement('settings-appearance-fonts-page'); 121 appearancePage.set(USE_SYSTEM_PREF, false);
242 document.body.appendChild(fontsPage); 122 appearancePage.set(THEME_ID_PREF, 'fake theme id');
243 }); 123 Polymer.dom.flush();
244 124
245 teardown(function() { fontsPage.remove(); }); 125 // With a custom theme installed, "USE CLASSIC" should show.
126 var button = appearancePage.$$('#useDefault');
127 assertTrue(!!button);
246 128
247 test('fetchFontsData', function() { 129 MockInteractions.tap(button);
248 return fontsBrowserProxy.whenCalled('fetchFontsData'); 130 return appearanceBrowserProxy.whenCalled('useDefaultTheme');
249 }); 131 });
250 132
251 test('openAdvancedFontSettings', function() { 133 test('useSystemThemeLinux', function() {
252 cr.webUIListenerCallback('advanced-font-settings-installed', [true]); 134 assertFalse(!!appearancePage.get(THEME_ID_PREF));
253 Polymer.dom.flush(); 135 appearancePage.set(USE_SYSTEM_PREF, true);
254 var button = fontsPage.$$('#advancedButton'); 136 Polymer.dom.flush();
255 assert(!!button); 137 // The "USE GTK+" button shouldn't be showing if it's already in use.
256 MockInteractions.tap(button); 138 assertFalse(!!appearancePage.$$('#useSystem'));
257 return fontsBrowserProxy.whenCalled('openAdvancedFontSettings'); 139
258 }); 140 appearanceBrowserProxy.setIsSupervised(true);
141 appearancePage.set(USE_SYSTEM_PREF, false);
142 Polymer.dom.flush();
143 // Supervised users have their own theme and can't use GTK+ theme.
144 assertFalse(!!appearancePage.$$('#useDefault'));
145 assertFalse(!!appearancePage.$$('#useSystem'));
146 // If there's no "USE" buttons, the container should be hidden.
147 assertTrue(appearancePage.$$('.secondary-action').hidden);
148
149 appearanceBrowserProxy.setIsSupervised(false);
150 appearancePage.set(THEME_ID_PREF, 'fake theme id');
151 Polymer.dom.flush();
152 // If there's "USE" buttons again, the container should be visible.
153 assertTrue(!!appearancePage.$$('#useDefault'));
154 assertFalse(appearancePage.$$('.secondary-action').hidden);
155
156 var button = appearancePage.$$('#useSystem');
157 assertTrue(!!button);
158
159 MockInteractions.tap(button);
160 return appearanceBrowserProxy.whenCalled('useSystemTheme');
161 });
162 } else {
163 test('useDefaultTheme', function() {
164 assertFalse(!!appearancePage.get(THEME_ID_PREF));
165 assertFalse(!!appearancePage.$$('#useDefault'));
166
167 appearancePage.set(THEME_ID_PREF, 'fake theme id');
168 Polymer.dom.flush();
169
170 // With a custom theme installed, "RESET TO DEFAULT" should show.
171 var button = appearancePage.$$('#useDefault');
172 assertTrue(!!button);
173
174 MockInteractions.tap(button);
175 return appearanceBrowserProxy.whenCalled('useDefaultTheme');
259 }); 176 });
260 } 177 }
261
262 return {
263 registerTests: function() {
264 registerAppearanceFontSettingsBrowserTest();
265 registerAppearanceSettingsBrowserTest();
266 },
267 };
268 }); 178 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698