1/* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17import {assertDefined} from 'common/assert_utils'; 18import {TimestampConverter} from 'common/timestamp_converter'; 19import {TimestampConverterUtils} from 'test/unit/timestamp_converter_utils'; 20import {UnitTestUtils} from 'test/unit/utils'; 21import {CoarseVersion} from 'trace/coarse_version'; 22import {MediaBasedTraceEntry} from 'trace/media_based_trace_entry'; 23import {TraceFile} from 'trace/trace_file'; 24import {TraceType} from 'trace/trace_type'; 25import {ParserScreenshot} from './parser_screenshot'; 26 27describe('ParserScreenshot', () => { 28 let parser: ParserScreenshot; 29 let file: File; 30 31 beforeAll(async () => { 32 jasmine.addCustomEqualityTester(UnitTestUtils.timestampEqualityTester); 33 file = await UnitTestUtils.getFixtureFile('traces/screenshot.png'); 34 parser = new ParserScreenshot( 35 new TraceFile(file), 36 new TimestampConverter(TimestampConverterUtils.UTC_TIMEZONE_INFO, 0n), 37 ); 38 await parser.parse(); 39 parser.createTimestamps(); 40 }); 41 42 it('has expected trace type', () => { 43 expect(parser.getTraceType()).toEqual(TraceType.SCREENSHOT); 44 }); 45 46 it('has expected coarse version', () => { 47 expect(parser.getCoarseVersion()).toEqual(CoarseVersion.LATEST); 48 }); 49 50 it('provides timestamps', () => { 51 const timestamps = assertDefined(parser.getTimestamps()); 52 53 const expected = TimestampConverterUtils.makeElapsedTimestamp(0n); 54 timestamps.forEach((timestamp) => expect(timestamp).toEqual(expected)); 55 }); 56 57 it('does not apply timezone info', async () => { 58 const parserWithTimezoneInfo = new ParserScreenshot( 59 new TraceFile(file), 60 TimestampConverterUtils.TIMESTAMP_CONVERTER_WITH_UTC_OFFSET, 61 ); 62 await parserWithTimezoneInfo.parse(); 63 64 const expectedReal = TimestampConverterUtils.makeElapsedTimestamp(0n); 65 assertDefined(parser.getTimestamps()).forEach((timestamp) => 66 expect(timestamp).toEqual(expectedReal), 67 ); 68 }); 69 70 it('retrieves entry', async () => { 71 const entry = await parser.getEntry(0); 72 expect(entry).toBeInstanceOf(MediaBasedTraceEntry); 73 expect(entry.isImage).toBeTrue(); 74 }); 75}); 76