summaryrefslogtreecommitdiff
path: root/device-manager/testSrc/com/android/tools/idea/devicemanager/physicaltab/PhysicalDeviceDetailsPanelTest.java
blob: 4a849e773e5f87306b3a982b7a043000f13dec34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright (C) 2021 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.
 */
package com.android.tools.idea.devicemanager.physicaltab;

import static org.junit.Assert.assertEquals;

import com.android.sdklib.AndroidVersion;
import com.android.tools.idea.devicemanager.CountDownLatchAssert;
import com.android.tools.idea.devicemanager.CountDownLatchFutureCallback;
import com.android.tools.idea.devicemanager.DetailsPanel;
import com.android.tools.idea.devicemanager.Resolution;
import com.android.tools.idea.devicemanager.SerialNumber;
import com.android.tools.idea.devicemanager.physicaltab.PhysicalDeviceDetailsPanel.DeviceSection;
import com.android.tools.idea.devicemanager.physicaltab.PhysicalDeviceDetailsPanel.DeviceSectionCallback;
import com.android.tools.idea.devicemanager.physicaltab.PhysicalDeviceDetailsPanel.SummarySection;
import com.android.tools.idea.devicemanager.physicaltab.PhysicalDeviceDetailsPanel.SummarySectionCallback;
import com.android.tools.idea.wearpairing.WearPairingManager;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.awt.Container;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import javax.swing.JLabel;
import org.jetbrains.annotations.NotNull;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public final class PhysicalDeviceDetailsPanelTest {
  @Test
  public void summarySectionCallbackOnSuccess() throws InterruptedException {
    // Arrange
    PhysicalDevice device = new PhysicalDevice.Builder()
      .setKey(new SerialNumber("86UX00F4R"))
      .setName("Google Pixel 3")
      .setTarget("Android 12.0")
      .setAndroidVersion(new AndroidVersion(31))
      .setResolution(new Resolution(1080, 2160))
      .setDensity(440)
      .addAllAbis(Arrays.asList("arm64-v8a", "armeabi-v7a", "armeabi"))
      .build();

    ListenableFuture<PhysicalDevice> future = Futures.immediateFuture(device);
    CountDownLatch latch = new CountDownLatch(1);

    // Act
    PhysicalDeviceDetailsPanel panel = new PhysicalDeviceDetailsPanel(TestPhysicalDevices.ONLINE_GOOGLE_PIXEL_3,
                                                                      future,
                                                                      section -> newSummarySectionCallback(section, latch),
                                                                      DeviceSectionCallback::new,
                                                                      WearPairingManager.INSTANCE,
                                                                      false);

    // Assert
    CountDownLatchAssert.await(latch);

    SummarySection section = panel.getSummarySection();

    assertEquals("31", section.myApiLevelLabel.getText());
    assertEquals("1080 × 2160", section.myResolutionLabel.getText());
    assertEquals("393 × 786", section.myDpLabel.getText());
    assertEquals("arm64-v8a, armeabi-v7a, armeabi", section.myAbiListLabel.getText());
  }

  private static @NotNull FutureCallback<@NotNull PhysicalDevice> newSummarySectionCallback(@NotNull SummarySection section,
                                                                                            @NotNull CountDownLatch latch) {
    return new CountDownLatchFutureCallback<>(new SummarySectionCallback(section), latch);
  }

  @Ignore
  @Test
  public void deviceSectionCallbackOnSuccess() throws InterruptedException {
    // Arrange
    ListenableFuture<PhysicalDevice> future = Futures.immediateFuture(TestPhysicalDevices.GOOGLE_PIXEL_3);
    CountDownLatch latch = new CountDownLatch(1);

    // Act
    PhysicalDeviceDetailsPanel panel = new PhysicalDeviceDetailsPanel(TestPhysicalDevices.ONLINE_GOOGLE_PIXEL_3,
                                                                      future,
                                                                      SummarySectionCallback::new,
                                                                      section -> newDeviceSectionCallback(section, latch),
                                                                      WearPairingManager.INSTANCE,
                                                                      false);

    // Assert
    CountDownLatchAssert.await(latch);
    assertEquals("Google Pixel 3", panel.getDeviceSection().myNameLabel.getText());
  }

  private static @NotNull FutureCallback<@NotNull PhysicalDevice> newDeviceSectionCallback(@NotNull DeviceSection section,
                                                                                           @NotNull CountDownLatch latch) {
    return new CountDownLatchFutureCallback<>(new DeviceSectionCallback(section), latch);
  }

  @Test
  public void setInfoSectionPanelLayout() {
    // Act
    ListenableFuture<PhysicalDevice> future = Futures.immediateFuture(TestPhysicalDevices.GOOGLE_PIXEL_3);
    DetailsPanel detailsPanel = new PhysicalDeviceDetailsPanel(TestPhysicalDevices.GOOGLE_PIXEL_3, future, false);

    // Assert
    Container sectionPanel = detailsPanel.getInfoSectionPanel();

    assertEquals(1, sectionPanel.getComponentCount());
    assertEquals("Details unavailable for offline devices", ((JLabel)sectionPanel.getComponent(0)).getText());
  }
}