-
Notifications
You must be signed in to change notification settings - Fork 222
Add DnD tests issue #3182 #3195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>features</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
</buildSpec> | ||
<natures> | ||
</natures> | ||
</projectDescription> | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21"> | ||
<attributes> | ||
<attribute name="module" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> | ||
<classpathentry kind="src" path="src"> | ||
<attributes> | ||
<attribute name="test" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.eclipse.ui.tests.dnd</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.ManifestBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.pde.SchemaBuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.pde.PluginNature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21 | ||
org.eclipse.jdt.core.compiler.compliance=21 | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | ||
org.eclipse.jdt.core.compiler.release=enabled | ||
org.eclipse.jdt.core.compiler.source=21 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Manifest-Version: 1.0 | ||
Bundle-ManifestVersion: 2 | ||
Bundle-Name: Dnd | ||
Bundle-SymbolicName: org.eclipse.ui.tests.dnd | ||
Bundle-Version: 1.0.0.qualifier | ||
Require-Bundle: org.eclipse.swt, | ||
org.eclipse.jface, | ||
org.junit;bundle-version="4.13.2", | ||
org.eclipse.ui;bundle-version="3.207.300", | ||
org.eclipse.ui.tests;bundle-version="3.15.2100", | ||
org.eclipse.ui.workbench.texteditor;bundle-version="3.19.300", | ||
org.eclipse.core.runtime;bundle-version="3.33.100", | ||
org.eclipse.core.resources;bundle-version="3.22.200", | ||
org.eclipse.ui.tests.harness;bundle-version="1.10.600", | ||
junit-jupiter-api;bundle-version="5.12.2", | ||
junit-platform-suite-api;bundle-version="1.12.2" | ||
Automatic-Module-Name: org.eclipse.ui.tests.dnd | ||
Bundle-RequiredExecutionEnvironment: JavaSE-21 | ||
Import-Package: org.eclipse.ui.part |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source.. = src/ | ||
output.. = bin/ | ||
bin.includes = META-INF/,\ | ||
. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2004, 2005 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
Comment on lines
+1
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you copied this from somewhere. |
||
package org.eclipse.ui.tests.dnd; | ||
|
||
import org.eclipse.swt.graphics.Point; | ||
import org.eclipse.swt.widgets.Shell; | ||
|
||
public class DetachedDropTarget implements TestDropLocation { | ||
|
||
@Override | ||
public String toString() { | ||
return "out of the window"; | ||
} | ||
|
||
@Override | ||
public Point getLocation() { | ||
return new Point(0,0); | ||
} | ||
|
||
@Override | ||
public Shell[] getShells() { | ||
return new Shell[0]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.eclipse.ui.tests.dnd; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Every java file needs a "standard" copyright header. |
||
|
||
import org.eclipse.ui.IViewPart; | ||
|
||
public class DetachedWindowDragTest extends DragTest { | ||
|
||
public DetachedWindowDragTest(TestDragSource dragSource, | ||
TestDropLocation dropTarget) { | ||
super(dragSource, dropTarget); | ||
} | ||
|
||
@Override | ||
public void doSetUp() throws Exception { | ||
super.doSetUp(); | ||
|
||
page.showView(DragDropPerspectiveFactory.dropViewId2); | ||
Check warning on line 16 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java
|
||
page.showView(DragDropPerspectiveFactory.dropViewId1); | ||
Check warning on line 17 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java
|
||
page.showView(DragDropPerspectiveFactory.dropViewId3); | ||
Check warning on line 18 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java
|
||
|
||
IViewPart viewPart = page.showView(DragDropPerspectiveFactory.dropViewId1); | ||
Check warning on line 20 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java
|
||
DragOperations.drag(viewPart, new DetachedDropTarget(), true); | ||
|
||
viewPart = page.showView(DragDropPerspectiveFactory.dropViewId3); | ||
Check warning on line 23 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DetachedWindowDragTest.java
|
||
DragOperations.drag(viewPart, new DetachedDropTarget(), false); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.eclipse.ui.tests.dnd; | ||
|
||
import org.eclipse.ui.IFolderLayout; | ||
import org.eclipse.ui.IPageLayout; | ||
import org.eclipse.ui.IPerspectiveFactory; | ||
import org.eclipse.ui.IPlaceholderFolderLayout; | ||
|
||
/** | ||
* @since 3.0 | ||
*/ | ||
public class DragDropPerspectiveFactory implements IPerspectiveFactory { | ||
|
||
// Id's needed by the 'Detached Window' Drag / Drop tests | ||
public static final String viewFolderId = "oorg.eclipse.ui.test.dnd.detached.MockFolder1"; | ||
|
||
public static final String dropViewId1 = "org.eclipse.ui.tests.api.MockViewPart"; | ||
public static final String dropViewId2 = "org.eclipse.ui.tests.api.MockViewPart2"; | ||
public static final String dropViewId3 = "org.eclipse.ui.tests.api.MockViewPart3"; | ||
|
||
@Override | ||
public void createInitialLayout(IPageLayout layout) { | ||
String folderId = "org.eclipse.ui.test.dnd.mystack"; | ||
|
||
IFolderLayout folder = layout.createFolder(folderId, | ||
IPageLayout.BOTTOM, 0.5f, IPageLayout.ID_EDITOR_AREA); | ||
folder.addView(IPageLayout.ID_OUTLINE); | ||
folder.addView(IPageLayout.ID_PROBLEM_VIEW); | ||
folder.addView(IPageLayout.ID_PROP_SHEET); | ||
|
||
layout.addView(IPageLayout.ID_PROBLEM_VIEW, IPageLayout.LEFT, 0.5f, | ||
IPageLayout.ID_EDITOR_AREA); | ||
|
||
// Extra stacks and views that will be shown and detached during the 'Detached Window' tests | ||
IPlaceholderFolderLayout folder2 = layout.createPlaceholderFolder(viewFolderId, | ||
IPageLayout.RIGHT, 0.5f, IPageLayout.ID_EDITOR_AREA); | ||
folder2.addPlaceholder(dropViewId1); | ||
folder2.addPlaceholder(dropViewId2); | ||
|
||
layout.addPlaceholder(dropViewId3, IPageLayout.BOTTOM, 0.5f, viewFolderId); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package org.eclipse.ui.tests.dnd; | ||
|
||
import org.eclipse.jface.util.Geometry; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.graphics.Point; | ||
import org.eclipse.swt.graphics.Rectangle; | ||
import org.eclipse.ui.IEditorPart; | ||
import org.eclipse.ui.IViewPart; | ||
import org.eclipse.ui.IWorkbenchPage; | ||
import org.eclipse.ui.IWorkbenchPart; | ||
import org.eclipse.ui.IWorkbenchPartReference; | ||
import org.junit.Assert; | ||
|
||
/** | ||
* @since 3.0 | ||
*/ | ||
public class DragOperations { | ||
|
||
/** | ||
* Drags the given view OR editor to the given location (i.e. it only cares that we're given | ||
* a 'Part' and doesn't care whether it's a 'View' or an 'Editor'. | ||
* <p> | ||
* This method should eventually replace the original one once the Workbench has been updated | ||
* to handle Views and Editors without distincton. | ||
*/ | ||
@SuppressWarnings("unused") | ||
Check warning on line 26 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragOperations.java
|
||
public static void drag(IWorkbenchPart part, TestDropLocation target, boolean wholeFolder) { | ||
// DragUtil.forceDropLocation(target); | ||
|
||
// PartSite site = (PartSite) part.getSite(); | ||
// PartPane pane = site.getPane(); | ||
// PartStack parent = ((PartStack) (pane.getContainer())); | ||
// | ||
// parent.paneDragStart(wholeFolder ? null : pane, Display.getDefault().getCursorLocation(), false); | ||
|
||
Assert.fail("DND needs some updating"); | ||
// DragUtil.forceDropLocation(null); | ||
} | ||
|
||
/** | ||
* Returns the name of the given editor | ||
*/ | ||
public static String getName(IEditorPart editor) { | ||
IWorkbenchPage page = editor.getSite().getPage(); | ||
IWorkbenchPartReference ref = page.getReference(editor); | ||
return ref.getPartName(); | ||
} | ||
|
||
public static Rectangle getDisplayBounds() { | ||
return new Rectangle(0, 0, 0, 0); | ||
} | ||
|
||
public static Point getLocation(int side) { | ||
return DragOperations.getPoint(getDisplayBounds(), side); | ||
} | ||
|
||
public static Point getPointInEditorArea() { | ||
return new Point(0, 0); | ||
} | ||
|
||
public static Point getPoint(Rectangle bounds, int side) { | ||
Point centerPoint = Geometry.centerPoint(bounds); | ||
|
||
switch (side) { | ||
case SWT.TOP: | ||
return new Point(centerPoint.x, bounds.y + 1); | ||
case SWT.BOTTOM: | ||
return new Point(centerPoint.x, bounds.y + bounds.height - 1); | ||
case SWT.LEFT: | ||
return new Point(bounds.x + 1, centerPoint.y); | ||
case SWT.RIGHT: | ||
return new Point(bounds.x + bounds.width - 1, centerPoint.y); | ||
} | ||
|
||
return centerPoint; | ||
} | ||
|
||
public static String nameForConstant(int swtSideConstant) { | ||
switch (swtSideConstant) { | ||
case SWT.TOP: | ||
return "top"; | ||
case SWT.BOTTOM: | ||
return "bottom"; | ||
case SWT.LEFT: | ||
return "left"; | ||
case SWT.RIGHT: | ||
return "right"; | ||
} | ||
|
||
return "center"; | ||
} | ||
|
||
public static String getName(IViewPart targetPart) { | ||
return targetPart.getTitle(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.eclipse.ui.tests.dnd; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.swt.SWT; | ||
import org.eclipse.swt.widgets.Display; | ||
import org.eclipse.swt.widgets.Shell; | ||
import org.eclipse.ui.IEditorPart; | ||
import org.eclipse.ui.PlatformUI; | ||
import org.eclipse.ui.internal.WorkbenchPage; | ||
import org.eclipse.ui.internal.WorkbenchWindow; | ||
import org.eclipse.ui.part.FileEditorInput; | ||
import org.eclipse.ui.tests.api.MockEditorPart; | ||
import org.eclipse.ui.tests.harness.util.FileUtil; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class DragTest { | ||
|
||
TestDragSource dragSource; | ||
TestDropLocation dropTarget; | ||
|
||
static IProject project; | ||
static IFile file1, file2, file3; | ||
|
||
IEditorPart editor1, editor2, editor3; | ||
|
||
static WorkbenchWindow window; | ||
Check warning on line 29 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be an IWorkbenchWindow? Should any of these things really be static? |
||
static WorkbenchPage page; | ||
Check warning on line 30 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be an IWorkbenchPage? |
||
|
||
public DragTest(TestDragSource dragSource, TestDropLocation dropTarget) { | ||
this.dragSource = dragSource; | ||
this.dropTarget = dropTarget; | ||
} | ||
|
||
@AfterEach | ||
public void doSetUp() throws Exception { | ||
if (window == null) { | ||
window = (WorkbenchWindow) PlatformUI.getWorkbench(); | ||
Check warning on line 40 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
page = (WorkbenchPage) window.getActivePage(); | ||
Check warning on line 41 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
|
||
project = FileUtil.createProject("DragTest"); | ||
file1 = FileUtil.createFile("DragTest1.txt", project); | ||
file2 = FileUtil.createFile("DragTest2.txt", project); | ||
file3 = FileUtil.createFile("DragTest3.txt", project); | ||
} | ||
|
||
page.resetPerspective(); | ||
Check warning on line 49 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
page.closeAllEditors(false); | ||
Check warning on line 50 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
|
||
page.showView("org.eclipse.ui.views.ContentOutline"); | ||
Check warning on line 52 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
page.hideView(page.findView("org.eclipse.ui.internal.introview")); | ||
Check warning on line 53 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
editor1 = page.openEditor(new FileEditorInput(file1), MockEditorPart.ID1); | ||
Check warning on line 54 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
editor2 = page.openEditor(new FileEditorInput(file2), MockEditorPart.ID2); | ||
Check warning on line 55 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
editor3 = page.openEditor(new FileEditorInput(file3), MockEditorPart.ID2); | ||
Check warning on line 56 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
|
||
window.getShell().setActive(); | ||
Check warning on line 58 in tests/org.eclipse.ui.tests.dnd/src/org/eclipse/ui/tests/dnd/DragTest.java
|
||
DragOperations.drag(editor2, new EditorDropTarget(new ExistingWindowProvider(window), 0, SWT.CENTER), false); | ||
DragOperations.drag(editor3, new EditorAreaDropTarget(new ExistingWindowProvider(window), SWT.RIGHT), false); | ||
} | ||
|
||
@Test | ||
@DisplayName("drag editor2 to right") | ||
public void stallTest() { | ||
String[] testNames = {}; | ||
boolean testNameMatches = false; | ||
for (String testName : testNames) { | ||
if (testName.equals("drag editor2 to right")) { | ||
testNameMatches = true; | ||
break; | ||
} | ||
} | ||
|
||
if (testNames.length == 0 || testNameMatches) { | ||
Display display = Display.getCurrent(); | ||
Shell loopShell = new Shell(display, SWT.SHELL_TRIM); | ||
loopShell.setBounds(0, 0, 200, 100); | ||
loopShell.setText("Test Stall Shell"); | ||
loopShell.setVisible(true); | ||
|
||
while (loopShell != null && !loopShell.isDisposed()) { | ||
if (!display.readAndDispatch()) { | ||
display.sleep(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void performTest() throws Throwable { | ||
dragSource.setPage(page); | ||
dragSource.drag(dropTarget); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a .project file here is not needed and not desired.