diff options
| author | yusufo <yusufo@chromium.org> | 2016-03-24 15:33:11 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-03-24 22:35:29 +0000 |
| commit | 1939a020289f67eea94e2e5b73c15b491ea1c008 (patch) | |
| tree | bb37c58e7cf8973cfe1ae5856db21dda90d5d2a5 | |
| parent | ef83bc364ce7d0d27f1bcd8b97f2decabe9690b0 (diff) | |
| download | chromium_src-1939a020289f67eea94e2e5b73c15b491ea1c008.zip chromium_src-1939a020289f67eea94e2e5b73c15b491ea1c008.tar.gz chromium_src-1939a020289f67eea94e2e5b73c15b491ea1c008.tar.bz2 | |
Add tests for Tab reparenting
- Fixes a strict mode violation in tab reparenting.
- Adds basic test that reparent a tab and check whether the
right WindowAndroid was accessible.
- Adds tests that check whether infobar and select pop ups are
not clashing with reparenting
BUG=597740
Review URL: https://codereview.chromium.org/1830843002
Cr-Commit-Position: refs/heads/master@{#383169}
4 files changed, 162 insertions, 6 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java index 82fde9f..91b67cb 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/customtabs/CustomTabActivity.java @@ -577,7 +577,7 @@ public class CustomTabActivity extends ChromeActivity { && TextUtils.equals(getPackageName(), creatorPackage)) { RecordUserAction.record( "TaskManagement.OpenInChromeActionButtonClicked"); - if (openCurrentUrlInBrowser()) finish(); + if (openCurrentUrlInBrowser(false)) finish(); } else { mIntentDataProvider.sendButtonPendingIntentWithUrl( getApplicationContext(), getActivityTab().getUrl()); @@ -697,7 +697,7 @@ public class CustomTabActivity extends ChromeActivity { && !mIntentDataProvider.shouldShowBookmarkMenuItem()) { return true; } else if (id == R.id.open_in_browser_id) { - openCurrentUrlInBrowser(); + openCurrentUrlInBrowser(false); RecordUserAction.record("CustomTabsMenuOpenInChrome"); return true; } else if (id == R.id.find_in_page_id) { @@ -745,10 +745,11 @@ public class CustomTabActivity extends ChromeActivity { /** * Opens the URL currently being displayed in the Custom Tab in the regular browser. + * @param forceReparenting Whether tab reparenting should be forced for testing. * * @return Whether or not the tab was sent over successfully. */ - boolean openCurrentUrlInBrowser() { + boolean openCurrentUrlInBrowser(boolean forceReparenting) { if (getActivityTab() == null) return false; String url = getTabModelSelector().getCurrentTab().getUrl(); @@ -769,12 +770,13 @@ public class CustomTabActivity extends ChromeActivity { StrictMode.setThreadPolicy(oldPolicy); } - if (willChromeHandleIntent) { + if (willChromeHandleIntent || forceReparenting) { intent.setPackage(getPackageName()); boolean enableTabReparenting = ChromeVersionInfo.isLocalBuild() || ChromeVersionInfo.isCanaryBuild() || ChromeVersionInfo.isDevBuild() - || FieldTrialList.findFullName("TabReparenting").startsWith("Enabled"); + || FieldTrialList.findFullName("TabReparenting").startsWith("Enabled") + || forceReparenting; if (enableTabReparenting) { // Take the activity tab and set it aside for reparenting. final Tab tab = getActivityTab(); diff --git a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java index e3a8cc4..83f4267 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/tabmodel/TabPersistentStore.java @@ -233,7 +233,15 @@ public class TabPersistentStore extends TabPersister { */ public static File getStateDirectory(Context context, int index) { File file = new File(getBaseStateDirectory(context), Integer.toString(index)); - if (!file.exists() && !file.mkdirs()) Log.e(TAG, "Failed to create state folder: " + file); + StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); + StrictMode.allowThreadDiskWrites(); + try { + if (!file.exists() && !file.mkdirs()) { + Log.e(TAG, "Failed to create state folder: " + file); + } + } finally { + StrictMode.setThreadPolicy(oldPolicy); + } return file; } diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java index 894e832..50e1226 100644 --- a/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabActivityTest.java @@ -10,6 +10,7 @@ import android.app.Activity; import android.app.Application; import android.app.Instrumentation; import android.app.Instrumentation.ActivityMonitor; +import android.app.Instrumentation.ActivityResult; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; @@ -44,6 +45,7 @@ import org.chromium.base.library_loader.LibraryProcessType; import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.Restriction; import org.chromium.chrome.R; +import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeSwitches; import org.chromium.chrome.browser.ChromeTabbedActivity; import org.chromium.chrome.browser.IntentHandler; @@ -59,6 +61,7 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector; import org.chromium.chrome.browser.toolbar.CustomTabToolbar; import org.chromium.chrome.browser.util.ColorUtils; import org.chromium.chrome.test.util.ChromeRestriction; +import org.chromium.chrome.test.util.browser.LocationSettingsTestUtil; import org.chromium.chrome.test.util.browser.contextmenu.ContextMenuUtils; import org.chromium.content.browser.BrowserStartupController; import org.chromium.content.browser.BrowserStartupController.StartupCallback; @@ -104,6 +107,9 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { TEST_ACTION = "org.chromium.chrome.browser.customtabs.TEST_PENDING_INTENT_SENT"; private static final String TEST_PAGE = "/chrome/test/data/android/google.html"; private static final String TEST_PAGE_2 = "/chrome/test/data/android/test.html"; + private static final String GEOLOCATION_PAGE = + "/chrome/test/data/geolocation/geolocation_on_load.html"; + private static final String SELECT_POPUP_PAGE = "/chrome/test/data/android/select.html"; private static final String FRAGMENT_TEST_PAGE = "/chrome/test/data/android/fragment.html"; private static final String TEST_MENU_TITLE = "testMenuTitle"; private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome"; @@ -432,6 +438,86 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { } /** + * Test whether a custom tab can be reparented to a new activity. + */ + @SmallTest + public void testTabReparentingBasic() throws InterruptedException { + startCustomTabActivityWithIntent(createMinimalCustomTabIntent()); + reparentAndVerifyTab(); + } + + /** + * Test whether a custom tab can be reparented to a new activity while showing an infobar. + */ + @SmallTest + public void testTabReparentingInfoBar() throws InterruptedException { + LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); + startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent( + getInstrumentation().getTargetContext(), + mTestServer.getURL(GEOLOCATION_PAGE), null)); + CriteriaHelper.pollUiThread(new Criteria() { + @Override + public boolean isSatisfied() { + Tab currentTab = getActivity().getActivityTab(); + return currentTab != null + && currentTab.getInfoBarContainer() != null + && currentTab.getInfoBarContainer().getInfoBarsForTesting().size() == 1; + } + }); + final ChromeActivity newActivity = reparentAndVerifyTab(); + CriteriaHelper.pollUiThread(new Criteria() { + @Override + public boolean isSatisfied() { + Tab currentTab = newActivity.getActivityTab(); + return currentTab != null + && currentTab.getInfoBarContainer() != null + && currentTab.getInfoBarContainer().getInfoBarsForTesting().size() == 1; + } + }); + } + + /** + * Test whether a custom tab can be reparented to a new activity while showing a select popup. + */ + @SmallTest + public void testTabReparentingSelectPopup() throws InterruptedException { + LocationSettingsTestUtil.setSystemLocationSettingEnabled(true); + startCustomTabActivityWithIntent(CustomTabsTestUtils.createMinimalCustomTabIntent( + getInstrumentation().getTargetContext(), + mTestServer.getURL(SELECT_POPUP_PAGE), null)); + CriteriaHelper.pollUiThread(new Criteria() { + @Override + public boolean isSatisfied() { + Tab currentTab = getActivity().getActivityTab(); + return currentTab != null + && currentTab.getContentViewCore() != null; + } + }); + try { + DOMUtils.clickNode(CustomTabActivityTest.this, + getActivity().getActivityTab().getContentViewCore(), "select"); + } catch (TimeoutException e) { + fail(); + } + CriteriaHelper.pollUiThread(new Criteria() { + @Override + public boolean isSatisfied() { + return getActivity().getActivityTab().getContentViewCore().getSelectPopupForTest() + != null; + } + }); + final ChromeActivity newActivity = reparentAndVerifyTab(); + CriteriaHelper.pollUiThread(new Criteria() { + @Override + public boolean isSatisfied() { + Tab currentTab = newActivity.getActivityTab(); + return currentTab != null + && currentTab.getContentViewCore() != null + && currentTab.getContentViewCore().getSelectPopupForTest() == null; + } + }); + } + /** * Test whether the color of the toolbar is correctly customized. For L or later releases, * status bar color is also tested. */ @@ -1039,6 +1125,46 @@ public class CustomTabActivityTest extends CustomTabActivityTestBase { return connection; } + private ChromeActivity reparentAndVerifyTab() throws InterruptedException { + ActivityResult result = null; + final ActivityMonitor monitor = getInstrumentation().addMonitor( + ChromeTabbedActivity.class.getName(), result, false); + final Tab tabToBeReparented = mActivity.getActivityTab(); + ThreadUtils.postOnUiThread(new Runnable() { + @Override + public void run() { + mActivity.openCurrentUrlInBrowser(true); + assertNull(mActivity.getActivityTab()); + } + }); + CriteriaHelper.pollInstrumentationThread(new Criteria() { + @Override + public boolean isSatisfied() { + return getInstrumentation().checkMonitorHit(monitor, 1); + } + }); + assertTrue(monitor.getLastActivity() instanceof ChromeActivity); + final ChromeActivity newActivity = (ChromeActivity) monitor.getLastActivity(); + CriteriaHelper.pollUiThread((new Criteria() { + @Override + public boolean isSatisfied() { + return newActivity.getActivityTab() != null + && newActivity.getActivityTab().equals(tabToBeReparented); + } + })); + CriteriaHelper.pollUiThread((new Criteria() { + @Override + public boolean isSatisfied() { + return mActivity.isActivityDestroyed(); + } + })); + assertEquals(newActivity.getWindowAndroid(), tabToBeReparented.getWindowAndroid()); + assertEquals(newActivity.getWindowAndroid(), + tabToBeReparented.getContentViewCore().getWindowAndroid()); + assertFalse(tabToBeReparented.getDelegateFactory() instanceof CustomTabDelegateFactory); + return newActivity; + } + private IBinder warmUpAndLaunchUrlWithSession(ICustomTabsCallback cb) throws InterruptedException { CustomTabsConnection connection = warmUpAndWait(); diff --git a/chrome/test/data/android/select.html b/chrome/test/data/android/select.html new file mode 100644 index 0000000..a69d749 --- /dev/null +++ b/chrome/test/data/android/select.html @@ -0,0 +1,20 @@ +<html> + +<head> +<title>The Google</title> +<meta name="viewport" content="width=device-width, initial-scale=0.5, maximum-scale=0.5" /> +</head> + +<body> + +Which animal is the strongest:<br/> +<select id="select"> + <option>Black bear</option> + <option>Polar bear</option> + <option>Grizzly</option> + <option>Tiger</option> + <option>Lion</option>" +</select> +</body> + +</html> |
