Commit 1047884d authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Disable the "Add" share button when a share path mount error occurs

If attempting to add a share results in an "invalid URL" error, the
"Add" button should be disabled until the share URL is changed.

BUG=926138

Change-Id: I21b1387b0c73683ed9a3e0a60dcdf710911b5057
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1634031Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Anand Mistry <amistry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665772}
parent df6f17d9
...@@ -9,6 +9,8 @@ class TestSmbBrowserProxy extends TestBrowserProxy { ...@@ -9,6 +9,8 @@ class TestSmbBrowserProxy extends TestBrowserProxy {
'smbMount', 'smbMount',
'startDiscovery', 'startDiscovery',
]); ]);
/** @type{!SmbMountResult} */
this.smbMountResult = SmbMountResult.SUCCESS;
} }
/** @override */ /** @override */
...@@ -16,7 +18,7 @@ class TestSmbBrowserProxy extends TestBrowserProxy { ...@@ -16,7 +18,7 @@ class TestSmbBrowserProxy extends TestBrowserProxy {
this.methodCalled( this.methodCalled(
'smbMount', 'smbMount',
[smbUrl, smbName, username, password, authMethod, inSettings]); [smbUrl, smbName, username, password, authMethod, inSettings]);
return Promise.resolve(SmbMountResult.SUCCESS); return Promise.resolve(this.smbMountResult);
} }
/** @override */ /** @override */
...@@ -137,6 +139,7 @@ suite('AddSmbShareDialogTests', function() { ...@@ -137,6 +139,7 @@ suite('AddSmbShareDialogTests', function() {
addDialog.authenticationMethod_ = expectedAuthMethod; addDialog.authenticationMethod_ = expectedAuthMethod;
addDialog.shouldOpenFileManagerAfterMount = expectedShouldOpenFileManager; addDialog.shouldOpenFileManagerAfterMount = expectedShouldOpenFileManager;
smbBrowserProxy.resetResolver('smbMount');
addButton.click(); addButton.click();
return smbBrowserProxy.whenCalled('smbMount').then(function(args) { return smbBrowserProxy.whenCalled('smbMount').then(function(args) {
expectEquals(expectedSmbUrl, args[0]); expectEquals(expectedSmbUrl, args[0]);
...@@ -230,4 +233,29 @@ suite('AddSmbShareDialogTests', function() { ...@@ -230,4 +233,29 @@ suite('AddSmbShareDialogTests', function() {
expectEquals(expectedSmbUrl, addDialog.mountUrl_); expectEquals(expectedSmbUrl, addDialog.mountUrl_);
expectEquals(expectedSmbUrl, addDialog.mountUrl_); expectEquals(expectedSmbUrl, addDialog.mountUrl_);
}); });
test('InvalidUrlErrorDisablesAddButton', function() {
const url = addDialog.$.address;
const addButton = addDialog.$$('.action-button');
// Invalid URL, but passes regex test.
url.value = 'smb://foo\\\\/bar';
expectFalse(addButton.disabled);
smbBrowserProxy.smbMountResult = SmbMountResult.INVALID_URL;
addButton.click();
return new Promise((resolve, reject) => {
const pollFunc = () => {
if (url.errorMessage && addButton.disabled) {
resolve();
return;
}
setTimeout(pollFunc, 100);
};
// url.errorMessage can't be observed for a change, so instead, poll.
pollFunc();
});
});
}); });
...@@ -115,7 +115,7 @@ ...@@ -115,7 +115,7 @@
[[i18n('cancel')]] [[i18n('cancel')]]
</paper-button> </paper-button>
<paper-button class="action-button" on-click="onAddButtonTap_" <paper-button class="action-button" on-click="onAddButtonTap_"
disabled="[[!canAddShare_(mountUrl_, inProgress_)]]"> disabled="[[!canAddShare_(mountUrl_, inProgress_, currentMountError_)]]">
[[i18n('add')]] [[i18n('add')]]
</paper-button> </paper-button>
</div> </div>
......
...@@ -298,7 +298,7 @@ Polymer({ ...@@ -298,7 +298,7 @@ Polymer({
* @private * @private
*/ */
isShareUrlValid_: function() { isShareUrlValid_: function() {
if (!this.mountUrl_) { if (!this.mountUrl_ || this.shouldShowPathError_()) {
return false; return false;
} }
return smb_shares.SMB_SHARE_URL_REGEX.test(this.mountUrl_); return smb_shares.SMB_SHARE_URL_REGEX.test(this.mountUrl_);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment