Avoid opening files at invalid file cursor index
This usually occurs when files are being rapidly switched through -- the file cursor hasn't been initialized yet, Change-Id: I05a874c4f0adb601f8934bfc0a7ee5b1315cd017
This commit is contained in:
@@ -579,6 +579,7 @@
|
||||
if (opt_index != null) {
|
||||
this.$.fileCursor.setCursorAtIndex(opt_index);
|
||||
}
|
||||
if (!this._files[this.$.fileCursor.index]) { return; }
|
||||
page.show(this._computeDiffURL(this.changeNum, this.patchRange,
|
||||
this._files[this.$.fileCursor.index].__path));
|
||||
},
|
||||
|
||||
@@ -1168,5 +1168,20 @@ limitations under the License.
|
||||
assert.isTrue(element._showInlineDiffs);
|
||||
});
|
||||
});
|
||||
|
||||
test('_openSelectedFile behavior', () => {
|
||||
const _files = element._files;
|
||||
element.set('_files', []);
|
||||
const showStub = sandbox.stub(page, 'show');
|
||||
// Noop when there are no files.
|
||||
element._openSelectedFile();
|
||||
assert.isFalse(showStub.called);
|
||||
|
||||
element.set('_files', _files);
|
||||
flushAsynchronousOperations();
|
||||
// Navigates when a file is selected.
|
||||
element._openSelectedFile();
|
||||
assert.isTrue(showStub.called);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user