]> source.dussan.org Git - vaadin-framework.git/commitdiff
Revert "Tree item fails with ItemClickListener (#14388)"
authorSauli Tähkäpää <sauli@vaadin.com>
Fri, 5 Sep 2014 12:20:27 +0000 (15:20 +0300)
committerVaadin Code Review <review@vaadin.com>
Fri, 5 Sep 2014 15:02:00 +0000 (15:02 +0000)
This reverts commit d71ae18e355468487a947c84d0f92ed9c44b002e
which caused regression on #6845.
Converted TreeItemClickListeningTest (#6845) to TB4.

Change-Id: Ia4c7c5814dc4e8916ab3f80633ceecdfb74040b0

client/src/com/vaadin/client/ui/VTree.java
uitest/src/com/vaadin/tests/components/tree/TreeItemClickListening.html [deleted file]
uitest/src/com/vaadin/tests/components/tree/TreeItemClickListening.java
uitest/src/com/vaadin/tests/components/tree/TreeItemClickListeningTest.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediate.java [deleted file]
uitest/src/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediateTest.java [deleted file]
uitest/src/com/vaadin/tests/tb3/AbstractTB3Test.java

index caa728ab21977cda7313582b2c9ac58094f03e87..b12053ea046dccdd9f47fadb471a93e518650035 100644 (file)
@@ -160,13 +160,6 @@ public class VTree extends FocusElementPanel implements VHasDropHandler,
 
     private boolean selectionHasChanged = false;
 
-    /*
-     * to fix #14388. The cause of defect #14388: event 'clickEvent' is sent to
-     * server before updating of "selected" variable, but should be send after
-     * it
-     */
-    private boolean sendClickEventNow = false;
-
     /** For internal use only. May be removed or replaced in the future. */
     public String[] bodyActionKeys;
 
@@ -478,15 +471,9 @@ public class VTree extends FocusElementPanel implements VHasDropHandler,
         Command command = new Command() {
             @Override
             public void execute() {
-                /*
-                 * we should send selection to server immediately in 2 cases: 1)
-                 * 'immediate' property of Tree is true 2) sendClickEventNow is
-                 * true
-                 */
                 client.updateVariable(paintableId, "selected",
                         selectedIds.toArray(new String[selectedIds.size()]),
-                        sendClickEventNow || immediate);
-                sendClickEventNow = false;
+                        immediate);
                 selectionHasChanged = false;
             }
         };
@@ -844,7 +831,7 @@ public class VTree extends FocusElementPanel implements VHasDropHandler,
                     // server. We do not want to send the event if there is a
                     // selection event happening after this. In all other cases
                     // we want to send it immediately.
-                    sendClickEventNow = true;
+                    boolean sendClickEventNow = true;
 
                     if (details.getButton() == MouseButton.LEFT && immediate
                             && selectable) {
@@ -862,13 +849,8 @@ public class VTree extends FocusElementPanel implements VHasDropHandler,
                     }
 
                     client.updateVariable(paintableId, "clickedKey", key, false);
-
-                    /*
-                     * in any case event should not be send immediately here -
-                     * send after updating of "selected" variable
-                     */
                     client.updateVariable(paintableId, "clickEvent",
-                            details.toString(), false);
+                            details.toString(), sendClickEventNow);
                 }
             });
         }
diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeItemClickListening.html b/uitest/src/com/vaadin/tests/components/tree/TreeItemClickListening.html
deleted file mode 100644 (file)
index 841565d..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head profile="http://selenium-ide.openqa.org/profiles/test-case">
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<link rel="selenium.base" href="" />
-<title>New Test</title>
-</head>
-<body>
-<table cellpadding="1" cellspacing="1" border="1">
-<thead>
-<tr><td rowspan="1" colspan="3">New Test</td></tr>
-</thead><tbody>
-<tr>
-       <td>open</td>
-       <td>/run/com.vaadin.tests.components.tree.TreeItemClickListening?restartApplication</td>
-       <td></td>
-</tr>
-<tr>
-       <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[0]</td>
-       <td>36,7</td>
-</tr>
-<tr>
-       <td>assertText</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::PID_SLog_row_0</td>
-       <td>1. Left Click</td>
-</tr>
-<tr>
-       <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[1]</td>
-       <td>45,7</td>
-</tr>
-<tr>
-       <td>assertText</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::PID_SLog_row_0</td>
-       <td>2. Left Click</td>
-</tr>
-<tr>
-       <td>mouseClick</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[2]</td>
-       <td>37,13</td>
-</tr>
-<tr>
-       <td>assertText</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::PID_SLog_row_0</td>
-       <td>3. Left Click</td>
-</tr>
-<tr>
-       <td>mouseDownRight</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[3]</td>
-       <td></td>
-</tr>
-<tr>
-       <td>mouseUpRight</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[3]</td>
-       <td></td>
-</tr>
-<tr>
-       <td>assertText</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::PID_SLog_row_0</td>
-       <td>4. Right Click</td>
-</tr>
-<tr>
-       <td>mouseDownRight</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[4]</td>
-       <td></td>
-</tr>
-<tr>
-       <td>mouseUpRight</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VTree[0]#n[4]</td>
-       <td></td>
-</tr>
-<tr>
-       <td>assertText</td>
-       <td>vaadin=runcomvaadintestscomponentstreeTreeItemClickListening::PID_SLog_row_0</td>
-       <td>5. Right Click</td>
-</tr>
-</tbody></table>
-</body>
-</html>
index 724c1c6f62e98d08138b8c3aea9a9714e8af5bed..a3f2b113cda792323e616b0b0313cb568bac93de 100644 (file)
@@ -1,24 +1,22 @@
 package com.vaadin.tests.components.tree;
 
 import com.vaadin.event.ItemClickEvent;
-import com.vaadin.tests.components.TestBase;
-import com.vaadin.tests.util.Log;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
 import com.vaadin.ui.Tree;
 
-public class TreeItemClickListening extends TestBase {
+public class TreeItemClickListening extends AbstractTestUIWithLog {
 
     private int clickCounter = 0;
 
-    private Log log = new Log(5);
-
     @Override
-    protected void setup() {
+    protected void setup(VaadinRequest request) {
 
         Tree tree = new Tree();
         tree.setImmediate(true);
 
         tree.addContainerProperty("caption", String.class, "");
-        for (int i = 1; i <= 10; i++) {
+        for (int i = 1; i <= 2; i++) {
             String item = "Node " + i;
             tree.addItem(item);
             tree.getContainerProperty(item, "caption").setValue("Caption " + i);
@@ -38,19 +36,15 @@ public class TreeItemClickListening extends TestBase {
                 case RIGHT:
                     log.log("Right Click");
                     break;
-                case MIDDLE:
-                    log.log("Middle Click");
-                    break;
                 }
             }
         });
 
         addComponent(tree);
-        addComponent(log);
     }
 
     @Override
-    protected String getDescription() {
+    protected String getTestDescription() {
         return "Item click event should be triggered from all mouse button clicks";
     }
 
@@ -58,5 +52,4 @@ public class TreeItemClickListening extends TestBase {
     protected Integer getTicketNumber() {
         return 6845;
     }
-
 }
diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeItemClickListeningTest.java b/uitest/src/com/vaadin/tests/components/tree/TreeItemClickListeningTest.java
new file mode 100644 (file)
index 0000000..2567fdb
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.tree;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class TreeItemClickListeningTest extends MultiBrowserTest {
+
+    private WebElement getTreeNode(String caption) {
+        return getDriver().findElement(
+                By.xpath("//span[text() = '" + caption + "']"));
+    }
+
+    @Test
+    public void test() throws InterruptedException {
+        openTestURL();
+
+        performLeftClick();
+        assertEventFired("1. Left Click");
+
+        performRightClick();
+        assertEventFired("2. Right Click");
+    }
+
+    private void assertEventFired(String text) {
+        assertThat(
+                String.format("Couldn't find text '%s' from the log.", text),
+                logContainsText(text));
+    }
+
+    private void performLeftClick() {
+        new Actions(driver).click(getTreeNode("Caption 1")).build().perform();
+    }
+
+    private void performRightClick() {
+        new Actions(driver).contextClick(getTreeNode("Caption 2")).build()
+                .perform();
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediate.java b/uitest/src/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediate.java
deleted file mode 100644 (file)
index 8e0f39b..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.vaadin.tests.components.tree;
-
-import com.vaadin.event.ItemClickEvent;
-import com.vaadin.server.VaadinRequest;
-import com.vaadin.tests.components.AbstractTestUIWithLog;
-import com.vaadin.ui.Tree;
-
-@SuppressWarnings("serial")
-public class TreeItemSelectionWithoutImmediate extends AbstractTestUIWithLog {
-
-    protected static final String TREE_ID = "TreeId";
-
-    protected static final String MENU_ITEM_TEMPLATE = "Menu Item %d";
-
-    @Override
-    protected void setup(VaadinRequest request) {
-        Tree tree = new Tree("With ItemClickListener not Immediate");
-        tree.setId(TREE_ID);
-        tree.setImmediate(false);
-
-        for (int i = 1; i <= 4; i++) {
-            tree.addItem(String.format(MENU_ITEM_TEMPLATE, i));
-        }
-
-        tree.addItemClickListener(new ItemClickEvent.ItemClickListener() {
-
-            @Override
-            public void itemClick(ItemClickEvent event) {
-                log("ItemClickEvent = " + event.getItemId());
-            }
-        });
-
-        addComponent(tree);
-    }
-
-    @Override
-    protected String getTestDescription() {
-        return "Test for ensuring that selection of tree items works correctly if immediate == false "
-                + "and ItemClickListener is added to Tree";
-    }
-
-    @Override
-    protected Integer getTicketNumber() {
-        return 14388;
-    }
-}
diff --git a/uitest/src/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediateTest.java b/uitest/src/com/vaadin/tests/components/tree/TreeItemSelectionWithoutImmediateTest.java
deleted file mode 100644 (file)
index 2fb35b1..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2000-2014 Vaadin Ltd.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.tests.components.tree;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.is;
-
-import org.junit.Test;
-import org.openqa.selenium.WebElement;
-import org.openqa.selenium.interactions.Actions;
-
-import com.vaadin.testbench.By;
-import com.vaadin.tests.tb3.MultiBrowserTest;
-
-public class TreeItemSelectionWithoutImmediateTest extends MultiBrowserTest {
-
-    private static final long serialVersionUID = 1L;
-
-    @Test
-    public void testSelectTreeWithItemClickListenerNotImmediate()
-            throws InterruptedException {
-        openTestURL();
-
-        // click on item i (in circle we select next item and check if it is
-        // selected in tree)
-        for (int i = 1; i <= 4; i++) {
-            WebElement treeItem = getTreeNode(String.format(
-                    TreeItemSelectionWithoutImmediate.MENU_ITEM_TEMPLATE, i));
-
-            new Actions(getDriver()).moveToElement(treeItem).click().perform();
-            Thread.sleep(100);
-
-            WebElement selectedElement = driver.findElement(By
-                    .className("v-tree-node-selected"));
-
-            treeItem = getTreeNode(String.format(
-                    TreeItemSelectionWithoutImmediate.MENU_ITEM_TEMPLATE, i));
-
-            assertThat("Clicked element should be selected", selectedElement
-                    .getText().equals(treeItem.getText()), is(true));
-        }
-    }
-
-    private WebElement getTreeNode(String caption) {
-        return getDriver().findElement(
-                By.xpath("//span[text() = '" + caption + "']"));
-    }
-}
index 1e1cbedbd6e291e1a915f5e70847f919e5605a60..8e6370a6fdb51d5f9f13a5a27b1712b7227a0127 100644 (file)
@@ -27,11 +27,10 @@ import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 import java.lang.reflect.Field;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import elemental.json.JsonObject;
-import elemental.json.impl.JsonUtil;
 import org.apache.commons.io.IOUtils;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
@@ -66,10 +65,15 @@ import com.vaadin.testbench.TestBench;
 import com.vaadin.testbench.TestBenchDriverProxy;
 import com.vaadin.testbench.TestBenchElement;
 import com.vaadin.testbench.TestBenchTestCase;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.testbench.elements.VerticalLayoutElement;
 import com.vaadin.tests.components.AbstractTestUIWithLog;
 import com.vaadin.tests.tb3.MultiBrowserTest.Browser;
 import com.vaadin.ui.UI;
 
+import elemental.json.JsonObject;
+import elemental.json.impl.JsonUtil;
+
 /**
  * Base class for TestBench 3+ tests. All TB3+ tests in the project should
  * extend this class.
@@ -1258,7 +1262,32 @@ public abstract class AbstractTB3Test extends TestBenchTestCase {
         return null;
     }
 
-    private static JsonObject extractObject(HttpResponse resp) throws IOException {
+    protected boolean logContainsText(String string) {
+        List<String> logs = getLogs();
+
+        for (String text : logs) {
+            if (text.contains(string)) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
+    protected List<String> getLogs() {
+        VerticalLayoutElement log = $(VerticalLayoutElement.class).id("Log");
+        List<LabelElement> logLabels = log.$(LabelElement.class).all();
+        List<String> logTexts = new ArrayList<String>();
+
+        for (LabelElement label : logLabels) {
+            logTexts.add(label.getText());
+        }
+
+        return logTexts;
+    }
+
+    private static JsonObject extractObject(HttpResponse resp)
+            throws IOException {
         InputStream contents = resp.getEntity().getContent();
         StringWriter writer = new StringWriter();
         IOUtils.copy(contents, writer, "UTF8");