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. | |
10 * | |
11 * @constructor | |
12 * @implements {settings.AppearanceBrowserProxy} | |
13 * @extends {settings.TestBrowserProxy} | |
14 */ | |
15 var TestAppearanceBrowserProxy = function() { | |
16 settings.TestBrowserProxy.call(this, [ | |
17 'getResetThemeEnabled', | |
18 'openWallpaperManager', | |
19 'resetTheme', | |
20 ]); | |
21 | |
22 this.allowResetTheme = false; | |
dpapad
2016/04/19 23:32:40
Nit: @type {boolean}
dschuyler
2016/04/20 00:19:07
Done.
| |
23 }; | |
24 | |
25 TestAppearanceBrowserProxy.prototype = { | |
26 __proto__: settings.TestBrowserProxy.prototype, | |
27 | |
28 /** @override */ | |
29 getResetThemeEnabled: function() { | |
30 this.methodCalled('getResetThemeEnabled'); | |
31 return Promise.resolve(this.allowResetTheme); | |
32 }, | |
33 | |
34 /** @override */ | |
35 openWallpaperManager: function() { | |
36 this.methodCalled('openWallpaperManager'); | |
37 }, | |
38 | |
39 /** @override */ | |
40 resetTheme: function() { | |
41 this.methodCalled('resetTheme'); | |
42 }, | |
43 | |
44 setAllowResetTheme: function(isEnabled) { | |
45 this.allowResetTheme = isEnabled; | |
46 cr.webUIListenerCallback('reset-theme-enabled-changed', isEnabled); | |
47 Polymer.dom.flush(); | |
48 } | |
49 }; | |
50 | |
51 /** | |
9 * A test version of FontsBrowserProxy. | 52 * A test version of FontsBrowserProxy. |
10 * | 53 * |
11 * @constructor | 54 * @constructor |
12 * @implements {settings.FontsBrowserProxy} | 55 * @implements {settings.FontsBrowserProxy} |
13 * @extends {settings.TestBrowserProxy} | 56 * @extends {settings.TestBrowserProxy} |
14 */ | 57 */ |
15 var TestFontsBrowserProxy = function() { | 58 var TestFontsBrowserProxy = function() { |
16 settings.TestBrowserProxy.call(this, [ | 59 settings.TestBrowserProxy.call(this, [ |
17 'fetchFontsData', | 60 'fetchFontsData', |
18 'observeAdvancedFontExtensionAvailable', | 61 'observeAdvancedFontExtensionAvailable', |
62 'openAdvancedFontSettings', | |
19 ]); | 63 ]); |
20 | 64 |
21 /** @private {!FontsData} */ | 65 /** @private {!FontsData} */ |
22 this.fontsData_ = { | 66 this.fontsData_ = { |
23 'fontList': [['font name', 'alternate', 'ltr']], | 67 'fontList': [['font name', 'alternate', 'ltr']], |
24 'encodingList': [['encoding name', 'alternate', 'ltr']], | 68 'encodingList': [['encoding name', 'alternate', 'ltr']], |
25 }; | 69 }; |
26 }; | 70 }; |
27 | 71 |
28 TestFontsBrowserProxy.prototype = { | 72 TestFontsBrowserProxy.prototype = { |
29 __proto__: settings.TestBrowserProxy.prototype, | 73 __proto__: settings.TestBrowserProxy.prototype, |
30 | 74 |
31 /** @override */ | 75 /** @override */ |
32 fetchFontsData: function() { | 76 fetchFontsData: function() { |
33 this.methodCalled('fetchFontsData'); | 77 this.methodCalled('fetchFontsData'); |
34 return Promise.resolve(this.fontsData_); | 78 return Promise.resolve(this.fontsData_); |
35 }, | 79 }, |
36 | 80 |
37 /** @override */ | 81 /** @override */ |
38 observeAdvancedFontExtensionAvailable: function() { | 82 observeAdvancedFontExtensionAvailable: function() { |
39 this.methodCalled('observeAdvancedFontExtensionAvailable'); | 83 this.methodCalled('observeAdvancedFontExtensionAvailable'); |
40 }, | 84 }, |
85 | |
86 /** @override */ | |
87 openAdvancedFontSettings: function() { | |
88 this.methodCalled('openAdvancedFontSettings'); | |
89 }, | |
41 }; | 90 }; |
42 | 91 |
92 function registerAppearanceSettingsBrowserTest() { | |
93 var appearancePage = null; | |
94 | |
95 /** @type {?TestAppearanceBrowserProxy} */ | |
96 var appearanceBrowserProxy = null; | |
97 | |
98 suite('AppearanceHandler', function() { | |
99 setup(function() { | |
100 appearanceBrowserProxy = new TestAppearanceBrowserProxy(); | |
101 settings.AppearanceBrowserProxyImpl.instance_ = appearanceBrowserProxy; | |
102 | |
103 PolymerTest.clearBody(); | |
104 | |
105 appearancePage = document.createElement('settings-appearance-page'); | |
106 document.body.appendChild(appearancePage); | |
107 | |
108 return Promise.all([ | |
109 PolymerTest.importHtml('chrome://md-settings/i18n_setup.html'), | |
dpapad
2016/04/19 23:32:40
Is this necessary? Can it be added as a dependency
dschuyler
2016/04/20 00:19:07
Done.
| |
110 ]); | |
111 }); | |
112 | |
113 teardown(function() { appearancePage.remove(); }); | |
114 | |
115 if (cr.isChromeOS) { | |
116 test('wallpaperManager', function() { | |
117 var button = appearancePage.$$('#wallpaperButton'); | |
dpapad
2016/04/19 23:32:40
Nit: Does the following work?
var button = appear
dschuyler
2016/04/20 00:19:07
Done.
| |
118 assert(!!button); | |
dpapad
2016/04/19 23:32:40
Nit(optional): assertTrue(!!button).
Effectively
dschuyler
2016/04/20 00:19:07
Done.
| |
119 MockInteractions.tap(button); | |
120 return appearanceBrowserProxy.whenCalled('openWallpaperManager'); | |
121 }); | |
122 } else { | |
123 test('noWallpaperManager', function() { | |
124 // The wallpaper button should not be present. | |
125 var button = appearancePage.$$('#wallpaperButton'); | |
126 assert(!button); | |
127 }); | |
128 } | |
129 | |
130 test('resetTheme', function() { | |
131 appearanceBrowserProxy.setAllowResetTheme(true); | |
132 var button = appearancePage.$$('#resetTheme'); | |
133 assert(!!button); | |
134 MockInteractions.tap(button); | |
135 return appearanceBrowserProxy.whenCalled('resetTheme'); | |
136 }); | |
137 }); | |
138 } | |
139 | |
43 function registerAppearanceFontSettingsBrowserTest() { | 140 function registerAppearanceFontSettingsBrowserTest() { |
44 var fontsPage = null; | 141 var fontsPage = null; |
45 | 142 |
46 /** @type {?TestFontsBrowserProxy} */ | 143 /** @type {?TestFontsBrowserProxy} */ |
47 var fontsBrowserProxy = null; | 144 var fontsBrowserProxy = null; |
48 | 145 |
49 suite('AppearanceFontHandler', function() { | 146 suite('AppearanceFontHandler', function() { |
50 setup(function() { | 147 setup(function() { |
51 fontsBrowserProxy = new TestFontsBrowserProxy(); | 148 fontsBrowserProxy = new TestFontsBrowserProxy(); |
52 settings.FontsBrowserProxyImpl.instance_ = fontsBrowserProxy; | 149 settings.FontsBrowserProxyImpl.instance_ = fontsBrowserProxy; |
53 | 150 |
54 PolymerTest.clearBody(); | 151 PolymerTest.clearBody(); |
55 | 152 |
56 fontsPage = document.createElement('settings-appearance-fonts-page'); | 153 fontsPage = document.createElement('settings-appearance-fonts-page'); |
57 document.body.appendChild(fontsPage); | 154 document.body.appendChild(fontsPage); |
58 }); | 155 }); |
59 | 156 |
60 teardown(function() { fontsPage.remove(); }); | 157 teardown(function() { fontsPage.remove(); }); |
61 | 158 |
62 test('fetchFontsData', function() { | 159 test('fetchFontsData', function() { |
63 return fontsBrowserProxy.whenCalled('fetchFontsData'); | 160 return fontsBrowserProxy.whenCalled('fetchFontsData'); |
64 }); | 161 }); |
162 | |
163 test('openAdvancedFontSettings', function() { | |
164 cr.webUIListenerCallback('advanced-font-settings-installed', [true]); | |
165 Polymer.dom.flush(); | |
166 var button = fontsPage.$$('#advancedButton'); | |
167 assert(!!button); | |
168 MockInteractions.tap(button); | |
169 return fontsBrowserProxy.whenCalled('openAdvancedFontSettings'); | |
170 }); | |
65 }); | 171 }); |
66 } | 172 } |
67 | 173 |
68 return { | 174 return { |
69 registerTests: function() { | 175 registerTests: function() { |
70 registerAppearanceFontSettingsBrowserTest(); | 176 registerAppearanceFontSettingsBrowserTest(); |
177 registerAppearanceSettingsBrowserTest(); | |
71 }, | 178 }, |
72 }; | 179 }; |
73 }); | 180 }); |
OLD | NEW |