-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Prevent NPE with autoUpload=false and multiple files are being u…
…ploaded (#919) Fixes: vaadin/vaadin-upload#358
- Loading branch information
Showing
4 changed files
with
107 additions
and
2 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
31 changes: 31 additions & 0 deletions
31
...tests/src/main/java/com/vaadin/flow/component/upload/tests/it/NonImmediateUploadView.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,31 @@ | ||
package com.vaadin.flow.component.upload.tests.it; | ||
|
||
import com.vaadin.flow.component.AttachEvent; | ||
import com.vaadin.flow.component.html.Div; | ||
import com.vaadin.flow.component.html.Span; | ||
import com.vaadin.flow.component.upload.Upload; | ||
import com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer; | ||
import com.vaadin.flow.router.Route; | ||
|
||
@Route("vaadin-upload/non-immediate-upload") | ||
public class NonImmediateUploadView extends Div { | ||
|
||
private Span result = new Span("No errors"); | ||
|
||
public NonImmediateUploadView() { | ||
result.setId("error-handler-message"); | ||
|
||
MultiFileMemoryBuffer buffer = new MultiFileMemoryBuffer(); | ||
Upload upload = new Upload(buffer); | ||
upload.setAutoUpload(false); | ||
add(upload, result); | ||
} | ||
|
||
@Override | ||
public void onAttach(AttachEvent attachEvent) { | ||
attachEvent.getUI().getSession().setErrorHandler(event -> { | ||
result.setText("There was an error"); | ||
event.getThrowable().printStackTrace(); | ||
}); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...tion-tests/src/test/java/com/vaadin/flow/component/upload/tests/NonImmediateUploadIT.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,65 @@ | ||
package com.vaadin.flow.component.upload.tests; | ||
|
||
import java.io.File; | ||
|
||
import org.junit.Assert; | ||
import org.junit.AssumptionViolatedException; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import com.vaadin.flow.component.upload.testbench.UploadElement; | ||
import com.vaadin.flow.testutil.TestPath; | ||
import com.vaadin.testbench.TestBenchElement; | ||
|
||
@TestPath("vaadin-upload/non-immediate-upload") | ||
public class NonImmediateUploadIT extends AbstractUploadIT { | ||
|
||
@Before | ||
public void init() { | ||
if (getRunLocallyBrowser() == null) { | ||
// Multiple file upload does not work with Remotewebdriver | ||
// and autoUpload=false | ||
// Related to | ||
// https://github.com/SeleniumHQ/selenium/issues/7408 | ||
throw new AssumptionViolatedException( | ||
"Skipped <Multiple file upload does not work with Remotewebdriver>"); | ||
} | ||
} | ||
|
||
@Test | ||
public void uploadMultipleFiles_shouldNotThrowException_onStart() | ||
throws Exception { | ||
uploadMultipleFiles_shouldNotThrowException("start-button"); | ||
} | ||
|
||
@Test | ||
public void uploadMultipleFiles_shouldNotThrowException_onRemove() | ||
throws Exception { | ||
uploadMultipleFiles_shouldNotThrowException("clear-button"); | ||
} | ||
|
||
private void uploadMultipleFiles_shouldNotThrowException(String buttonType) | ||
throws Exception { | ||
open(); | ||
File file1 = createTempFile(); | ||
File file2 = createTempFile(); | ||
UploadElement upload = $(UploadElement.class).waitForFirst(); | ||
WebElement input = getInput(upload); | ||
fillPathToUploadInput(input, file1.getPath(), file2.getPath()); | ||
WebElement button = findButtonInVaadinUploadFile(upload, buttonType); | ||
button.click(); | ||
TestBenchElement element = $("span").id("error-handler-message"); | ||
Assert.assertEquals("No errors", element.getText()); | ||
} | ||
|
||
private WebElement findButtonInVaadinUploadFile(UploadElement upload, | ||
String buttonType) { | ||
final String QUERY = String.format( | ||
"return arguments[0]" | ||
+ ".shadowRoot.querySelector('vaadin-upload-file')" | ||
+ ".shadowRoot.querySelector('[part=\"%s\"]')", | ||
buttonType); | ||
return (WebElement) getCommandExecutor().executeScript(QUERY, upload); | ||
} | ||
} |
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