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, ElementFinder} from 'protractor';
18import {E2eTestUtils} from './utils';
19
20describe('Viewer Protolog', () => {
21  const scrollSelectors = {
22    viewer: 'viewer-protolog',
23    scroll: '.scroll-messages',
24    entry: '.message',
25  };
26  const totalEntries = 7295;
27  const scrollToTotalBottomOffset = 700000;
28
29  beforeEach(async () => {
30    browser.manage().timeouts().implicitlyWait(1000);
31    await E2eTestUtils.checkServerIsUp('Winscope', E2eTestUtils.WINSCOPE_URL);
32    await browser.get(E2eTestUtils.WINSCOPE_URL);
33  });
34
35  it('processes trace from zip and navigates correctly', async () => {
36    await E2eTestUtils.loadTraceAndCheckViewer(
37      'traces/deployment_full_trace_phone.zip',
38      'ProtoLog',
39      scrollSelectors.viewer,
40    );
41    await E2eTestUtils.checkTotalScrollEntries(
42      scrollSelectors,
43      scrollViewport,
44      totalEntries,
45      scrollToTotalBottomOffset,
46    );
47    await E2eTestUtils.checkTimelineTraceSelector({
48      icon: 'notes',
49      color: 'rgba(64, 165, 138, 1)',
50    });
51    await E2eTestUtils.checkFinalRealTimestamp('2022-11-21, 18:05:18.259');
52    await E2eTestUtils.checkInitialRealTimestamp('2022-11-21, 18:05:09.777');
53
54    await checkSelectFilter(
55      '.source-file',
56      ['com/android/server/wm/ActivityStarter.java'],
57      1,
58    );
59    await checkSelectFilter(
60      '.source-file',
61      [
62        'com/android/server/wm/ActivityStarter.java',
63        'com/android/server/wm/ActivityClientController.java',
64      ],
65      4,
66    );
67
68    await E2eTestUtils.checkTotalScrollEntries(
69      scrollSelectors,
70      scrollViewport,
71      totalEntries,
72      scrollToTotalBottomOffset,
73    );
74    await filterByText('FREEZE');
75    await E2eTestUtils.checkTotalScrollEntries(
76      scrollSelectors,
77      scrollViewport,
78      4,
79    );
80  });
81
82  async function checkSelectFilter(
83    filterSelector: string,
84    options: string[],
85    expectedFilteredEntries: number,
86  ) {
87    await E2eTestUtils.toggleSelectFilterOptions(
88      scrollSelectors.viewer,
89      filterSelector,
90      options,
91    );
92    await E2eTestUtils.checkTotalScrollEntries(
93      scrollSelectors,
94      scrollViewport,
95      expectedFilteredEntries,
96    );
97
98    await E2eTestUtils.toggleSelectFilterOptions(
99      scrollSelectors.viewer,
100      filterSelector,
101      options,
102    );
103    await E2eTestUtils.checkTotalScrollEntries(
104      scrollSelectors,
105      scrollViewport,
106      totalEntries,
107      scrollToTotalBottomOffset,
108    );
109  }
110
111  async function filterByText(filterString: string) {
112    await E2eTestUtils.updateInputField(
113      `${scrollSelectors.viewer} .filters .text`,
114      'protologTextInput',
115      filterString,
116    );
117  }
118
119  function scrollViewport(
120    viewportEl: ElementFinder,
121    offset: number,
122    done: () => void,
123  ) {
124    viewportEl['scrollTop'] = offset;
125    window.requestAnimationFrame(() => done());
126  }
127});
128