Search in sources :

Example 1 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class GuiTestUtil method waitForIdeToStart.

// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
    GuiActionRunner.executeInEDT(false);
    Robot robot = null;
    try {
        robot = BasicRobot.robotWithCurrentAwtHierarchy();
        final MyProjectManagerListener listener = new MyProjectManagerListener();
        //[ACCEPT IntelliJ IDEA Privacy Policy Agreement]
        acceptAgreementIfNeeded(robot);
        findFrame(new GenericTypeMatcher<Frame>(Frame.class) {

            @Override
            protected boolean isMatching(@NotNull Frame frame) {
                if (frame instanceof IdeFrame) {
                    if (frame instanceof IdeFrameImpl) {
                        listener.myActive = true;
                        ProjectManager.getInstance().addProjectManagerListener(listener);
                    }
                    return true;
                }
                return false;
            }
        }).withTimeout(LONG_TIMEOUT.duration()).using(robot);
        if (listener.myActive) {
            Pause.pause(new Condition("Project to be opened") {

                @Override
                public boolean test() {
                    boolean notified = listener.myNotified;
                    if (notified) {
                        ProgressManager progressManager = ProgressManager.getInstance();
                        boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
                        if (isIdle) {
                            ProjectManager.getInstance().removeProjectManagerListener(listener);
                        }
                        return isIdle;
                    }
                    return false;
                }
            }, LONG_TIMEOUT);
        }
    } finally {
        GuiActionRunner.executeInEDT(true);
        if (robot != null) {
            robot.cleanUpWithoutDisposingWindows();
        }
    }
}
Also used : Condition(org.fest.swing.timing.Condition) IdeFrameImpl(com.intellij.openapi.wm.impl.IdeFrameImpl) IdeFrame(com.intellij.openapi.wm.IdeFrame) WindowFinder.findFrame(org.fest.swing.finder.WindowFinder.findFrame) ProgressManager(com.intellij.openapi.progress.ProgressManager) Robot(org.fest.swing.core.Robot) IdeFrame(com.intellij.openapi.wm.IdeFrame)

Example 2 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class NewProjectWizardFixture method selectSdkPath.

public NewProjectWizardFixture selectSdkPath(@NotNull File sdkPath, String sdkType) {
    final SelectSdkDialogFixture sdkDialogFixture = SelectSdkDialogFixture.find(robot(), sdkType);
    sdkDialogFixture.selectPathToSdk(sdkPath).clickOk();
    pause(new Condition("Waiting for the returning of focus to dialog: " + target().getTitle()) {

        @Override
        public boolean test() {
            return target().isFocused();
        }
    }, GuiTestUtil.SHORT_TIMEOUT);
    return this;
}
Also used : Condition(org.fest.swing.timing.Condition) SelectSdkDialogFixture(com.intellij.testGuiFramework.fixtures.SelectSdkDialogFixture)

Example 3 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class GuiTestBase method closeAllProjects.

@SuppressWarnings("UnusedDeclaration")
protected // Called by GuiTestRunner via reflection.
void closeAllProjects() {
    pause(new Condition("Close all projects") {

        @Override
        public boolean test() {
            final Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
            execute(new GuiTask() {

                @Override
                protected void executeInEDT() throws Throwable {
                    TransactionGuard.submitTransaction(ApplicationManager.getApplication(), () -> {
                        for (Project project : openProjects) {
                            assertTrue("Failed to close project " + quote(project.getName()), closeAndDispose(project));
                        }
                    });
                }
            });
            return ProjectManager.getInstance().getOpenProjects().length == 0;
        }
    }, SHORT_TIMEOUT);
    //noinspection ConstantConditions
    boolean welcomeFrameShown = execute(new GuiQuery<Boolean>() {

        @Override
        protected Boolean executeInEDT() throws Throwable {
            Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
            if (openProjects.length == 0) {
                WelcomeFrame.showNow();
                WindowManagerImpl windowManager = (WindowManagerImpl) WindowManager.getInstance();
                windowManager.disposeRootFrame();
                return true;
            }
            return false;
        }
    });
    if (welcomeFrameShown) {
        pause(new Condition("'Welcome' frame to show up") {

            @Override
            public boolean test() {
                for (Frame frame : Frame.getFrames()) {
                    if (frame == WelcomeFrame.getInstance() && frame.isShowing()) {
                        return true;
                    }
                }
                return false;
            }
        }, SHORT_TIMEOUT);
    }
}
Also used : Condition(org.fest.swing.timing.Condition) GuiTask(org.fest.swing.edt.GuiTask) Project(com.intellij.openapi.project.Project) WelcomeFrame(com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame) WindowManagerImpl(com.intellij.openapi.wm.impl.WindowManagerImpl)

Example 4 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class EditorFixture method waitUntilFileIsLoaded.

/**
   * An Editor could load files async, sometimes we should wait a bit when the virtual
   * file for a current editor will be set.
   *
   * @return FileFixture for loaded virtual file
   */
@NotNull
public FileFixture waitUntilFileIsLoaded() {
    Ref<VirtualFile> virtualFileReference = new Ref<>();
    pause(new Condition("Wait when virtual file is created...") {

        @Override
        public boolean test() {
            virtualFileReference.set(execute(new GuiQuery<VirtualFile>() {

                @Override
                protected VirtualFile executeInEDT() throws Throwable {
                    return getCurrentFile();
                }
            }));
            return virtualFileReference.get() != null;
        }
    }, THIRTY_SEC_TIMEOUT);
    return new FileFixture(myFrame.getProject(), virtualFileReference.get());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Condition(org.fest.swing.timing.Condition) Ref(com.intellij.openapi.util.Ref) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with Condition

use of org.fest.swing.timing.Condition in project intellij-community by JetBrains.

the class ActionLinkFixture method findByActionId.

@NotNull
public static ActionLinkFixture findByActionId(@NotNull final String actionId, @NotNull final Robot robot, @NotNull final Container container) {
    final Ref<ActionLink> actionLinkRef = new Ref<ActionLink>();
    pause(new Condition("Find ActionLink with ID '" + actionId + "'") {

        @Override
        public boolean test() {
            Collection<ActionLink> found = robot.finder().findAll(container, new GenericTypeMatcher<ActionLink>(ActionLink.class) {

                @Override
                protected boolean isMatching(@NotNull ActionLink actionLink) {
                    if (actionLink.isVisible()) {
                        AnAction action = actionLink.getAction();
                        String id = ActionManager.getInstance().getId(action);
                        return actionId.equals(id);
                    }
                    return false;
                }
            });
            if (found.size() == 1) {
                actionLinkRef.set(getFirstItem(found));
                return true;
            }
            return false;
        }
    }, SHORT_TIMEOUT);
    ActionLink actionLink = actionLinkRef.get();
    if (actionLink == null) {
        throw new ComponentLookupException("Failed to find ActionLink with ID '" + actionId + "'");
    }
    return new ActionLinkFixture(robot, actionLink);
}
Also used : Condition(org.fest.swing.timing.Condition) Ref(com.intellij.openapi.util.Ref) Collection(java.util.Collection) ComponentLookupException(org.fest.swing.exception.ComponentLookupException) GenericTypeMatcher(org.fest.swing.core.GenericTypeMatcher) NotNull(org.jetbrains.annotations.NotNull) AnAction(com.intellij.openapi.actionSystem.AnAction) ActionLink(com.intellij.ui.components.labels.ActionLink) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Condition (org.fest.swing.timing.Condition)36 NotNull (org.jetbrains.annotations.NotNull)17 Ref (com.intellij.openapi.util.Ref)9 GuiTask (org.fest.swing.edt.GuiTask)8 Collection (java.util.Collection)7 Assert.assertNotNull (junit.framework.Assert.assertNotNull)6 GenericTypeMatcher (org.fest.swing.core.GenericTypeMatcher)5 GuiQuery (org.fest.swing.edt.GuiQuery)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 ComponentLookupException (org.fest.swing.exception.ComponentLookupException)4 Nullable (org.jetbrains.annotations.Nullable)4 Project (com.intellij.openapi.project.Project)3 Content (com.intellij.ui.content.Content)3 ProjectView (com.intellij.ide.projectView.ProjectView)2 AnAction (com.intellij.openapi.actionSystem.AnAction)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 ProgressManager (com.intellij.openapi.progress.ProgressManager)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 IdeFrameImpl (com.intellij.openapi.wm.impl.IdeFrameImpl)2