Commit 3b2fd29c authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: minor cleanup of test

BUG=none
TEST=none

Change-Id: I93d3562fcd28cc8d58f2e9b7ccb0356b6ee8dbbd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2097510Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749415}
parent 3689ffc8
...@@ -32,45 +32,42 @@ public class BrowserFragmentLifecycleTest { ...@@ -32,45 +32,42 @@ public class BrowserFragmentLifecycleTest {
public InstrumentationActivityTestRule mActivityTestRule = public InstrumentationActivityTestRule mActivityTestRule =
new InstrumentationActivityTestRule(); new InstrumentationActivityTestRule();
private Tab getTab() {
return TestThreadUtils.runOnUiThreadBlockingNoException(
() -> mActivityTestRule.getActivity().getTab());
}
@Test @Test
@SmallTest @SmallTest
public void successfullyLoadsUrlAfterRecreation() { public void successfullyLoadsUrlAfterRecreation() {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank"); mActivityTestRule.launchShellWithUrl("about:blank");
Tab tab = TestThreadUtils.runOnUiThreadBlockingNoException(() -> activity.getTab());
String url = "data:text,foo"; String url = "data:text,foo";
mActivityTestRule.navigateAndWait(tab, url, false); mActivityTestRule.navigateAndWait(getTab(), url, false);
mActivityTestRule.recreateActivity(); mActivityTestRule.recreateActivity();
InstrumentationActivity newActivity = mActivityTestRule.getActivity();
tab = TestThreadUtils.runOnUiThreadBlockingNoException(() -> newActivity.getTab());
url = "data:text,bar"; url = "data:text,bar";
mActivityTestRule.navigateAndWait(tab, url, false); mActivityTestRule.navigateAndWait(getTab(), url, false);
} }
@Test @Test
@SmallTest @SmallTest
public void restoreAfterRecreate() throws Throwable { public void restoreAfterRecreate() throws Throwable {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank"); mActivityTestRule.launchShellWithUrl("about:blank");
Tab tab = TestThreadUtils.runOnUiThreadBlockingNoException(() -> activity.getTab());
String url = "data:text,foo"; String url = "data:text,foo";
mActivityTestRule.navigateAndWait(tab, url, false); mActivityTestRule.navigateAndWait(getTab(), url, false);
mActivityTestRule.recreateActivity(); mActivityTestRule.recreateActivity();
InstrumentationActivity newActivity = mActivityTestRule.getActivity(); waitForTabToFinishRestore(getTab(), url);
waitForTabToFinishRestore(TestThreadUtils.runOnUiThreadBlocking(() -> {
return mActivityTestRule.getActivity().getTab();
}),
url);
} }
// https://crbug.com/1021041 // https://crbug.com/1021041
@Test @Test
@SmallTest @SmallTest
public void handlesFragmentDestroyWhileNavigating() { public void handlesFragmentDestroyWhileNavigating() {
BoundedCountDownLatch latch = new BoundedCountDownLatch(1);
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank"); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank");
BoundedCountDownLatch latch = new BoundedCountDownLatch(1);
TestThreadUtils.runOnUiThreadBlocking(() -> { TestThreadUtils.runOnUiThreadBlocking(() -> {
NavigationController navigationController = activity.getTab().getNavigationController(); NavigationController navigationController = activity.getTab().getNavigationController();
navigationController.registerNavigationCallback(new NavigationCallback() { navigationController.registerNavigationCallback(new NavigationCallback() {
...@@ -118,11 +115,10 @@ public class BrowserFragmentLifecycleTest { ...@@ -118,11 +115,10 @@ public class BrowserFragmentLifecycleTest {
extras.putString(InstrumentationActivity.EXTRA_PERSISTENCE_ID, "x"); extras.putString(InstrumentationActivity.EXTRA_PERSISTENCE_ID, "x");
final String url = mActivityTestRule.getTestDataURL("simple_page.html"); final String url = mActivityTestRule.getTestDataURL("simple_page.html");
mActivityTestRule.launchShellWithUrl(url, extras); mActivityTestRule.launchShellWithUrl(url, extras);
mActivityTestRule.recreateActivity(); mActivityTestRule.recreateActivity();
InstrumentationActivity newActivity = mActivityTestRule.getActivity(); Tab tab = getTab();
Assert.assertNotNull(newActivity);
Tab tab = TestThreadUtils.runOnUiThreadBlockingNoException(() -> newActivity.getTab());
Assert.assertNotNull(tab); Assert.assertNotNull(tab);
waitForTabToFinishRestore(tab, url); waitForTabToFinishRestore(tab, url);
} }
...@@ -148,7 +144,7 @@ public class BrowserFragmentLifecycleTest { ...@@ -148,7 +144,7 @@ public class BrowserFragmentLifecycleTest {
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString(InstrumentationActivity.EXTRA_PERSISTENCE_ID, "x"); extras.putString(InstrumentationActivity.EXTRA_PERSISTENCE_ID, "x");
final String url = mActivityTestRule.getTestDataURL("simple_page.html"); final String url = mActivityTestRule.getTestDataURL("simple_page.html");
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl(url, extras); mActivityTestRule.launchShellWithUrl(url, extras);
final String initialTabId = TestThreadUtils.runOnUiThreadBlocking( final String initialTabId = TestThreadUtils.runOnUiThreadBlocking(
() -> { return mActivityTestRule.getActivity().getTab().getGuid(); }); () -> { return mActivityTestRule.getActivity().getTab().getGuid(); });
Assert.assertNotNull(initialTabId); Assert.assertNotNull(initialTabId);
...@@ -156,8 +152,7 @@ public class BrowserFragmentLifecycleTest { ...@@ -156,8 +152,7 @@ public class BrowserFragmentLifecycleTest {
mActivityTestRule.recreateActivity(); mActivityTestRule.recreateActivity();
InstrumentationActivity newActivity = mActivityTestRule.getActivity(); Tab tab = getTab();
Tab tab = TestThreadUtils.runOnUiThreadBlockingNoException(() -> newActivity.getTab());
Assert.assertNotNull(tab); Assert.assertNotNull(tab);
waitForTabToFinishRestore(tab, url); waitForTabToFinishRestore(tab, url);
final String restoredTabId = final String restoredTabId =
...@@ -169,17 +164,16 @@ public class BrowserFragmentLifecycleTest { ...@@ -169,17 +164,16 @@ public class BrowserFragmentLifecycleTest {
@SmallTest @SmallTest
public void restoreTabGuidAfterRecreate() throws Throwable { public void restoreTabGuidAfterRecreate() throws Throwable {
InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank"); InstrumentationActivity activity = mActivityTestRule.launchShellWithUrl("about:blank");
final Tab tab = TestThreadUtils.runOnUiThreadBlockingNoException(() -> activity.getTab()); final Tab tab = getTab();
final String initialTabId = TestThreadUtils.runOnUiThreadBlocking( final String initialTabId =
() -> { return mActivityTestRule.getActivity().getTab().getGuid(); }); TestThreadUtils.runOnUiThreadBlocking(() -> { return tab.getGuid(); });
String url = "data:text,foo"; String url = "data:text,foo";
mActivityTestRule.navigateAndWait(tab, url, false); mActivityTestRule.navigateAndWait(tab, url, false);
mActivityTestRule.recreateActivity(); mActivityTestRule.recreateActivity();
InstrumentationActivity newActivity = mActivityTestRule.getActivity(); final Tab restoredTab = getTab();
final Tab restoredTab = Assert.assertNotEquals(tab, restoredTab);
TestThreadUtils.runOnUiThreadBlockingNoException(() -> newActivity.getTab());
waitForTabToFinishRestore(restoredTab, url); waitForTabToFinishRestore(restoredTab, url);
final String restoredTabId = TestThreadUtils.runOnUiThreadBlockingNoException( final String restoredTabId = TestThreadUtils.runOnUiThreadBlockingNoException(
() -> { return restoredTab.getGuid(); }); () -> { return restoredTab.getGuid(); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment