diff options
author | Simeon Andreev | 2017-12-12 08:48:04 +0000 |
---|---|---|
committer | Eric Williams | 2017-12-13 15:51:37 +0000 |
commit | fc22ad835b303358b44053dbf13b338315828ee6 (patch) | |
tree | 24db58efdb8f56f4b38bdd4d144ea867712c7795 /tests/org.eclipse.swt.tests | |
parent | 49ef404ccb2016f1522c5d6b966c44116aeeba21 (diff) | |
download | eclipse.platform.swt-fc22ad835b303358b44053dbf13b338315828ee6.tar.gz eclipse.platform.swt-fc22ad835b303358b44053dbf13b338315828ee6.tar.xz eclipse.platform.swt-fc22ad835b303358b44053dbf13b338315828ee6.zip |
Bug 528251 - Test to check tab highlight with nested CTabFolders
When a view contains a selected CTabFolder, selecting another view in
the same part stack results in non-highlighted view tab. This is the
case, since CTabFolder.onActivate/onDeactivate will tell ancestor
CTabFolders to highlight resp. not highlight. Selecting another view
results in deactivating the nested CTabFolder and so removing
highlighting from the part stack tabs.
This is a test for the missing highlight.
Change-Id: Iad92b122883068114ddeebe96bc422da206d2c85
Signed-off-by: Simeon Andreev <simeon.danailov.andreev@gmail.com>
Diffstat (limited to 'tests/org.eclipse.swt.tests')
-rw-r--r-- | tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java index 592a392300..b678a4892b 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_CTabFolder.java @@ -14,16 +14,20 @@ package org.eclipse.swt.tests.junit; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; +import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.graphics.Color; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Text; import org.junit.Before; import org.junit.Ignore; @@ -182,4 +186,83 @@ public void test_checkSize() { assertTrue("\nBug 507611 - CTabFolder is too thin for its actual content. \nCtabFolder height:"+folderY+"\nExpected min:"+expectedminHeight, folderY > expectedminHeight); } +/** + * Test for bug 528251. + * + * We define two {@link CTabFolder tab folders}, of which one has a nested tab folder. + * We validate that selecting the nested tab does not break selection highlight for the top-level tabs. + * + * @see Bug528251_CTabFolder_nested_highlighting + */ +@Test +public void test_nestedTabHighlighting () { + CTabFolder partStackTabFolder = new CTabFolder(shell, SWT.NONE); + + CTabItem consoleViewTab = new CTabItem(partStackTabFolder, SWT.NONE); + consoleViewTab.setText("Console View"); + + SashForm anotherView = new SashForm(partStackTabFolder, SWT.NONE); + CTabItem anotherViewTab = new CTabItem(partStackTabFolder, SWT.NONE); + anotherViewTab.setText("Other View"); + anotherViewTab.setControl(anotherView); + CTabFolder anotherViewNestedTabFolder = new CTabFolder(anotherView, SWT.NONE); + CTabItem anotherViewNestedTab = new CTabItem(anotherViewNestedTabFolder, SWT.NONE); + anotherViewNestedTab.setText("nested tab"); + + shell.pack(); + shell.open(); + + processEvents(); + + // nothing is selected, expect no highlight + boolean shouldHighlightConsoleViewTab = reflection_shouldHighlight(partStackTabFolder); + assertFalse("expected CTabFolder to not need highlighting without any selection", + shouldHighlightConsoleViewTab); + + // "click" on the Console View tab + partStackTabFolder.notifyListeners(SWT.Activate, new Event()); + partStackTabFolder.setSelection(consoleViewTab); + // "click" on the Other View tab, per default the first sub-tab is also highlighted + partStackTabFolder.setSelection(anotherViewTab); + anotherViewNestedTabFolder.notifyListeners(SWT.Activate, new Event()); + // "click" on the nested tab + anotherViewNestedTabFolder.setSelection(anotherViewNestedTab); + partStackTabFolder.setSelection(consoleViewTab); + // "click" on the Console View tab, this hides and deactivates the nested CTabFolder + anotherViewNestedTabFolder.notifyListeners(SWT.Deactivate, new Event()); + processEvents(); + + // the Console View tab is selected, so it should still be highlighted + shouldHighlightConsoleViewTab = reflection_shouldHighlight(partStackTabFolder); + assertTrue("Bug 528251 - View tab not highlighted due to another view with a CTabFolder", + shouldHighlightConsoleViewTab); +} + +private void processEvents() { + Display display = shell.getDisplay(); + + while (display.readAndDispatch()) { + // + } +} + +private static boolean reflection_shouldHighlight(CTabFolder partStackTabs) { + String shouldHighlightMethodName = "shouldHighlight"; + Class<?> cTabFolderClass = CTabFolder.class; + + boolean shouldHighlightConsoleViewTab = false; + try { + Method method = cTabFolderClass.getDeclaredMethod(shouldHighlightMethodName); + method.setAccessible(true); + Object result = method.invoke(partStackTabs); + Boolean shouldHighlight = (Boolean) result; + shouldHighlightConsoleViewTab = shouldHighlight.booleanValue(); + } catch (Throwable t) { + String message = "reflection call to " + cTabFolderClass.getName() + "." + shouldHighlightMethodName + "() failed"; + throw new AssertionError(message, t); + } + + return shouldHighlightConsoleViewTab; +} + } |