Author: vrubezhny
Date: 2012-02-15 11:48:43 -0500 (Wed, 15 Feb 2012)
New Revision: 38765
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexResolveSelector.html
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleResolveSelector.css
Modified:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java
Log:
JBIDE-10127
Resolve selector in open-on of style class in VPE
org.jboss.tools.jst.text.ext.test.CSSStylesheetOpenOnTest.testCSSClassResolveSelectorOpenOn()
JUnit Test Test Case is added due to verify the issue.
org.jboss.tools.jst.text.ext.test.CSSStylesheetOpenOnTest.
testCSSClassOpenOnWithASecondRuleNameInARow() JUnit Test Case is fixed.
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexResolveSelector.html
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexResolveSelector.html
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexResolveSelector.html 2012-02-15
16:48:43 UTC (rev 38765)
@@ -0,0 +1,39 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
+ <title>Hello!</title>
+ <link href="styleResolveSelector.css" rel="stylesheet"
type="text/css"/>
+</head>
+<body>
+ <p class="styleA">
+ .styleA {color: #FF0000}
+ </p>
+ <p class="styleA">
+ .styleA {color: #FF0000}
+ <br/>
+ <b class="styleB">.styleA .styleB {color: #FF8000}</b>
+ </p>
+ <div class="styleA">
+ div.styleA {color: #FF0080}
+ </div>
+ <div title="x" class="styleA">
+ div[title="x"].styleA {color: #0000FF}
+ </div>
+ <p>
+ <input type="button" class="styleA" value="p input.styleA
{color: #CCAA00}"/>
+ </p>
+ <div>
+ <p>
+ <input type="button" class="styleA" value="div p
input.styleA {color: #CC00FF}"/>
+ </p>
+ </div>
+ <div title="y">
+ <div>
+ <p>
+ <input type="button" class="styleA"
value="[title='y'] div p input.styleA {color: #00CCFF}"/>
+ </p>
+ </div>
+ </div>
+</body>
+</html>
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexResolveSelector.html
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html 2012-02-15
16:44:11 UTC (rev 38764)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/indexWithSecondClassInRule.html 2012-02-15
16:48:43 UTC (rev 38765)
@@ -5,8 +5,20 @@
<link rel="stylesheet" href="secondClassName.css" />
</head>
<body>
- <div class="event">aaa</div>
- <div class="evt_sub">bbb</div>
- <div class="style2">ccc</div>
+ <div class="event">
+ <div class="evt_sub">
+ <div class="style2">.event .evt_sub .style2</div>
+ </div>
+ </div>
+ <div class="event">
+ <div class="evt_sub">
+ <div class="style2"><span>.event .evt_sub .style2
span</span></div>
+ </div>
+ </div>
+ <div class="event">
+ <div class="evt_sub">
+ <div class="style2"><strong>.event .evt_sub .style2
strong</strong></div>
+ </div>
+ </div>
</body>
</html>
Added:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleResolveSelector.css
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleResolveSelector.css
(rev 0)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleResolveSelector.css 2012-02-15
16:48:43 UTC (rev 38765)
@@ -0,0 +1,7 @@
+.styleA {color: #FF0000}
+.styleA .styleB {color: #FF8000}
+div.styleA {color: #FF0080}
+div[title="x"].styleA {color: #0000FF}
+p input.styleA {color: #CCAA00}
+div p input.styleA {color: #CC00FF}
+[title="y"] p input.styleA {color: #00CCFF}
\ No newline at end of file
Property changes on:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/projects/OpenOnTest/WebContent/styleResolveSelector.css
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java 2012-02-15
16:44:11 UTC (rev 38764)
+++
trunk/jst/tests/org.jboss.tools.jst.text.ext.test/src/org/jboss/tools/jst/text/ext/test/CSSStylesheetOpenOnTest.java 2012-02-15
16:48:43 UTC (rev 38765)
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 Red Hat, Inc.
+ * Copyright (c) 2011-2012 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
@@ -20,6 +20,7 @@
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.source.ISourceViewer;
@@ -37,8 +38,8 @@
private static final String PAGE_NAME =
PROJECT_NAME+"/WebContent/index.html";
private static final String MEDIA_PAGE_NAME =
PROJECT_NAME+"/WebContent/indexWithMediaRules.html";
private static final String SECOND_IN_A_ROW_PAGE_NAME =
PROJECT_NAME+"/WebContent/indexWithSecondClassInRule.html";
+ private static final String RESOLVE_SELECTOR_PAGE_NAME =
PROJECT_NAME+"/WebContent/indexResolveSelector.html";
-
public IProject project = null;
protected void setUp() {
@@ -219,11 +220,9 @@
*/
public void testCSSClassOpenOnWithASecondRuleNameInARow() throws PartInitException,
BadLocationException {
HashSet<IEditorPart> openedEditors = new HashSet<IEditorPart>();
- final String tagName = "<div";
- final String[] valuesToFind = {
- "event", "evt_sub", "style2"};
- final String[] editorNames = {
- "secondClassName.css", "secondClassName.css",
"secondClassName.css"};
+ final String textToFind = "class=\"style2\"";
+ final String valueToFind = "style2";
+ final String editorName = "secondClassName.css";
final int[] editorSelectionOffsets = {
0, 0, 0};
final int[] editorSelectionLengths = {
@@ -237,18 +236,21 @@
ISourceViewer viewer = jspMultyPageEditor.getSourceEditor().getTextViewer();
IDocument document = viewer.getDocument();
- for (int i = 0; i < valuesToFind.length; i++) {
- IRegion reg = new FindReplaceDocumentAdapter(document).find(0,
- tagName, true, true, false, false);
- assertNotNull("Tag:"+tagName+" not found",reg);
-
+ int startFrom = 0;
+ for (int i = 0; i < editorSelectionOffsets.length; i++) {
+ IRegion reg = new FindReplaceDocumentAdapter(document).find(startFrom,
+ textToFind, true, true, false, false);
+ assertNotNull("Tag: <div "+textToFind+"/> not found",reg);
+
+ startFrom = reg.getOffset() + reg.getLength();
+
reg = new FindReplaceDocumentAdapter(document).find(reg.getOffset(),
- valuesToFind[i], true, true, false, false);
- assertNotNull("Value to find '"+valuesToFind[i]+"' not
found",reg);
-
+ valueToFind, true, true, false, false);
+ assertNotNull("Tag: <div "+textToFind+"/> not found",reg);
+
IHyperlink[] links = HyperlinkDetector.getInstance().detectHyperlinks(viewer, reg,
true); // new Region(reg.getOffset() + reg.getLength(), 0)
- assertTrue("Hyperlinks for value '"+valuesToFind[i]+"' are not
found",(links != null && links.length > 0));
+ assertTrue("Hyperlinks for value '"+valueToFind+"' are not
found",(links != null && links.length > 0));
boolean found = false;
for(IHyperlink link : links){
@@ -258,7 +260,7 @@
IEditorPart resultEditor =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (resultEditor != null) openedEditors.add(resultEditor);
- if(editorNames[i].equals(resultEditor.getTitle())){
+ if(editorName.equals(resultEditor.getTitle())){
StructuredTextEditor stEditor = null;
if (resultEditor instanceof StructuredTextEditor) {
stEditor = (StructuredTextEditor)resultEditor;
@@ -277,14 +279,95 @@
}
}
}
- assertTrue("OpenOn have not opened "+editorNames[i]+"
editor",found);
+ assertTrue("OpenOn have not opened "+editorName+"
editor",found);
}
} finally {
closeEditors(openedEditors);
}
}
-
+ public void testCSSClassResolveSelectorOpenOn() throws PartInitException,
BadLocationException {
+ HashSet<IEditorPart> openedEditors = new HashSet<IEditorPart>();
+
+ // CSS class names to be tested are placed one by one,
+ // so, for each next test we'll continue to search in document
+ // (We'll not search from beginning each time)
+ //
+ // Position to continue the search from
+ int startFrom = 0;
+
+ // 'class="' - is the string to search
+ final String TEXT_TO_SEARCH = "class=\"";
+
+ // Valid CSS Stylesheet to be opened
+ final String VALID_CSS_EDITOR_NAME = "styleResolveSelector.css";
+
+ // Valid values for Text Selection after the open on is performed
+ final String[] VALID_TEXT_SELECTIONS = new String[] {
+ ".styleA {color: #FF0000}",
+ ".styleA {color: #FF0000}",
+ ".styleA .styleB {color: #FF8000}",
+ "div.styleA {color: #FF0080}",
+ "div[title=\"x\"].styleA {color: #0000FF}",
+ "p input.styleA {color: #CCAA00}",
+ "div p input.styleA {color: #CC00FF}",
+ "[title=\"y\"] p input.styleA {color: #00CCFF}"
+ };
+
+ for (int i = 0; i < VALID_TEXT_SELECTIONS.length; i++) {
+ IEditorPart editor = WorkbenchUtils.openEditor(RESOLVE_SELECTOR_PAGE_NAME);
+ if (editor != null) openedEditors.add(editor);
+ try {
+ assertTrue(editor instanceof JSPMultiPageEditor);
+ JSPMultiPageEditor jspMultyPageEditor = (JSPMultiPageEditor) editor;
+ ISourceViewer viewer = jspMultyPageEditor.getSourceEditor().getTextViewer();
+
+ IDocument document = viewer.getDocument();
+ IRegion reg = new FindReplaceDocumentAdapter(document).find(startFrom,
+ TEXT_TO_SEARCH, true, true, false, false);
+ assertNotNull("Attribute :" + TEXT_TO_SEARCH + " not found whyle
search starting from " + startFrom, reg);
+
+ startFrom = reg.getOffset() + reg.getLength();
+
+ IHyperlink[] links = HyperlinkDetector.getInstance().detectHyperlinks(viewer, new
Region(startFrom, 0), true); // new Region(reg.getOffset() + reg.getLength(), 0)
+
+ assertTrue("Hyperlinks not found for position " + startFrom,(links != null
&& links.length > 0));
+
+ boolean found = false;
+ for(IHyperlink link : links){
+ assertNotNull(link.toString());
+
+ link.open();
+
+ IEditorPart resultEditor =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ if (resultEditor != null) openedEditors.add(resultEditor);
+ if(VALID_CSS_EDITOR_NAME.equals(resultEditor.getTitle())){
+ StructuredTextEditor stEditor = null;
+ if (resultEditor instanceof StructuredTextEditor) {
+ stEditor = (StructuredTextEditor)resultEditor;
+ } else if (resultEditor instanceof JSPMultiPageEditor) {
+ stEditor = ((JSPMultiPageEditor)resultEditor).getSourceEditor();
+ }
+ assertNotNull("Unexpected Editor is openned: " + resultEditor.getTitle()
+ " [" + resultEditor.getClass().getName() + "]", stEditor);
+ ISelection selection = stEditor.getSelectionProvider().getSelection();
+ assertFalse("Required CSS Rule is not selected", selection.isEmpty());
+ if (selection instanceof TextSelection) {
+ TextSelection textSelection = (TextSelection)selection;
+ String selectionText =
stEditor.getTextViewer().getDocument().get(textSelection.getOffset(),
textSelection.getLength());
+ assertTrue("Required CSS Rule is not selected",
+ (VALID_TEXT_SELECTIONS[i].equalsIgnoreCase(selectionText)));
+ found = true;
+ break;
+ }
+ }
+ }
+ assertTrue("OpenOn have not opened a valid selection in " +
VALID_CSS_EDITOR_NAME + " editor",found);
+ } finally {
+ closeEditors(openedEditors);
+ }
+ }
+ }
+
protected void closeEditors (HashSet<IEditorPart> editors) {
if (editors == null || editors.isEmpty())
return;