|
28 | 28 | import android.util.AndroidRuntimeException;
|
29 | 29 | import android.view.LayoutInflater;
|
30 | 30 | import androidx.fragment.app.testing.FragmentScenario;
|
| 31 | +import androidx.lifecycle.Lifecycle; |
31 | 32 | import androidx.test.espresso.web.webdriver.DriverAtoms;
|
32 | 33 | import androidx.test.espresso.web.webdriver.Locator;
|
33 | 34 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
@@ -264,4 +265,42 @@ void onFailure(HCaptchaException exception) {
|
264 | 265 |
|
265 | 266 | assertTrue(failureLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS));
|
266 | 267 | }
|
| 268 | + |
| 269 | + @Test |
| 270 | + public void testPauseResumeFragment() throws Exception { |
| 271 | + final CountDownLatch successLatch = new CountDownLatch(1); |
| 272 | + final HCaptchaStateListener listener = new HCaptchaStateTestAdapter() { |
| 273 | + |
| 274 | + @Override |
| 275 | + void onSuccess(String token) { |
| 276 | + successLatch.countDown(); |
| 277 | + } |
| 278 | + }; |
| 279 | + |
| 280 | + final FragmentScenario<HCaptchaDialogFragment> scenario = launchCaptchaFragment(config, listener); |
| 281 | + scenario.moveToState(Lifecycle.State.STARTED).moveToState(Lifecycle.State.RESUMED); |
| 282 | + |
| 283 | + waitHCaptchaWebViewToken(successLatch, AWAIT_CALLBACK_MS); |
| 284 | + |
| 285 | + assertTrue(successLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS)); |
| 286 | + } |
| 287 | + |
| 288 | + @Test |
| 289 | + public void testActivityRecreate() throws Exception { |
| 290 | + final CountDownLatch successLatch = new CountDownLatch(1); |
| 291 | + final HCaptchaStateListener listener = new HCaptchaStateTestAdapter() { |
| 292 | + |
| 293 | + @Override |
| 294 | + void onSuccess(String token) { |
| 295 | + successLatch.countDown(); |
| 296 | + } |
| 297 | + }; |
| 298 | + |
| 299 | + final FragmentScenario<HCaptchaDialogFragment> scenario = launchCaptchaFragment(config, listener); |
| 300 | + scenario.recreate(); |
| 301 | + |
| 302 | + waitHCaptchaWebViewToken(successLatch, AWAIT_CALLBACK_MS); |
| 303 | + |
| 304 | + assertTrue(successLatch.await(AWAIT_CALLBACK_MS, TimeUnit.MILLISECONDS)); |
| 305 | + } |
267 | 306 | }
|
0 commit comments