-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error handling trying to enable HTML5 DnD for mobile from thre…
…ad (#12170) (#12175) - Informative error message - Reset back to disabled state when enabling fails - Incorrect usage also detectable using non-mobile devices Fixes #12152
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
uitest/src/main/java/com/vaadin/tests/components/ui/MobileHtml5DndEnablingError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.vaadin.tests.components.ui; | ||
|
||
import com.vaadin.server.VaadinRequest; | ||
import com.vaadin.tests.components.AbstractTestUI; | ||
import com.vaadin.ui.Label; | ||
|
||
public class MobileHtml5DndEnablingError extends AbstractTestUI { | ||
|
||
@Override | ||
protected void setup(VaadinRequest request) { | ||
final MobileHtml5DndEnablingError ui = MobileHtml5DndEnablingError.this; | ||
new Thread() { | ||
@Override | ||
public void run() { | ||
try { | ||
Thread.sleep(100); | ||
} catch (InterruptedException e) { | ||
} | ||
ui.access(() -> { | ||
Label label; | ||
try { | ||
ui.setMobileHtml5DndEnabled(true); | ||
label = new Label( | ||
"If you see this, there was no error."); | ||
} catch (Exception e) { | ||
label = new Label("Error message: " + e.getMessage()); | ||
} | ||
label.setId("error"); | ||
label.setSizeFull(); | ||
ui.addComponent(label); | ||
}); | ||
} | ||
}.start(); | ||
} | ||
|
||
@Override | ||
protected String getTestDescription() { | ||
return "Attempting to set HTML5 DnD enabled for mobile devices from " | ||
+ "a thread should give an informative error message."; | ||
} | ||
|
||
@Override | ||
protected Integer getTicketNumber() { | ||
return 12152; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
uitest/src/test/java/com/vaadin/tests/components/ui/MobileHtml5DndEnablingErrorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.vaadin.tests.components.ui; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
|
||
import com.vaadin.testbench.elements.LabelElement; | ||
import com.vaadin.tests.tb3.SingleBrowserTest; | ||
|
||
public class MobileHtml5DndEnablingErrorTest extends SingleBrowserTest { | ||
|
||
@Test | ||
public void testErrorMessage() { | ||
openTestURL(); | ||
LabelElement label = $(LabelElement.class).id("error"); | ||
assertTrue("Unexpected Label content: " + label.getText(), | ||
label.getText().startsWith("Error message: HTML5 DnD cannot")); | ||
} | ||
} |