Skip to content

Commit c24ee1a

Browse files
committed
Adjust animation test host return timing
1 parent 1d6d08f commit c24ee1a

File tree

1 file changed

+35
-33
lines changed

1 file changed

+35
-33
lines changed

docs/demos/common/src/test/java/com/codenameone/developerguide/animations/AnimationDemosScreenshotTest.java

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,7 @@ private void waitForFormReady(Form form) {
152152
}
153153

154154
private void waitForHost(Form host) {
155-
long deadline = System.currentTimeMillis() + FORM_TIMEOUT_MS;
156-
while (Display.getInstance().getCurrent() != host) {
157-
animateCurrentForm();
158-
TestUtils.waitFor(50);
159-
if (System.currentTimeMillis() > deadline) {
160-
fail("Timed out waiting to return to host form.");
161-
break;
162-
}
163-
}
155+
TestUtils.waitForFormTitle(HOST_TITLE, FORM_TIMEOUT_MS);
164156
TestUtils.waitFor(200);
165157
}
166158

@@ -170,40 +162,50 @@ private void returnToHost(Form demoForm, Form host) {
170162
}
171163

172164
long deadline = System.currentTimeMillis() + FORM_TIMEOUT_MS;
173-
174-
if (demoForm != null && demoForm != currentForm()) {
175-
unwindForm(demoForm, host);
165+
boolean restoreSlowMotion = Motion.isSlowMotion();
166+
if (restoreSlowMotion) {
167+
Motion.setSlowMotion(false);
176168
}
177169

178-
while (System.currentTimeMillis() <= deadline) {
179-
Dialog activeDialog = activeDialog();
180-
if (activeDialog != null) {
181-
activeDialog.dispose();
182-
animateCurrentForm();
183-
TestUtils.waitFor(120);
184-
continue;
170+
try {
171+
if (demoForm != null && demoForm != currentForm()) {
172+
unwindForm(demoForm, host);
185173
}
186174

187-
Form active = currentForm();
188-
if (active == host) {
189-
break;
175+
while (System.currentTimeMillis() <= deadline) {
176+
Dialog activeDialog = activeDialog();
177+
if (activeDialog != null) {
178+
activeDialog.dispose();
179+
animateCurrentForm();
180+
TestUtils.waitFor(120);
181+
continue;
182+
}
183+
184+
Form active = currentForm();
185+
if (active == host) {
186+
break;
187+
}
188+
189+
if (active == null) {
190+
host.show();
191+
} else {
192+
unwindForm(active, host);
193+
}
194+
195+
animateCurrentForm();
196+
TestUtils.waitFor(120);
190197
}
191198

192-
if (active == null) {
199+
if (currentForm() != host) {
193200
host.show();
194-
} else {
195-
unwindForm(active, host);
196201
}
197202

198-
animateCurrentForm();
199-
TestUtils.waitFor(120);
200-
}
201-
202-
if (currentForm() != host) {
203-
host.show();
203+
waitForHost(host);
204+
} finally {
205+
if (restoreSlowMotion) {
206+
Motion.setSlowMotion(true);
207+
}
204208
}
205-
206-
waitForHost(host);
207209
}
208210

209211
private void unwindForm(Form form, Form host) {

0 commit comments

Comments
 (0)