Chromium Code Reviews| Index: chrome/test/data/webui/settings/site_settings_category_tests.js |
| diff --git a/chrome/test/data/webui/settings/site_settings_category_tests.js b/chrome/test/data/webui/settings/site_settings_category_tests.js |
| index c82f668c5a9613bc2f1a7bfdd6a68ab470bbd56c..29419069c4e486804c79e9e324305a3dbfb2a5c3 100644 |
| --- a/chrome/test/data/webui/settings/site_settings_category_tests.js |
| +++ b/chrome/test/data/webui/settings/site_settings_category_tests.js |
| @@ -51,18 +51,46 @@ cr.define('site_settings_category', function() { |
| document.body.appendChild(testElement); |
| }); |
| - test('categoryEnabled correctly represents prefs', function() { |
| + /** |
| + * Returns a promise that resolves once the selected item is updated. |
| + * @param {function()} action is executed after the listener is set up. |
| + * @return {!Promise} a Promise fulfilled when the selected item changes. |
| + */ |
| + function runAndResolveWhenCategoryEnabledChanged(action) { |
| + return new Promise(function(resolve, reject) { |
| + var handler = function() { |
| + testElement.removeEventListener( |
| + 'category-enabled-changed', handler); |
| + resolve(); |
| + }; |
| + testElement.addEventListener('category-enabled-changed', handler); |
| + action(); |
| + }); |
| + } |
| + |
| + test('categoryEnabled correctly represents prefs (enabled)', function() { |
| testElement.category = settings.ContentSettingsTypes.GEOLOCATION; |
| - testElement.prefs = prefsLocationEnabled; |
| - assertTrue(testElement.categoryEnabled); |
| - MockInteractions.tap(testElement.$.toggle); |
| - assertFalse(testElement.categoryEnabled); |
| + return runAndResolveWhenCategoryEnabledChanged(function() { |
| + testElement.prefs = prefsLocationEnabled; |
| + }).then(function() { |
| + assertTrue(testElement.categoryEnabled); |
| + MockInteractions.tap(testElement.$.toggle); |
| + assertFalse(testElement.categoryEnabled); |
| + }); |
| + }); |
| + |
| + test('categoryEnabled correctly represents prefs (disabled)', function() { |
| + testElement.category = settings.ContentSettingsTypes.GEOLOCATION; |
| - testElement.prefs = prefsLocationDisabled; |
| - assertFalse(testElement.categoryEnabled); |
| - MockInteractions.tap(testElement.$.toggle); |
| - assertTrue(testElement.categoryEnabled); |
| + testElement.categoryEnabled = true; // Ensure change event fires. |
|
tommycli
2016/02/17 18:18:06
Is this really to ensure the change event fires? O
Finnur
2016/02/18 20:38:18
The answer is 'both' (unless I'm misunderstanding
tommycli
2016/02/18 22:15:18
Optional nit: Would it make more sense to do somet
Finnur
2016/02/19 10:18:13
No, at a glance I don't think so. The 'change' eve
|
| + return runAndResolveWhenCategoryEnabledChanged(function() { |
| + testElement.prefs = prefsLocationDisabled; |
| + }).then(function() { |
| + assertFalse(testElement.categoryEnabled); |
| + MockInteractions.tap(testElement.$.toggle); |
| + assertTrue(testElement.categoryEnabled); |
| + }); |
| }); |
| test('basic category tests', function() { |