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