Commit 3593028a authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

weblayer: adds test for top-view crash

BUG=1075662
TEST=FullscreenCallbackTest.testDestroyFragmentWhileFullscreen

Change-Id: I46cc5865fe5b395304f860d715704bc909a818ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2170976Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763492}
parent e30b83a5
...@@ -79,4 +79,13 @@ public class FullscreenCallbackTest { ...@@ -79,4 +79,13 @@ public class FullscreenCallbackTest {
mDelegate.waitForExitFullscreen(); mDelegate.waitForExitFullscreen();
Assert.assertEquals(1, mDelegate.mExitFullscreenCount); Assert.assertEquals(1, mDelegate.mExitFullscreenCount);
} }
/**
* Verifies there are no crashes when destroying the fragment in fullscreen.
*/
@Test
@SmallTest
public void testDestroyFragmentWhileFullscreen() {
TestThreadUtils.runOnUiThreadBlocking(() -> { mActivity.destroyFragment(); });
}
} }
...@@ -91,6 +91,21 @@ public class InstrumentationActivity extends FragmentActivity { ...@@ -91,6 +91,21 @@ public class InstrumentationActivity extends FragmentActivity {
return mBrowser; return mBrowser;
} }
/**
* Explicitly destroys the fragment. There is normally no need to call this. It's useful for
* tests that want to verify destruction.
*/
public void destroyFragment() {
removeCallbacks();
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.remove(mFragment);
transaction.commitNow();
mFragment = null;
mBrowser = null;
}
/** Interface used to intercept intents for testing. */ /** Interface used to intercept intents for testing. */
public static interface IntentInterceptor { public static interface IntentInterceptor {
void interceptIntent(Fragment fragment, Intent intent, int requestCode, Bundle options); void interceptIntent(Fragment fragment, Intent intent, int requestCode, Bundle options);
...@@ -194,12 +209,17 @@ public class InstrumentationActivity extends FragmentActivity { ...@@ -194,12 +209,17 @@ public class InstrumentationActivity extends FragmentActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
removeCallbacks();
}
private void removeCallbacks() {
if (mTabCallback != null) { if (mTabCallback != null) {
mTab.unregisterTabCallback(mTabCallback); mTab.unregisterTabCallback(mTabCallback);
mTabCallback = null; mTabCallback = null;
} }
if (mTabListCallback != null) { if (mTabListCallback != null) {
mBrowser.unregisterTabListCallback(mTabListCallback); mBrowser.unregisterTabListCallback(mTabListCallback);
mTabListCallback = null;
} }
} }
......
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