1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package ohos.devtools.views.distributed; 17 18 import com.intellij.openapi.wm.IdeGlassPane; 19 import com.intellij.openapi.wm.impl.IdeGlassPaneImpl; 20 import ohos.devtools.Config; 21 import ohos.devtools.views.distributed.bean.DistributedParams; 22 import org.assertj.swing.fixture.FrameFixture; 23 import org.junit.jupiter.api.AfterEach; 24 import org.junit.jupiter.api.BeforeEach; 25 import org.junit.jupiter.api.Test; 26 27 import javax.swing.JFrame; 28 import javax.swing.JPanel; 29 import java.awt.AWTException; 30 import java.awt.Dimension; 31 import java.awt.MouseInfo; 32 import java.awt.Point; 33 import java.awt.Robot; 34 import java.awt.event.InputEvent; 35 36 class DistributedDataStatisticsPaneTest { 37 private FrameFixture frame; 38 private DistributedDataStatisticsPane panel; 39 private JFrame jFrame; 40 private Robot robot; 41 42 @BeforeEach setUp()43 void setUp() { 44 jFrame = new JFrame(); 45 try { 46 robot = new Robot(); 47 IdeGlassPane ideGlassPane = new IdeGlassPaneImpl(jFrame.getRootPane()); 48 jFrame.getRootPane().setGlassPane((JPanel) ideGlassPane); 49 } catch (AWTException e) { 50 e.printStackTrace(); 51 } 52 DistributedPanel distributedPanel = new DistributedPanel(); 53 distributedPanel.load(new DistributedParams.Builder() 54 .setPkgNameA("com.test.maps") 55 .setPkgNameB("com.distributed.ims") 56 .setDeviceNameA("distributed device 1") 57 .setDeviceNameB("distributed device 2") 58 .setProcessIdA(27521) 59 .setProcessIdB(1155) 60 .setPathA(Config.TRACE_DISTRIBUTED_A) 61 .setPathB(Config.TRACE_DISTRIBUTED_B) 62 .setOffsetA(186485719530000L) 63 .setOffsetB(186590530788000L) 64 .build()); 65 distributedPanel.updateUI(); 66 panel = new DistributedDataStatisticsPane(); 67 jFrame.add(panel); 68 frame = new FrameFixture(jFrame); 69 frame.show(new Dimension(1024, 600)); 70 frame.moveTo(new Point(0, 0)); 71 } 72 73 @AfterEach tearDown()74 void tearDown() { 75 frame.cleanUp(); 76 } 77 78 @Test load()79 void load() { 80 delay(); 81 mouseClick(390, 68); 82 83 mouseClick(312, 64); 84 mouseClick(290, 87); 85 mouseClick(390, 68); 86 87 mouseClick(312, 64); 88 mouseClick(290, 106); 89 mouseClick(390, 68); 90 91 mouseClick(312, 64); 92 mouseClick(290, 123); 93 mouseClick(390, 68); 94 95 mouseClick(312, 64); 96 mouseClick(290, 140); 97 mouseClick(390, 68); 98 99 mouseClick(312, 64); 100 mouseClick(290, 158); 101 mouseClick(390, 68); 102 delay(); 103 } 104 mouseClick(int level, int vertical)105 private void mouseClick(int level, int vertical) { 106 robot.delay(2000); 107 robot.mouseMove(level, vertical); 108 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); 109 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); 110 } 111 keyClick(int keyEvent)112 private void keyClick(int keyEvent) { 113 robot.delay(2000); 114 robot.keyPress(keyEvent); 115 robot.keyRelease(keyEvent); 116 } 117 select(int x1, int y1, int x2, int y2)118 private void select(int x1, int y1, int x2, int y2) { 119 robot.delay(2000); 120 robot.mouseMove(x1, y1); 121 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); 122 robot.mouseMove(x2, y2); 123 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); 124 } 125 wheel(int wheelAmt)126 private void wheel(int wheelAmt) { 127 robot.delay(1000); 128 robot.mouseWheel(wheelAmt); 129 } 130 delay()131 private void delay() { 132 robot.delay(2000); 133 } 134 inspect()135 private void inspect() { 136 while (true) { 137 Point location = MouseInfo.getPointerInfo().getLocation(); 138 robot.delay(1000); 139 } 140 } 141 } 142