1/*
2 * Copyright (C) 2022 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 {browser, by, element} from 'protractor';
18import {E2eTestUtils} from './utils';
19
20describe('Upload traces', () => {
21  const DEFAULT_TIMEOUT_MS = 20000;
22
23  beforeAll(async () => {
24    jasmine.DEFAULT_TIMEOUT_INTERVAL = DEFAULT_TIMEOUT_MS;
25    await browser.manage().timeouts().implicitlyWait(DEFAULT_TIMEOUT_MS);
26    await E2eTestUtils.checkServerIsUp('Winscope', E2eTestUtils.WINSCOPE_URL);
27  });
28
29  beforeEach(async () => {
30    await browser.get(E2eTestUtils.WINSCOPE_URL);
31  });
32
33  it('can clear all files', async () => {
34    await E2eTestUtils.loadBugReport(DEFAULT_TIMEOUT_MS);
35    await E2eTestUtils.clickClearAllButton();
36    await checkNoFilesUploaded();
37  });
38
39  it('can remove a file using the close icon', async () => {
40    await E2eTestUtils.loadBugReport(DEFAULT_TIMEOUT_MS);
41    await E2eTestUtils.clickCloseIcon();
42    await checkFileRemoved();
43  });
44
45  it('can replace an uploaded file with a new file', async () => {
46    await E2eTestUtils.loadBugReport(DEFAULT_TIMEOUT_MS);
47    await E2eTestUtils.uploadFixture(
48      'traces/perfetto/layers_trace.perfetto-trace',
49    );
50    await checkFileReplaced();
51  });
52
53  it('can process bugreport', async () => {
54    await E2eTestUtils.loadBugReport(DEFAULT_TIMEOUT_MS);
55    await E2eTestUtils.clickViewTracesButton();
56    await checkRendersSurfaceFlingerView();
57  });
58
59  async function checkRendersSurfaceFlingerView() {
60    const viewerPresent = await element(
61      by.css('viewer-surface-flinger'),
62    ).isPresent();
63    expect(viewerPresent).toBeTruthy();
64  }
65
66  it("doesn't emit messages for valid trace file", async () => {
67    await E2eTestUtils.uploadFixture(
68      'traces/elapsed_and_real_timestamp/SurfaceFlinger.pb',
69    );
70    expect(
71      await E2eTestUtils.areMessagesEmitted(DEFAULT_TIMEOUT_MS),
72    ).toBeFalsy();
73  });
74
75  async function checkNoFilesUploaded() {
76    // default timeout to understand whether the messages where emitted or not.
77    await browser.manage().timeouts().implicitlyWait(1000);
78    const filesUploaded = await element(by.css('.uploaded-files')).isPresent();
79    await browser.manage().timeouts().implicitlyWait(DEFAULT_TIMEOUT_MS);
80    expect(filesUploaded).toBeFalsy();
81  }
82
83  async function checkFileRemoved() {
84    const text = await element(by.css('.uploaded-files')).getText();
85    expect(text).toContain('Window Manager');
86    expect(text).not.toContain('Surface Flinger');
87    expect(text).toContain('Transactions');
88    expect(text).toContain('Transitions');
89  }
90
91  async function checkFileReplaced() {
92    const text = await element(by.css('.uploaded-files')).getText();
93    expect(text).toContain('Surface Flinger');
94
95    expect(text).not.toContain('layers_trace_from_transactions.winscope');
96    expect(text).toContain('layers_trace.perfetto-trace');
97  }
98});
99