Index: chrome/test/data/webui/settings/startup_urls_page_test.js |
diff --git a/chrome/test/data/webui/settings/startup_urls_page_test.js b/chrome/test/data/webui/settings/startup_urls_page_test.js |
index 1c4490aa0365a441bd5c69b0c48adbfddf5c8dd5..038017ee7abc6211dbc845b8208d52b268a873d4 100644 |
--- a/chrome/test/data/webui/settings/startup_urls_page_test.js |
+++ b/chrome/test/data/webui/settings/startup_urls_page_test.js |
@@ -10,33 +10,126 @@ cr.define('settings_startup_urls_page', function() { |
*/ |
function TestStartupUrlsPageBrowserProxy() { |
settings.TestBrowserProxy.call(this, [ |
- 'validateStartupPage', |
'addStartupPage', |
+ 'loadStartupPages', |
+ 'useCurrentPages', |
+ 'validateStartupPage', |
]); |
+ |
+ /** @private {boolean} */ |
+ this.urlIsValid_ = true; |
} |
TestStartupUrlsPageBrowserProxy.prototype = { |
__proto__: settings.TestBrowserProxy.prototype, |
- urlsAreValid: false, |
+ /** @param {boolean} isValid */ |
+ setUrlValidity: function(isValid) { |
+ this.urlIsValid_ = isValid; |
+ }, |
+ |
+ /** @override */ |
+ addStartupPage: function(url) { |
+ this.methodCalled('addStartupPage', url); |
+ return Promise.resolve(this.urlIsValid_); |
+ }, |
/** @override */ |
- loadStartupPages: function() {}, |
+ loadStartupPages: function() { |
+ this.methodCalled('loadStartupPages'); |
+ }, |
/** @override */ |
- validateStartupPage: function(url) { |
- this.methodCalled('validateStartupPage'); |
- var resolver = new PromiseResolver; |
- resolver.promise = Promise.resolve(this.urlsAreValid); |
- return resolver; |
+ useCurrentPages: function() { |
+ this.methodCalled('useCurrentPages'); |
}, |
/** @override */ |
- addStartupPage: function(url) { |
- this.methodCalled('addStartupPage'); |
+ validateStartupPage: function(url) { |
+ this.methodCalled('validateStartupPage', url); |
+ return Promise.resolve(this.urlIsValid_); |
}, |
}; |
+ suite('StartupUrlDialog', function() { |
+ /** @type {?SettingsStartupUrlDialogElement} */ |
+ var dialog = null; |
+ |
+ var browserProxy = null; |
+ |
+ /** |
+ * Triggers an 'input' event on the given text input field, which triggers |
+ * validation to occur. |
+ * @param {!PaperInputElement} element |
+ */ |
+ function pressSpace(element) { |
+ // The actual key code is irrelevant for these tests. |
+ MockInteractions.keyEventOn(element, 'input', 32 /* space key code */); |
+ } |
+ |
+ setup(function() { |
+ browserProxy = new TestStartupUrlsPageBrowserProxy(); |
+ settings.StartupUrlsPageBrowserProxyImpl.instance_ = browserProxy; |
+ PolymerTest.clearBody(); |
+ dialog = document.createElement('settings-startup-url-dialog'); |
+ document.body.appendChild(dialog); |
+ }); |
+ |
+ teardown(function() { dialog.remove(); }); |
+ |
+ // Test that validation occurs as the user is typing, and that the action |
+ // button is updated accordingly. |
+ test('Validation', function() { |
+ assertTrue(dialog.$.dialog.opened); |
+ var addButton = dialog.$.add; |
+ assertTrue(!!addButton); |
+ assertTrue(addButton.disabled); |
+ |
+ var inputElement = dialog.$.url; |
+ assertTrue(!!inputElement); |
+ |
+ var expectedUrl = "dummy-foo.com"; |
+ inputElement.value = expectedUrl; |
+ browserProxy.setUrlValidity(false); |
+ pressSpace(inputElement); |
+ |
+ return browserProxy.whenCalled('validateStartupPage').then(function(url) { |
+ assertEquals(expectedUrl, url); |
+ assertTrue(addButton.disabled); |
+ |
+ browserProxy.setUrlValidity(true); |
+ browserProxy.resetResolver('validateStartupPage'); |
+ pressSpace(inputElement); |
+ |
+ return browserProxy.whenCalled('validateStartupPage'); |
+ }).then(function() { |
+ assertFalse(addButton.disabled); |
+ }); |
+ }); |
+ |
+ test('AddStartupPage', function() { |
+ assertTrue(dialog.$.dialog.opened); |
+ var addButton = dialog.$.add; |
+ addButton.disabled = false; |
+ |
+ // Test that the dialog remains open if the user somehow manages to submit |
+ // an invalid URL. |
+ browserProxy.setUrlValidity(false); |
+ MockInteractions.tap(addButton); |
+ return browserProxy.whenCalled('addStartupPage').then(function() { |
+ assertTrue(dialog.$.dialog.opened); |
+ |
+ // Test that dialog is closed if the user submits a valid URL. |
+ browserProxy.setUrlValidity(true); |
+ browserProxy.resetResolver('addStartupPage'); |
+ MockInteractions.tap(addButton); |
+ return browserProxy.whenCalled('addStartupPage'); |
+ }).then(function() { |
+ assertFalse(dialog.$.dialog.opened); |
+ }); |
+ }); |
+ }); |
+ |
suite('StartupUrlsPage', function() { |
/** @type {?SettingsStartupUrlsPageElement} */ |
var page = null; |
@@ -53,26 +146,26 @@ cr.define('settings_startup_urls_page', function() { |
teardown(function() { page.remove(); }); |
- test('validate', function() { |
- browserProxy.whenCalled('validateStartupPage').then(function() { |
- var addButton = page.$.add; |
- assertTrue(!!addButton); |
- assertFalse(browserProxy.urlsAreValid); |
- assertTrue(addButton.disabled); |
+ // Test that the page is requesting information from the browser. |
+ test('Initialization', function() { |
+ return browserProxy.whenCalled('loadStartupPages'); |
+ }); |
- browserProxy.resetResolver('validateStartupPage'); |
- browserProxy.whenCalled('validateStartupPage').then(function() { |
- page.async(function() { |
- assertFalse(addButton.disabled); |
- MockInteractions.tap(addButton); |
- }); |
- }); |
- |
- browserProxy.urlsAreValid = true; |
- page.$.newUrl.value = "overriding validation anyway"; |
- }); |
+ test('UseCurrentPages', function() { |
+ var useCurrentPagesButton = page.$.useCurrentPages; |
+ assertTrue(!!useCurrentPagesButton); |
+ MockInteractions.tap(useCurrentPagesButton); |
+ return browserProxy.whenCalled('useCurrentPages'); |
+ }); |
+ |
+ test('AddPage_OpensDialog', function() { |
+ var addPageButton = page.$.addPage; |
+ assertTrue(!!addPageButton); |
+ assertFalse(!!page.$$('settings-startup-url-dialog')); |
- return browserProxy.whenCalled('addStartupPage'); |
+ MockInteractions.tap(addPageButton); |
+ Polymer.dom.flush(); |
+ assertTrue(!!page.$$('settings-startup-url-dialog')); |
}); |
}); |
}); |