Skip to content

Commit

Permalink
Fix TestMetadataModel {@extends} class problems
Browse files Browse the repository at this point in the history
Per CL:1450538, this test's internal metadataModel helper class, which
uses @extends {MetedataData} to lie to Closure about its type (a fake)
becomes problematic for ES6 class conversion tools: lie detected.

There's no compelling need to for the helper to be a class: we can add
a factory method to supply {!MetadataModel} fakes as needed, similarly
to all other files app unittests.

No change in behavior, no new tests.

Bug: 778674
Change-Id: Id0c2194d649ff9fa32861359f5647a2a0d338b8b
Reviewed-on: https://chromium-review.googlesource.com/c/1465601
Reviewed-by: Noel Gordon <[email protected]>
Reviewed-by: Anand Mistry <[email protected]>
Commit-Queue: Noel Gordon <[email protected]>
Cr-Commit-Position: refs/heads/master@{#631105}
  • Loading branch information
Noel Gordon authored and Commit Bot committed Feb 12, 2019
1 parent e2a408e commit 97b1a5b
Showing 1 changed file with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var TEST_METADATA = {
const TEST_METADATA = {
'a.txt': {
contentMimeType: 'text/plain',
size: 1023,
Expand Down Expand Up @@ -33,44 +33,39 @@ function assertEntryArrayEquals(entryArray, names) {
}

function makeSimpleFileListModel(names) {
var fileListModel = new FileListModel(new TestMetadataModel({}));
var fileListModel = new FileListModel(createFakeMetadataModel({}));
for (var i = 0; i < names.length; i++) {
fileListModel.push({name: names[i], isDirectory: false});
}
return fileListModel;
}

/**
* MetadataModel for this test.
* It is supposed to provide metadata from TEST_METADATA to work with the
* FileListModel.
*
* @constructor
* @extends {MetadataModel}
* @param {Object} testdata
* Returns a fake MetadataModel, used to provide metadata from the given |data|
* object (usually TEST_METADATA) to the FileListModel.
* @param {!Object} data
* @return {!MetadataModel}
*/
function TestMetadataModel(testdata) {
this.testdata_ = testdata;
}

TestMetadataModel.prototype = {
getCache : function(entries, names) {
var result = [];
for (var i = 0; i < entries.length; i++) {
var metadata = {};
if (!entries[i].isDirectory && this.testdata_[entries[i].name]) {
for (var j = 0; j < names.length; j++) {
metadata[names[j]] = this.testdata_[entries[i].name][names[j]];
function createFakeMetadataModel(data) {
return /** @type {!MetadataModel} */ ({
getCache: (entries, names) => {
let result = [];
for (let i = 0; i < entries.length; i++) {
let metadata = {};
if (!entries[i].isDirectory && data[entries[i].name]) {
for (let j = 0; j < names.length; j++) {
metadata[names[j]] = data[entries[i].name][names[j]];
}
}
result.push(metadata);
}
result.push(metadata);
}
return result;
},
};
return result;
},
});
}

function testIsImageDominant() {
var fileListModel = new FileListModel(new TestMetadataModel(TEST_METADATA));
var fileListModel = new FileListModel(createFakeMetadataModel(TEST_METADATA));

assertEquals(fileListModel.isImageDominant(), false);

Expand All @@ -97,7 +92,7 @@ function testIsImageDominant() {
}

function testSortWithFolders() {
var fileListModel = new FileListModel(new TestMetadataModel(TEST_METADATA));
var fileListModel = new FileListModel(createFakeMetadataModel(TEST_METADATA));
fileListModel.push({ name: 'dirA', isDirectory: true });
fileListModel.push({ name: 'dirB', isDirectory: true });
fileListModel.push({ name: 'a.txt', isDirectory: false });
Expand Down

0 comments on commit 97b1a5b

Please sign in to comment.