run manager: test for toolwindow activation suppression
authorSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 14 Aug 2015 12:39:54 +0000 (15:39 +0300)
committerSergey Simonchik <sergey.simonchik@jetbrains.com>
Fri, 14 Aug 2015 12:40:55 +0000 (15:40 +0300)
platform/lang-impl/testSources/com/intellij/execution/impl/ModuleRunConfigurationManagerTest.java

index d40f19f327ada15aad594dc41dba67b735572bb2..b8105d9fea41b29dc17d2aabf1413688b01c59d3 100644 (file)
 package com.intellij.execution.impl;
 
 import com.intellij.ProjectTopics;
-import com.intellij.execution.ExecutionException;
-import com.intellij.execution.Executor;
-import com.intellij.execution.RunnerAndConfigurationSettings;
+import com.intellij.execution.*;
+import com.intellij.execution.configuration.EmptyRunProfileState;
 import com.intellij.execution.configurations.*;
+import com.intellij.execution.executors.DefaultRunExecutor;
+import com.intellij.execution.process.ProcessHandler;
 import com.intellij.execution.runners.ExecutionEnvironment;
+import com.intellij.execution.runners.ExecutionEnvironmentBuilder;
+import com.intellij.execution.runners.GenericProgramRunner;
+import com.intellij.execution.runners.RunContentBuilder;
+import com.intellij.execution.ui.RunContentDescriptor;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.options.SettingsEditor;
 import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Disposer;
 import com.intellij.testFramework.LightPlatformTestCase;
 import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.messages.MessageBus;
@@ -36,6 +42,7 @@ import org.jmock.Expectations;
 import org.jmock.Mockery;
 
 import javax.swing.*;
+import java.io.OutputStream;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
@@ -114,6 +121,26 @@ public class ModuleRunConfigurationManagerTest extends LightPlatformTestCase {
     assertSameElements("one run config should be removed", myRemovedSettings, Collections.singleton(mySettings));
   }
 
+  public void testSuppressToolwindowActivation() throws Exception {
+    RunnerAndConfigurationSettings settings = new RunnerAndConfigurationSettingsImpl(
+      new MyRunManagerImpl(), new MyModuleBasedConfiguration("my-name", getProject(), getModule()), false
+    );
+    settings.setActivateToolWindowBeforeRun(true);
+    MockProgramRunner programRunner = new MockProgramRunner();
+    ExecutionEnvironment env = new ExecutionEnvironmentBuilder(getProject(), DefaultRunExecutor.getRunExecutorInstance())
+      .runnerAndSettings(programRunner, settings)
+      .build();
+    RunContentDescriptor descriptorToReuse = new RunContentDescriptor(null, null, new JPanel(), "name");
+    descriptorToReuse.setActivateToolWindowWhenAdded(false);
+    descriptorToReuse.setReuseToolWindowActivation(true);
+    env.setContentToReuse(descriptorToReuse);
+    env.getRunner().execute(env);
+    RunContentDescriptor lastDescriptor = programRunner.getLastDescriptor();
+    assertNotNull(lastDescriptor);
+    assertFalse(lastDescriptor.isActivateToolWindowWhenAdded());
+    Disposer.dispose(descriptorToReuse);
+  }
+
   private static final class MyRunConfigurationModule extends RunConfigurationModule {
     private final Module myModule;
     public MyRunConfigurationModule(@NotNull final Project project, @NotNull final Module module) {
@@ -170,7 +197,7 @@ public class ModuleRunConfigurationManagerTest extends LightPlatformTestCase {
     @Nullable
     @Override
     public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
-      return null;
+      return EmptyRunProfileState.INSTANCE;
     }
   }
 
@@ -213,4 +240,52 @@ public class ModuleRunConfigurationManagerTest extends LightPlatformTestCase {
       return new ConfigurationFactory[0];
     }
   }
+
+  private static class MockProgramRunner extends GenericProgramRunner {
+    private RunContentDescriptor myLastDescriptor;
+
+    @NotNull
+    @Override
+    public String getRunnerId() {
+      return "MockProgramRunner";
+    }
+
+    @Override
+    protected RunContentDescriptor doExecute(@NotNull RunProfileState state, @NotNull ExecutionEnvironment env) throws ExecutionException {
+      ExecutionResult executionResult = new DefaultExecutionResult(null, new NopProcessHandler());
+      myLastDescriptor = new RunContentBuilder(executionResult, env).showRunContent(env.getContentToReuse());
+      return myLastDescriptor;
+    }
+
+    @Override
+    public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
+      return true;
+    }
+
+    public RunContentDescriptor getLastDescriptor() {
+      return myLastDescriptor;
+    }
+  }
+
+  public static class NopProcessHandler extends ProcessHandler {
+    @Override
+    protected void destroyProcessImpl() {
+      notifyProcessTerminated(0);
+    }
+
+    @Override
+    protected void detachProcessImpl() {
+    }
+
+    @Override
+    public boolean detachIsDefault() {
+      return false;
+    }
+
+    @Nullable
+    @Override
+    public OutputStream getProcessInput() {
+      return null;
+    }
+  }
 }