diff --git a/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt new file mode 100644 index 000000000000..5db741b8b614 --- /dev/null +++ b/community-guitests/testSrc/com/intellij/testGuiFramework/tests/community/focus/SearchEverywhereFocusTest.kt @@ -0,0 +1,81 @@ +// 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.focus + +import com.intellij.testGuiFramework.fixtures.IdeFrameFixture +import com.intellij.testGuiFramework.impl.GuiTestCase +import com.intellij.testGuiFramework.impl.GuiTestUtilKt +import com.intellij.testGuiFramework.tests.community.CommunityProjectCreator +import com.intellij.testGuiFramework.util.Key.ESCAPE +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.Window +import java.awt.event.InputEvent +import javax.swing.JLabel + +class SearchEverywhereFocusTest : GuiTestCase() { + + private val typedString = "here is a demo text" + private val expectedText = typedString + private val searchWindowLabelText = "Search Everywhere:" + + @Test + fun testGoToClassFocus() { + CommunityProjectCreator.createCommandLineProject() + Pause.pause(1000) + ideFrame { + focusOnEditor() + doubleShift(50) + fastType(typedString) + Pause.pause(500) + checkTextInSearchWindow(findSearchWindowTwice(), expectedText) + shortcut(ESCAPE) + focusOnEditor() + } + } + + + private fun GuiTestCase.doubleShift(delayBetweenMs: Int = 0) { + val smartRobot = robot() as SmartWaitRobot + smartRobot.fastPressAndReleaseModifiers(InputEvent.SHIFT_MASK) + if (delayBetweenMs > 0) Pause.pause(delayBetweenMs.toLong()) + smartRobot.fastPressAndReleaseModifiers(InputEvent.SHIFT_MASK) + } + + private fun IdeFrameFixture.focusOnEditor() { editor { moveTo(89) } } + + private fun GuiTestCase.fastType(stringToType: String) { + val smartRobot = this@fastType.robot() as SmartWaitRobot + smartRobot.fastTyping(stringToType) + } + + private fun GuiTestCase.checkTextInSearchWindow(searchWindow: Container, expectedText: String) { + with(this) { + val textfield = textfield("", searchWindow, this.defaultTimeout) + Assert.assertEquals(textfield.target().text, expectedText) + } + } + + private fun findSearchWindowTwice() : Container { + return try { + findSearchWindow(searchWindowLabelText) + } + catch (cle: ComponentLookupException) { + this.robot().waitForIdle() + findSearchWindow(searchWindowLabelText) + } + } + + private fun findSearchWindow(labelText: String): Container { + fun checkWindowContainsEnterClassName(it: Window) = GuiTestUtilKt.findAllWithBFS(it, + JLabel::class.java).firstOrNull { it.text?.contains(labelText) == true } != null + return Window.getWindows() + .filterNotNull() + .firstOrNull { checkWindowContainsEnterClassName(it) } ?: throw ComponentLookupException( + "Unable to find search window") + } + +} \ No newline at end of file diff --git a/platform/testGuiFramework/src/org/fest/swing/core/SmartWaitRobot.kt b/platform/testGuiFramework/src/org/fest/swing/core/SmartWaitRobot.kt index 1aeccae54016..dfea7d3a7c86 100644 --- a/platform/testGuiFramework/src/org/fest/swing/core/SmartWaitRobot.kt +++ b/platform/testGuiFramework/src/org/fest/swing/core/SmartWaitRobot.kt @@ -138,6 +138,13 @@ class SmartWaitRobot : BasicRobot(null, ExistingHierarchy()) { fastReleaseModifiers(updatedModifiers) } + fun fastPressAndReleaseModifiers(vararg modifiers: Int) { + val unifiedModifiers = InputModifiers.unify(*modifiers) + fastPressModifiers(unifiedModifiers) + Pause.pause(50) + fastReleaseModifiers(unifiedModifiers) + } + fun fastPressAndReleaseKeyWithoutModifiers(keyCode: Int) { fastPressKey(keyCode) fastReleaseKey(keyCode)