Skip to content

Commit 0f33778

Browse files
committed
ADAP-78: added test case for "preload"
1 parent fa310db commit 0f33778

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

src/test/java/com/openfin/desktop/WindowTest.java

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
package com.openfin.desktop;
22

3-
import com.openfin.desktop.animation.AnimationTransitions;
4-
import com.openfin.desktop.animation.OpacityTransition;
5-
import com.openfin.desktop.animation.PositionTransition;
6-
import com.openfin.desktop.animation.SizeTransition;
7-
import com.openfin.desktop.demo.WindowEmbedDemo;
8-
import org.junit.AfterClass;
9-
import org.junit.BeforeClass;
10-
import org.junit.Test;
11-
import org.slf4j.Logger;
12-
import org.slf4j.LoggerFactory;
3+
import static junit.framework.Assert.assertEquals;
4+
import static junit.framework.Assert.assertFalse;
5+
import static junit.framework.Assert.assertTrue;
136

7+
import java.net.URL;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
1410
import java.util.HashMap;
15-
import java.util.List;
1611
import java.util.Map;
1712
import java.util.concurrent.CountDownLatch;
1813
import java.util.concurrent.TimeUnit;
1914
import java.util.concurrent.atomic.AtomicReference;
2015

21-
import static junit.framework.Assert.assertEquals;
22-
import static junit.framework.Assert.assertFalse;
23-
import static junit.framework.Assert.assertTrue;
16+
import org.junit.AfterClass;
17+
import org.junit.BeforeClass;
18+
import org.junit.Test;
19+
import org.slf4j.Logger;
20+
import org.slf4j.LoggerFactory;
21+
22+
import com.openfin.desktop.animation.AnimationTransitions;
23+
import com.openfin.desktop.animation.OpacityTransition;
24+
import com.openfin.desktop.animation.PositionTransition;
25+
import com.openfin.desktop.animation.SizeTransition;
2426

2527
/**
2628
* Created by wche on 1/25/16.
@@ -637,5 +639,34 @@ public void onError(Ack ack) {
637639
assertEquals("Window.executeJavaScript timeout", latch.getCount(), 0);
638640
TestUtils.closeApplication(application);
639641
}
642+
643+
@Test
644+
public void preload() throws Exception {
645+
URL preloadHtml = WindowTest.class.getClassLoader().getResource("preload.html");
646+
URL preloadJs = WindowTest.class.getClassLoader().getResource("preload.js");
647+
648+
Path preloadHtmlPath = Paths.get(preloadHtml.toURI());
649+
Path preloadJsPath = Paths.get(preloadJs.toURI());
650+
651+
ApplicationOptions options = TestUtils.getAppOptions(preloadHtmlPath.toUri().toString());
652+
options.getMainWindowOptions().setPreload(preloadJsPath.toUri().toString());
653+
654+
Application application = TestUtils.runApplication(options, desktopConnection);
655+
656+
Window mainWindow = application.getWindow();
657+
658+
Thread.sleep(1000);
659+
CountDownLatch latch = new CountDownLatch(1);
660+
mainWindow.executeJavaScript("_preload", result -> {
661+
if (result != null && result.toString().equals("12345")) {
662+
latch.countDown();
663+
}
664+
}, null);
665+
666+
latch.await(5, TimeUnit.SECONDS);
667+
assertEquals("execute java script timeout: " + options.getUUID(), 0, latch.getCount());
668+
669+
TestUtils.closeApplication(application);
670+
}
640671

641672
}

src/test/resources/preload.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
</head>
4+
<body>
5+
<div id="preload_test">
6+
<h4> this is a test </h4>
7+
</div>
8+
</body>
9+
</html>

src/test/resources/preload.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var _preload = 12345

0 commit comments

Comments
 (0)