mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[gui-test] accelerate Robot to fix GoToClassFocusTest
This commit is contained in:
+14
-12
@@ -1,37 +1,37 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
/*
|
||||
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
*/
|
||||
package com.intellij.testGuiFramework.tests.community
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.wm.ex.WindowManagerEx
|
||||
import com.intellij.testGuiFramework.fixtures.IdeFrameFixture
|
||||
import com.intellij.testGuiFramework.framework.GuiTestUtil
|
||||
import com.intellij.testGuiFramework.impl.GuiTestCase
|
||||
import com.intellij.testGuiFramework.impl.GuiTestUtilKt
|
||||
import com.intellij.testGuiFramework.util.Key
|
||||
import org.fest.swing.core.SmartWaitRobot
|
||||
import org.fest.swing.exception.ComponentLookupException
|
||||
import org.fest.swing.timing.Pause
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import java.awt.Container
|
||||
import java.awt.KeyboardFocusManager
|
||||
import java.lang.Math.tan
|
||||
import java.util.*
|
||||
import javax.swing.JLabel
|
||||
|
||||
class GoToClassFocusTest: GuiTestCase() {
|
||||
|
||||
private val typedString = "Here is a string to check missing symbols"
|
||||
private val LOG = Logger.getInstance(this::class.java)
|
||||
private val typedString = "hefuihwefwehrf;werfwerfw"
|
||||
private val actionKeyStroke by lazy { ActionManager.getInstance().getKeyboardShortcut("GotoClass")!!.firstKeyStroke }
|
||||
|
||||
@Test
|
||||
fun testGoToClassFocus() {
|
||||
CommunityProjectCreator.createCommandLineProject()
|
||||
Pause.pause(1000)
|
||||
ideFrame {
|
||||
focusOnEditor()
|
||||
for(i in 0..10) {
|
||||
startIntensiveCalcOnParallel()
|
||||
openGoToClassSearchAndType(this@GoToClassFocusTest)
|
||||
focusOnEditor()
|
||||
}
|
||||
@@ -65,8 +65,10 @@ class GoToClassFocusTest: GuiTestCase() {
|
||||
}
|
||||
|
||||
private fun openGoToClassSearchAndType(guiTestCase: GuiTestCase) {
|
||||
invokeAction("GotoClass")
|
||||
GuiTestUtil.typeText(typedString, guiTestRule.robot(),0)
|
||||
|
||||
val smartRobot = guiTestCase.robot() as SmartWaitRobot
|
||||
smartRobot.shortcutAndTypeString(actionKeyStroke, typedString, 100)
|
||||
Pause.pause(500)
|
||||
checkSearchWindow(guiTestCase)
|
||||
shortcut(Key.ESCAPE)
|
||||
}
|
||||
@@ -80,7 +82,7 @@ class GoToClassFocusTest: GuiTestCase() {
|
||||
}
|
||||
|
||||
private fun findSearchWindow(guiTestCase: GuiTestCase): Container {
|
||||
val windowContainer = WindowManagerEx.getInstanceEx().mostRecentFocusedWindow // it should be a window container for go to class ideally
|
||||
val windowContainer = KeyboardFocusManager.getCurrentKeyboardFocusManager().focusedWindow // it should be a window container for go to class ideally
|
||||
GuiTestUtilKt.findAllWithBFS(windowContainer, JLabel::class.java).firstOrNull { it.text == "Enter class name:" } ?: throw ComponentLookupException("Unable to find GoToClass search window")
|
||||
return windowContainer
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ import org.fest.swing.awt.AWT
|
||||
import org.fest.swing.edt.GuiActionRunner
|
||||
import org.fest.swing.edt.GuiTask
|
||||
import org.fest.swing.hierarchy.ExistingHierarchy
|
||||
import org.fest.swing.keystroke.KeyStrokeMap
|
||||
import org.fest.swing.timing.Pause
|
||||
import org.fest.swing.util.Modifiers
|
||||
import org.fest.util.Preconditions
|
||||
import java.awt.Component
|
||||
import java.awt.MouseInfo
|
||||
@@ -28,6 +30,7 @@ import java.awt.Point
|
||||
import java.awt.Window
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.swing.KeyStroke
|
||||
import javax.swing.SwingUtilities
|
||||
|
||||
/**
|
||||
@@ -41,6 +44,7 @@ class SmartWaitRobot() : BasicRobot(null, ExistingHierarchy()) {
|
||||
|
||||
val waitConst = 30L
|
||||
var myAwareClick: Boolean = false
|
||||
val fastRobot: java.awt.Robot = java.awt.Robot()
|
||||
|
||||
fun superWaitForIdle() {
|
||||
super.waitForIdle()
|
||||
@@ -136,6 +140,65 @@ class SmartWaitRobot() : BasicRobot(null, ExistingHierarchy()) {
|
||||
}
|
||||
}
|
||||
|
||||
fun fastPressAndReleaseKey(keyCode: Int, vararg modifiers: Int) {
|
||||
val unifiedModifiers = InputModifiers.unify(*modifiers)
|
||||
val updatedModifiers = Modifiers.updateModifierWithKeyCode(keyCode, unifiedModifiers)
|
||||
fastPressModifiers(updatedModifiers)
|
||||
if (updatedModifiers == unifiedModifiers) {
|
||||
fastPressKey(keyCode)
|
||||
fastReleaseKey(keyCode)
|
||||
}
|
||||
fastReleaseModifiers(updatedModifiers)
|
||||
}
|
||||
|
||||
fun fastPressAndReleaseKeyWithoutModifiers(keyCode: Int) {
|
||||
fastPressKey(keyCode)
|
||||
fastReleaseKey(keyCode)
|
||||
}
|
||||
|
||||
fun fastType(character: Char) {
|
||||
val keyStroke = KeyStrokeMap.keyStrokeFor(character) ?: throw Exception("Unable to get keystroke for char '$character'")
|
||||
fastPressAndReleaseKey(keyStroke.keyCode)
|
||||
}
|
||||
|
||||
fun preparedFastTypeWithoutModifiers(string: String) {
|
||||
val keyCodeArray = string
|
||||
.map { KeyStrokeMap.keyStrokeFor(it)?.keyCode ?: throw Exception("Unable to get keystroke for char '$it'") }
|
||||
.toIntArray()
|
||||
keyCodeArray.forEach { fastPressAndReleaseKeyWithoutModifiers(keyCode = it) }
|
||||
}
|
||||
|
||||
fun shortcutAndTypeString(keyStoke: KeyStroke, string: String, delayBetweenShortcutAndTypingMs: Int = 0) {
|
||||
val keyCodeArray = string
|
||||
.map { KeyStrokeMap.keyStrokeFor(it)?.keyCode ?: throw Exception("Unable to get keystroke for char '$it'") }
|
||||
.toIntArray()
|
||||
fastPressAndReleaseKey(keyStoke.keyCode, keyStoke.modifiers)
|
||||
if (delayBetweenShortcutAndTypingMs > 0) Pause.pause(delayBetweenShortcutAndTypingMs.toLong())
|
||||
keyCodeArray.forEach { fastPressAndReleaseKeyWithoutModifiers(keyCode = it); Pause.pause(10) }
|
||||
}
|
||||
|
||||
private fun fastPressKey(keyCode: Int) {
|
||||
fastRobot.keyPress(keyCode);
|
||||
}
|
||||
|
||||
private fun fastReleaseKey(keyCode: Int) {
|
||||
fastRobot.keyRelease(keyCode);
|
||||
}
|
||||
|
||||
private fun fastPressModifiers(modifierMask: Int) {
|
||||
val keys = Modifiers.keysFor(modifierMask)
|
||||
val keysSize = keys.size
|
||||
(0 until keysSize)
|
||||
.map { keys[it] }
|
||||
.forEach { fastPressKey(it) }
|
||||
}
|
||||
|
||||
private fun fastReleaseModifiers(modifierMask: Int) {
|
||||
val modifierKeys = Modifiers.keysFor(modifierMask)
|
||||
for (i in modifierKeys.indices.reversed())
|
||||
fastReleaseKey(modifierKeys[i])
|
||||
}
|
||||
|
||||
private fun myEdtAwareClick(button: MouseButton, times: Int, point: Point, component: Component?) {
|
||||
awareClick {
|
||||
performOnEdt {
|
||||
|
||||
Reference in New Issue
Block a user