diff --git a/tools/winscope/src/test/common/file.ts b/tools/winscope/src/test/common/file.ts deleted file mode 100644 index e7de1af6e..000000000 --- a/tools/winscope/src/test/common/file.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// This class is needed for testing because Node.js doesn't provide the Web API's File type -import {Blob} from './blob'; - -class File extends Blob { - constructor(buffer: ArrayBuffer, fileName: string) { - super(buffer); - this.name = fileName; - } - - readonly lastModified: number = 0; - readonly name: string; - readonly webkitRelativePath: string = ''; -} - -export {File}; diff --git a/tools/winscope/src/test/common/blob.ts b/tools/winscope/src/test/common/file_impl.ts similarity index 72% rename from tools/winscope/src/test/common/blob.ts rename to tools/winscope/src/test/common/file_impl.ts index d0205f97e..8ad842bcf 100644 --- a/tools/winscope/src/test/common/blob.ts +++ b/tools/winscope/src/test/common/file_impl.ts @@ -14,16 +14,25 @@ * limitations under the License. */ -// This class is needed for testing because Node.js doesn't provide the Web API's Blob type -class Blob { - constructor(buffer: ArrayBuffer) { - this.size = buffer.byteLength; - this.type = 'application/octet-stream'; +// This class is needed for unit tests because Node.js doesn't provide +// an implementation of the Web API's File type +class FileImpl { + readonly size: number; + readonly type: string; + readonly name: string; + readonly lastModified: number = 0; + readonly webkitRelativePath: string = ''; + private readonly buffer: ArrayBuffer; + + constructor(buffer: ArrayBuffer, fileName: string) { this.buffer = buffer; + this.size = this.buffer.byteLength; + this.type = 'application/octet-stream'; + this.name = fileName; } arrayBuffer(): Promise { - return new Promise((resolve, reject) => { + return new Promise((resolve) => { resolve(this.buffer); }); } @@ -39,10 +48,6 @@ class Blob { text(): Promise { throw new Error('Not implemented!'); } - - readonly size: number; - readonly type: string; - private readonly buffer: ArrayBuffer; } -export {Blob}; +export {FileImpl}; diff --git a/tools/winscope/src/test/common/utils.ts b/tools/winscope/src/test/common/utils.ts index c8cba176e..d7f1e8853 100644 --- a/tools/winscope/src/test/common/utils.ts +++ b/tools/winscope/src/test/common/utils.ts @@ -15,14 +15,12 @@ */ import * as fs from 'fs'; import * as path from 'path'; -import {Blob} from './blob'; -import {File} from './file'; +import {FileImpl} from './file_impl'; class CommonTestUtils { static async getFixtureFile(filename: string): Promise { const buffer = CommonTestUtils.loadFixture(filename); - const blob = new Blob(buffer); - return new File(await blob.arrayBuffer(), filename); + return new FileImpl(buffer, filename) as unknown as File; } static loadFixture(filename: string): ArrayBuffer {