• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2025 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 {ConnectionState} from 'trace_collection/connection_state';
18import {ConnectionStateListener} from 'trace_collection/connection_state_listener';
19import {MockAdbHostConnection} from 'trace_collection/mock/mock_adb_host_connection';
20
21describe('AdbHostConnection', () => {
22  const listener = jasmine.createSpyObj<ConnectionStateListener>(
23    'ConnectionStateListener',
24    [
25      'onAvailableTracesChange',
26      'onDevicesChange',
27      'onError',
28      'onConnectionStateChange',
29    ],
30  );
31
32  let connection: MockAdbHostConnection;
33
34  beforeEach(() => {
35    connection = new MockAdbHostConnection(listener);
36    resetListener();
37  });
38
39  it('initializes extra parameters', () => {
40    const spy = spyOn(
41      MockAdbHostConnection.prototype,
42      'initializeExtraParameters',
43    );
44    connection = new MockAdbHostConnection(listener);
45    expect(spy).toHaveBeenCalledTimes(1);
46  });
47
48  it('calls listener on new state', async () => {
49    await connection.restart();
50    expect(listener.onConnectionStateChange.calls.allArgs()).toEqual([
51      [ConnectionState.CONNECTING],
52    ]);
53  });
54
55  it('destroys devices and host onDestroy', () => {
56    const hostSpy = spyOn(MockAdbHostConnection.prototype, 'destroyHost');
57    const deviceSpy = spyOn(connection.devices[0], 'onDestroy');
58    connection.onDestroy();
59    expect(hostSpy).toHaveBeenCalledTimes(1);
60    expect(deviceSpy).toHaveBeenCalledTimes(1);
61  });
62
63  function resetListener() {
64    listener.onAvailableTracesChange.calls.reset();
65    listener.onDevicesChange.calls.reset();
66    listener.onError.calls.reset();
67    listener.onConnectionStateChange.calls.reset();
68  }
69});
70