summaryrefslogtreecommitdiffstats
path: root/uitest
diff options
context:
space:
mode:
authorJuuso Valli <juuso@vaadin.com>2014-08-18 12:15:33 +0300
committerVaadin Code Review <review@vaadin.com>2014-08-19 13:52:25 +0000
commit5ae6f5b1d0f362c5893fa61730841b2a6bcb6e2d (patch)
tree99b9e5b4a3700b1c9d6343c371fca4e8f3b998c5 /uitest
parent90d7e00154b26dfc22b0ea46fc7775e39430eeec (diff)
downloadvaadin-framework-5ae6f5b1d0f362c5893fa61730841b2a6bcb6e2d.tar.gz
vaadin-framework-5ae6f5b1d0f362c5893fa61730841b2a6bcb6e2d.zip
Prevent erroneous screenshot removal (#14446)
Change-Id: I6832399a888a8f99a77b6d345271d02e5cec3f54
Diffstat (limited to 'uitest')
-rw-r--r--uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java40
1 files changed, 31 insertions, 9 deletions
diff --git a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java
index 1782e0042e..a99eea9bf6 100644
--- a/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java
+++ b/uitest/src/com/vaadin/tests/tb3/ScreenshotTB3Test.java
@@ -180,9 +180,20 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test {
* given reference image fails.
*/
private File getErrorFileFromReference(File referenceFile) {
- return new File(referenceFile.getAbsolutePath().replace(
- getScreenshotReferenceDirectory(),
- getScreenshotErrorDirectory()));
+
+ String absolutePath = referenceFile.getAbsolutePath();
+ String screenshotReferenceDirectory = getScreenshotReferenceDirectory();
+ String screenshotErrorDirectory = getScreenshotErrorDirectory();
+ // We throw an exception to safeguard against accidental reference
+ // deletion. See (#14446)
+ if (!absolutePath.contains(screenshotReferenceDirectory)) {
+ throw new IllegalStateException(
+ "Reference screenshot not in reference directory. Screenshot path: '"
+ + absolutePath + "', directory path: '"
+ + screenshotReferenceDirectory + "'");
+ }
+ return new File(absolutePath.replace(screenshotReferenceDirectory,
+ screenshotErrorDirectory));
}
/**
@@ -248,11 +259,23 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test {
protected abstract String getScreenshotDirectory();
/**
+ * @return the base directory of 'reference' and 'errors' screenshots with a
+ * trailing file separator
+ */
+ private String getScreenshotDirectoryWithTrailingSeparator() {
+ String screenshotDirectory = getScreenshotDirectory();
+ if (!screenshotDirectory.endsWith(File.separator)) {
+ screenshotDirectory += File.separator;
+ }
+ return screenshotDirectory;
+ }
+
+ /**
* @return the directory where reference images are stored (the 'reference'
* folder inside the screenshot directory)
*/
private String getScreenshotReferenceDirectory() {
- return getScreenshotDirectory() + "/reference";
+ return getScreenshotDirectoryWithTrailingSeparator() + "reference";
}
/**
@@ -260,7 +283,7 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test {
* (the 'errors' folder inside the screenshot directory)
*/
private String getScreenshotErrorDirectory() {
- return getScreenshotDirectory() + "/errors";
+ return getScreenshotDirectoryWithTrailingSeparator() + "errors";
}
/**
@@ -366,7 +389,7 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test {
}
// WindowMaximizeRestoreTest_Windows_InternetExplorer_8_window-1-moved-maximized-restored.png
- return getScreenshotReferenceDirectory() + "/"
+ return getScreenshotReferenceDirectory() + File.separator
+ getScreenshotBaseName() + "_" + uniqueBrowserIdentifier + "_"
+ identifier + ".png";
}
@@ -399,13 +422,12 @@ public abstract class ScreenshotTB3Test extends AbstractTB3Test {
errorDirectory.mkdirs();
}
- final String errorBase = getScreenshotErrorBaseName()
- .replace("\\", "/");
+ final String errorBase = getScreenshotErrorBaseName();
File[] files = errorDirectory.listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
- String thisFile = pathname.getAbsolutePath().replace("\\", "/");
+ String thisFile = pathname.getAbsolutePath();
if (thisFile.startsWith(errorBase)) {
return true;
}