Normalize download_scheme preference to lower case in PG

Bug: Issue 5180
Bug: Issue 5142
Change-Id: Ic946e0b11b2eceb2568b1f6f33981682c65fd1e1
This commit is contained in:
Wyatt Allen
2016-12-20 14:50:55 -08:00
parent 42ea853037
commit f446363803
4 changed files with 36 additions and 2 deletions

View File

@@ -66,7 +66,8 @@
if (!loggedIn) { return; }
this.$.restAPI.getPreferences().then(function(prefs) {
if (prefs.download_scheme) {
this._selectedScheme = prefs.download_scheme;
// Note (issue 5180): normalize the download scheme with lower-case.
this._selectedScheme = prefs.download_scheme.toLowerCase();
}
}.bind(this));
},
@@ -74,7 +75,8 @@
_computeDownloadCommands: function(change, patchNum, _selectedScheme) {
var commandObj;
for (var rev in change.revisions) {
if (change.revisions[rev]._number == patchNum) {
if (change.revisions[rev]._number == patchNum &&
change.revisions[rev].fetch.hasOwnProperty(_selectedScheme)) {
commandObj = change.revisions[rev].fetch[_selectedScheme].commands;
break;
}

View File

@@ -226,4 +226,23 @@ limitations under the License.
firstSchemeButton.getAttribute('data-scheme'));
});
});
test('normalize scheme from preferences', function(done) {
stub('gr-rest-api-interface', {
getPreferences: function() {
return Promise.resolve({download_scheme: 'REPO'});
},
});
element = fixture('loggedIn');
element.change = getChangeObject();
element.patchNum = 1;
element.config = {
schemes: {'anonymous http': {}, http: {}, repo: {}, ssh: {}},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
assert.equal(element._selectedScheme, 'repo');
done();
});
});
</script>

View File

@@ -212,6 +212,12 @@
},
savePreferences: function(prefs, opt_errFn, opt_ctx) {
// Note (Issue 5142): normalize the download scheme with lower case before
// saving.
if (prefs.download_scheme) {
prefs.download_scheme = prefs.download_scheme.toLowerCase();
}
return this.send('PUT', '/accounts/self/preferences', prefs, opt_errFn,
opt_ctx);
},

View File

@@ -412,5 +412,12 @@ limitations under the License.
done();
});
});
test('savPreferences normalizes download scheme', function() {
var sendStub = sandbox.stub(element, 'send');
element.savePreferences({download_scheme: 'HTTP'});
assert.isTrue(sendStub.called);
assert.equal(sendStub.lastCall.args[2].download_scheme, 'http');
});
});
</script>