refactor test code
- segregate unit and e2e test utils - add UnitTestUtils::getParser() Test: cd development/tools/winscope-ng && npm run build:all && npm run test:all Change-Id: I48212fe9bb1ef01b09301cd8a721f10ea18c9b77
This commit is contained in:
@@ -17,16 +17,13 @@ import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {Parser} from "./parser";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
|
||||
describe("ParserAccessibility", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const trace = TestUtils.getFixtureBlob("trace_Accessibility.pb");
|
||||
const parsers = await new ParserFactory().createParsers([trace]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
parser = await UnitTestUtils.getParser("traces/Accessibility.pb");
|
||||
});
|
||||
|
||||
it("has expected trace type", () => {
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {Parser} from "./parser";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
|
||||
describe("Parser", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("trace_WindowManager.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("trace_WindowManager.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -17,13 +17,13 @@ import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {Parser} from "./parser";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
|
||||
describe("ParserInputMethodlClients", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("trace_InputMethodClients.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("trace_InputMethodClients.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -17,13 +17,13 @@ import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {Parser} from "./parser";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
|
||||
describe("ParserInputMethodManagerService", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("trace_InputMethodManagerService.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("trace_InputMethodManagerService.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -17,13 +17,13 @@ import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {Parser} from "./parser";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
|
||||
describe("ParserInputMethodService", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("trace_InputMethodService.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("trace_InputMethodService.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -17,7 +17,7 @@ import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {Parser} from "./parser";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
import {LogMessage} from "../common/trace/protolog";
|
||||
|
||||
describe("ParserProtoLog", () => {
|
||||
@@ -33,7 +33,7 @@ describe("ParserProtoLog", () => {
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("trace_ProtoLog.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("trace_ProtoLog.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import {ScreenRecordingTraceEntry} from "common/trace/screen_recording";
|
||||
import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
import {Parser} from "./parser";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("ParserScreenRecording", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const trace = TestUtils.getFixtureBlob("screen_recording.mp4");
|
||||
const trace = UnitTestUtils.getFixtureBlob("screen_recording.mp4");
|
||||
const parsers = await new ParserFactory().createParsers([trace]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import {ScreenRecordingTraceEntry} from "common/trace/screen_recording";
|
||||
import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
import {Parser} from "./parser";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("ParserScreenRecordingLegacy", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const trace = TestUtils.getFixtureBlob("screen_recording_legacy.mp4");
|
||||
const trace = UnitTestUtils.getFixtureBlob("screen_recording_legacy.mp4");
|
||||
const parsers = await new ParserFactory().createParsers([trace]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {LayerTraceEntry} from "common/trace/flickerlib/layers/LayerTraceEntry";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
import {Parser} from "./parser";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("ParserSurfaceFlinger", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("trace_SurfaceFlinger.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("trace_SurfaceFlinger.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {LayerTraceEntry} from "common/trace/flickerlib/layers/LayerTraceEntry";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
import {Parser} from "./parser";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
|
||||
@@ -24,7 +24,7 @@ describe("ParserSurfaceFlingerDump", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("dump_SurfaceFlinger.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("dump_SurfaceFlinger.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -17,13 +17,13 @@ import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {Parser} from "./parser";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
|
||||
describe("ParserTransactions", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("trace_Transactions.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("trace_Transactions.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -18,13 +18,13 @@ import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {Parser} from "./parser";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
|
||||
describe("ParserWindowManager", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("trace_WindowManager.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("trace_WindowManager.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -18,13 +18,13 @@ import {Timestamp, TimestampType} from "common/trace/timestamp";
|
||||
import {TraceType} from "common/trace/trace_type";
|
||||
import {ParserFactory} from "./parser_factory";
|
||||
import {Parser} from "./parser";
|
||||
import {TestUtils} from "test/test_utils";
|
||||
import {UnitTestUtils} from "test/unit/utils";
|
||||
|
||||
describe("ParserWindowManagerDump", () => {
|
||||
let parser: Parser;
|
||||
|
||||
beforeAll(async () => {
|
||||
const buffer = TestUtils.getFixtureBlob("dump_WindowManager.pb");
|
||||
const buffer = UnitTestUtils.getFixtureBlob("dump_WindowManager.pb");
|
||||
const parsers = await new ParserFactory().createParsers([buffer]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
parser = parsers[0];
|
||||
|
||||
@@ -17,27 +17,27 @@ import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
import {Blob} from "./blob";
|
||||
|
||||
class TestUtils {
|
||||
class CommonTestUtils {
|
||||
static getFixtureBlob(filename: string): Blob {
|
||||
const buffer = TestUtils.loadFixture(filename);
|
||||
const buffer = CommonTestUtils.loadFixture(filename);
|
||||
return new Blob(buffer);
|
||||
}
|
||||
|
||||
static loadFixture(filename: string): ArrayBuffer {
|
||||
return fs.readFileSync(TestUtils.getFixturePath(filename));
|
||||
return fs.readFileSync(CommonTestUtils.getFixturePath(filename));
|
||||
}
|
||||
|
||||
static getFixturePath(filename: string): string {
|
||||
return path.join(TestUtils.getProjectRootPath(), "src/test/fixtures", filename);
|
||||
}
|
||||
|
||||
static getProductionIndexHtmlPath(): string {
|
||||
return path.join(TestUtils.getProjectRootPath(), "dist/prod/index.html");
|
||||
return path.join(CommonTestUtils.getProjectRootPath(), "src/test/fixtures", filename);
|
||||
}
|
||||
|
||||
static getProjectRootPath(): string {
|
||||
return path.join(__dirname, "../..");
|
||||
let root = __dirname;
|
||||
while (path.basename(root) !== "winscope-ng") {
|
||||
root = path.dirname(root);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
}
|
||||
|
||||
export {TestUtils};
|
||||
export {CommonTestUtils};
|
||||
25
tools/winscope-ng/src/test/e2e/utils.ts
Normal file
25
tools/winscope-ng/src/test/e2e/utils.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import * as path from "path";
|
||||
import {CommonTestUtils} from "../common/utils";
|
||||
|
||||
class E2eTestUtils extends CommonTestUtils {
|
||||
static getProductionIndexHtmlPath(): string {
|
||||
return path.join(CommonTestUtils.getProjectRootPath(), "dist/prod/index.html");
|
||||
}
|
||||
}
|
||||
|
||||
export {E2eTestUtils};
|
||||
@@ -14,17 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {browser, element, by} from "protractor";
|
||||
import {TestUtils} from "../test_utils";
|
||||
import {E2eTestUtils} from "./utils";
|
||||
|
||||
describe("Viewer WindowManager", () => {
|
||||
beforeAll(async () => {
|
||||
browser.manage().timeouts().implicitlyWait(1000);
|
||||
browser.get("file://" + TestUtils.getProductionIndexHtmlPath());
|
||||
browser.get("file://" + E2eTestUtils.getProductionIndexHtmlPath());
|
||||
}),
|
||||
|
||||
it("processes trace and renders view", () => {
|
||||
const inputFile = element(by.css("input[type=\"file\"]"));
|
||||
inputFile.sendKeys(TestUtils.getFixturePath("trace_WindowManager.pb"));
|
||||
inputFile.sendKeys(E2eTestUtils.getFixturePath("trace_WindowManager.pb"));
|
||||
|
||||
const windowManagerViewerTitle = element(by.css(".viewer-window-manager .title"));
|
||||
expect(windowManagerViewerTitle.getText()).toContain("Window Manager");
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import {browser, element, by} from "protractor";
|
||||
import {TestUtils} from "../test_utils";
|
||||
import {E2eTestUtils} from "./utils";
|
||||
|
||||
describe("winscope", () => {
|
||||
beforeAll(() => {
|
||||
browser.get("file://" + TestUtils.getProductionIndexHtmlPath());
|
||||
browser.get("file://" + E2eTestUtils.getProductionIndexHtmlPath());
|
||||
}),
|
||||
|
||||
it("has title", () => {
|
||||
|
||||
29
tools/winscope-ng/src/test/unit/utils.ts
Normal file
29
tools/winscope-ng/src/test/unit/utils.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
import {Parser} from "parsers/parser";
|
||||
import {ParserFactory} from "parsers/parser_factory";
|
||||
import {CommonTestUtils} from "test/common/utils";
|
||||
|
||||
class UnitTestUtils extends CommonTestUtils {
|
||||
static async getParser(filename: string): Promise<Parser> {
|
||||
const trace = CommonTestUtils.getFixtureBlob(filename);
|
||||
const parsers = await new ParserFactory().createParsers([trace]);
|
||||
expect(parsers.length).toEqual(1);
|
||||
return parsers[0];
|
||||
}
|
||||
}
|
||||
|
||||
export {UnitTestUtils};
|
||||
Reference in New Issue
Block a user