Skip to content

Commit fc1dad9

Browse files
committed
ADAP-159: fixed test with Window.navigateBack and Forward
1 parent 520b4cc commit fc1dad9

3 files changed

Lines changed: 56 additions & 83 deletions

File tree

-3.26 KB
Binary file not shown.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,4 +450,12 @@ public void onError(Ack ack) {
450450
assertEquals("getMonitorInfo timeout", latch.getCount(), 0);
451451
return windowBoundsAtomicReference.get();
452452
}
453+
454+
public static void pause(int milliSeconds) {
455+
try {
456+
Thread.sleep(milliSeconds);
457+
} catch (InterruptedException e) {
458+
e.printStackTrace();
459+
}
460+
}
453461
}

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

Lines changed: 48 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class WindowTest {
3232
private static final String DESKTOP_UUID = WindowTest.class.getName();
3333
private static DesktopConnection desktopConnection;
3434
private static final String child_window_url = "http://test.openf.in/test.html"; // simple test app
35-
private static final String guest_url = "https://example.com";
35+
private static final String guest_url = "https://example.com/";
3636

3737
@BeforeClass
3838
public static void setup() throws Exception {
@@ -484,44 +484,11 @@ public void navigateBack() throws Exception {
484484
ApplicationOptions options = TestUtils.getAppOptions(null);
485485
Application application = TestUtils.runApplication(options, desktopConnection);
486486
Window window = application.getWindow();
487-
CountDownLatch latch = new CountDownLatch(1);
488-
window.navigate(guest_url, new AckListener() {
489-
@Override
490-
public void onSuccess(Ack ack) {
491-
if (ack.isSuccessful()) {
492-
window.navigate(guest_url, new AckListener() {
493-
@Override
494-
public void onSuccess(Ack ack) {
495-
if (ack.isSuccessful()) {
496-
window.navigateBack(new AckListener() {
497-
@Override
498-
public void onSuccess(Ack ack) {
499-
if (ack.isSuccessful()) {
500-
if (ack.isSuccessful()) {
501-
latch.countDown();
502-
}
503-
}
504-
}
505-
@Override
506-
public void onError(Ack ack) {
507-
}
508-
});
509-
}
510-
}
511-
@Override
512-
public void onError(Ack ack) {
513-
}
514-
});
515-
}
516-
}
517-
@Override
518-
public void onError(Ack ack) {
519-
}
520-
});
487+
CountDownLatch latch = new CountDownLatch(2);
488+
navigateAndWaitForContent(window, guest_url);
489+
navigateAndWaitForContent(window, "https://openfin.co");
490+
navigateHistoryAndWaitForContent(window, -1, latch);
521491

522-
latch.await(5, TimeUnit.SECONDS);
523-
assertEquals("Window.navigate timeout", latch.getCount(), 0);
524-
Thread.sleep(1000); // give time for guest_url to load
525492
window.executeJavaScript("location.href", result -> {
526493
if (result != null && result.toString().equals(guest_url)) {
527494
latch.countDown();
@@ -538,52 +505,12 @@ public void navigateForward() throws Exception {
538505
ApplicationOptions options = TestUtils.getAppOptions(null);
539506
Application application = TestUtils.runApplication(options, desktopConnection);
540507
Window window = application.getWindow();
541-
CountDownLatch latch = new CountDownLatch(1);
542-
window.navigate("https://www.google.com", new AckListener() {
543-
@Override
544-
public void onSuccess(Ack ack) {
545-
if (ack.isSuccessful()) {
546-
window.navigate(guest_url, new AckListener() {
547-
@Override
548-
public void onSuccess(Ack ack) {
549-
if (ack.isSuccessful()) {
550-
window.navigateBack(new AckListener() {
551-
@Override
552-
public void onSuccess(Ack ack) {
553-
if (ack.isSuccessful()) {
554-
window.navigateForward(new AckListener() {
555-
@Override
556-
public void onSuccess(Ack ack) {
557-
if (ack.isSuccessful()) {
558-
latch.countDown();
559-
}
560-
}
561-
@Override
562-
public void onError(Ack ack) {
563-
}
564-
});
565-
}
566-
}
567-
@Override
568-
public void onError(Ack ack) {
569-
}
570-
});
571-
}
572-
}
573-
@Override
574-
public void onError(Ack ack) {
575-
}
576-
});
577-
}
578-
}
579-
@Override
580-
public void onError(Ack ack) {
581-
}
582-
});
508+
CountDownLatch latch = new CountDownLatch(3);
509+
navigateAndWaitForContent(window, "https://openfin.co");
510+
navigateAndWaitForContent(window, guest_url);
511+
navigateHistoryAndWaitForContent(window, -1, latch);
512+
navigateHistoryAndWaitForContent(window, 1, latch);
583513

584-
latch.await(5, TimeUnit.SECONDS);
585-
assertEquals("Window.navigate timeout", latch.getCount(), 0);
586-
Thread.sleep(1000); // give time for guest_url to load
587514
window.executeJavaScript("location.href", result -> {
588515
if (result != null && result.toString().equals(guest_url)) {
589516
latch.countDown();
@@ -595,6 +522,44 @@ public void onError(Ack ack) {
595522
TestUtils.closeApplication(application);
596523
}
597524

525+
private void navigateAndWaitForContent(Window window, String url) throws Exception {
526+
String eventType = "dom-content-loaded";
527+
CountDownLatch latch = new CountDownLatch(1);
528+
EventListener listener = new EventListener() {
529+
@Override
530+
public void eventReceived(ActionEvent actionEvent) {
531+
if (eventType.equals(actionEvent.getType())) {
532+
latch.countDown();
533+
}
534+
}
535+
};
536+
TestUtils.addEventListener(window, "dom-content-loaded", listener);
537+
window.navigate(url, null);
538+
latch.await(5, TimeUnit.SECONDS);
539+
window.removeEventListener(eventType, listener, null);
540+
assertEquals("waitForWindowEvent timeout", latch.getCount(), 0);
541+
}
542+
543+
private void navigateHistoryAndWaitForContent(Window window, int direction, CountDownLatch latch) throws Exception {
544+
String eventType = "dom-content-loaded";
545+
EventListener listener = new EventListener() {
546+
@Override
547+
public void eventReceived(ActionEvent actionEvent) {
548+
if (eventType.equals(actionEvent.getType())) {
549+
latch.countDown();
550+
}
551+
}
552+
};
553+
TestUtils.addEventListener(window, "dom-content-loaded", listener);
554+
if (direction < 0) {
555+
window.navigateBack(null);
556+
} else {
557+
window.navigateForward(null);
558+
}
559+
latch.await(5, TimeUnit.SECONDS);
560+
window.removeEventListener(eventType, listener, null);
561+
}
562+
598563
@Test
599564
public void stopNavigate() throws Exception {
600565
ApplicationOptions options = TestUtils.getAppOptions(null);

0 commit comments

Comments
 (0)