Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3988)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/browseractions/BrowserActionActivityTest.java

Issue 2984453002: Add Browser Actions tab model selector and open a tab through it if ChromeTabbedActivity is not ava…
Patch Set: Sync changes. Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/browseractions/BrowserActionActivityTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/browseractions/BrowserActionActivityTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/browseractions/BrowserActionActivityTest.java
index 1889808e2e9c5227b880dc0e51eed16606f57ca5..3e20cd06406c32b40b32196e8276aa92180c7bb7 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/browseractions/BrowserActionActivityTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/browseractions/BrowserActionActivityTest.java
@@ -13,6 +13,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
+import android.os.StrictMode;
import android.support.customtabs.browseractions.BrowserActionsIntent;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
@@ -41,11 +42,13 @@ import org.chromium.chrome.browser.firstrun.FirstRunStatus;
import org.chromium.chrome.browser.util.IntentUtils;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
+import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.net.test.EmbeddedTestServer;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.Callable;
/**
* Instrumentation tests for context menu of a {@link BrowserActionActivity}.
@@ -68,6 +71,7 @@ public class BrowserActionActivityTest {
private ProgressDialog mProgressDialog;
private TestDelegate mTestDelegate;
private EmbeddedTestServer mTestServer;
+ private StrictMode.ThreadPolicy mOldPolicy;
private String mTestPage;
private String mTestPage2;
private String mTestPage3;
@@ -121,6 +125,12 @@ public class BrowserActionActivityTest {
mTestPage = mTestServer.getURL(TEST_PAGE);
mTestPage2 = mTestServer.getURL(TEST_PAGE_2);
mTestPage3 = mTestServer.getURL(TEST_PAGE_3);
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ mOldPolicy = StrictMode.allowThreadDiskWrites();
+ }
+ });
}
@After
@@ -132,6 +142,12 @@ public class BrowserActionActivityTest {
}
});
mTestServer.stopAndDestroyServer();
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ StrictMode.setThreadPolicy(mOldPolicy);
+ }
+ });
}
@Test
@@ -200,7 +216,7 @@ public class BrowserActionActivityTest {
mOnFinishNativeInitializationCallback.waitForCallback(0);
Assert.assertEquals(1, mActivityTestRule.getActivity().getCurrentTabModel().getCount());
// No notification should be shown.
- Assert.assertFalse(mMenuItemDelegate.hasBrowserActionsNotification());
+ Assert.assertFalse(BrowserActionsService.hasBrowserActionsNotification());
// Open a tab in the background.
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@@ -212,7 +228,12 @@ public class BrowserActionActivityTest {
});
// Notification for single tab should be shown.
- Assert.assertTrue(mMenuItemDelegate.hasBrowserActionsNotification());
+ CriteriaHelper.pollUiThread(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return BrowserActionsService.hasBrowserActionsNotification();
+ }
+ });
// Tabs should always be added at the end of the model.
Assert.assertEquals(2, mActivityTestRule.getActivity().getCurrentTabModel().getCount());
Assert.assertEquals(mTestPage,
@@ -222,7 +243,7 @@ public class BrowserActionActivityTest {
int prevTabId = mActivityTestRule.getActivity().getCurrentTabModel().getTabAt(0).getId();
int newTabId = mActivityTestRule.getActivity().getCurrentTabModel().getTabAt(1).getId();
// TODO(ltian): overwrite delegate prevent creating notifcation for test.
- Intent notificationIntent = mMenuItemDelegate.getNotificationIntent();
+ Intent notificationIntent = BrowserActionsService.getNotificationIntent();
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Force ChromeTabbedActivity dismissed to make sure it calls onStop then calls onStart next
@@ -240,7 +261,8 @@ public class BrowserActionActivityTest {
@Test
@SmallTest
- public void testOpenMulitpleTabInBackgroundWhenChromeAvailable() throws Exception {
+ public void testOpenMulitpleTabsInBackgroundWhenChromeAvailable() throws Exception {
+ Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
// Start ChromeTabbedActivity first.
mActivityTestRule.startMainActivityWithURL(mTestPage);
@@ -263,7 +285,12 @@ public class BrowserActionActivityTest {
Assert.assertEquals(2, mActivityTestRule.getActivity().getCurrentTabModel().getCount());
// Notification for multiple tabs should be shown.
- Assert.assertTrue(mMenuItemDelegate.hasBrowserActionsNotification());
+ CriteriaHelper.pollUiThread(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return BrowserActionsService.hasBrowserActionsNotification();
+ }
+ });
ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override
public void run() {
@@ -280,7 +307,7 @@ public class BrowserActionActivityTest {
mActivityTestRule.getActivity().getCurrentTabModel().getTabAt(1).getUrl());
Assert.assertEquals(mTestPage3,
mActivityTestRule.getActivity().getCurrentTabModel().getTabAt(2).getUrl());
- Intent notificationIntent = mMenuItemDelegate.getNotificationIntent();
+ Intent notificationIntent = BrowserActionsService.getNotificationIntent();
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Force ChromeTabbedActivity dismissed to make sure it calls onStop then calls onStart next
@@ -294,6 +321,106 @@ public class BrowserActionActivityTest {
Assert.assertTrue(mActivityTestRule.getActivity().getLayoutManager().overviewVisible());
}
+ @Test
+ @SmallTest
+ public void testOpenSingleTabInBackgroundWhenChromeNotAvailable() throws Exception {
+ // Load Browser Actions menu completely.
+ final BrowserActionActivity activity = startBrowserActionActivity(mTestPage);
+ mOnBrowserActionsMenuShownCallback.waitForCallback(0);
+ mOnFinishNativeInitializationCallback.waitForCallback(0);
+ // No notification should be shown.
+ Assert.assertFalse(BrowserActionsService.hasBrowserActionsNotification());
+
+ final BrowserActionsTabCreatorManager manager = mMenuItemDelegate.getTabCreatorManager();
+ final BrowserActionsTabModelSelector selector =
+ ThreadUtils.runOnUiThreadBlocking(new Callable<BrowserActionsTabModelSelector>() {
+ @Override
+ public BrowserActionsTabModelSelector call() {
+ return BrowserActionsTabModelSelector.getInstance(activity, manager);
+ }
+ });
+ Assert.assertFalse(selector.isActiveState());
+ // Open a tab in the background.
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ activity.getHelperForTesting().onItemSelected(
+ R.id.browser_actions_open_in_background);
+ }
+ });
+
+ // Notification for single tab should be shown.
+ CriteriaHelper.pollUiThread(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return BrowserActionsService.hasBrowserActionsNotification();
+ }
+ });
+ // New tab should be added to the BrowserActionTabModelSelector.
+ Assert.assertEquals(1, selector.getCurrentModel().getCount());
+ CriteriaHelper.pollUiThread(Criteria.equals(mTestPage, new Callable<String>() {
+ @Override
+ public String call() {
+ return selector.getCurrentModel().getTabAt(0).getUrl();
+ }
+ }));
+ }
+
+ @Test
+ @SmallTest
+ public void testOpenMultipleTabsInBackgroundWhenChromeNotAvailable() throws Exception {
+ // Load Browser Actions menu completely and open a tab in the background.
+ final BrowserActionActivity activity1 = startBrowserActionActivity(mTestPage);
+ mOnBrowserActionsMenuShownCallback.waitForCallback(0);
+ mOnFinishNativeInitializationCallback.waitForCallback(0);
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ activity1.getHelperForTesting().onItemSelected(
+ R.id.browser_actions_open_in_background);
+ }
+ });
+
+ // Load Browser Actions menu again and open another tab in the background.
+ final BrowserActionActivity activity2 = startBrowserActionActivity(mTestPage2, 1);
+ mOnBrowserActionsMenuShownCallback.waitForCallback(1);
+ mOnFinishNativeInitializationCallback.waitForCallback(1);
+ // Notification should already be shown.
+ Assert.assertTrue(BrowserActionsService.hasBrowserActionsNotification());
+ final BrowserActionsTabCreatorManager manager = mMenuItemDelegate.getTabCreatorManager();
+ final BrowserActionsTabModelSelector selector =
+ ThreadUtils.runOnUiThreadBlocking(new Callable<BrowserActionsTabModelSelector>() {
+ @Override
+ public BrowserActionsTabModelSelector call() {
+ return BrowserActionsTabModelSelector.getInstance(activity2, manager);
+ }
+ });
+ // BrowserActionsTabModelSelector should already been initialized and have one tab.
+ Assert.assertTrue(selector.isActiveState());
+ Assert.assertEquals(1, selector.getCurrentModel().getCount());
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() {
+ @Override
+ public void run() {
+ activity2.getHelperForTesting().onItemSelected(
+ R.id.browser_actions_open_in_background);
+ }
+ });
+ // BrowserActionTabModelSelector should have two tabs and tabs should be added sequentially.
+ Assert.assertEquals(2, selector.getCurrentModel().getCount());
+ CriteriaHelper.pollUiThread(Criteria.equals(mTestPage, new Callable<String>() {
+ @Override
+ public String call() {
+ return selector.getCurrentModel().getTabAt(0).getUrl();
+ }
+ }));
+ CriteriaHelper.pollUiThread(Criteria.equals(mTestPage2, new Callable<String>() {
+ @Override
+ public String call() {
+ return selector.getCurrentModel().getTabAt(1).getUrl();
+ }
+ }));
+ }
+
private BrowserActionActivity startBrowserActionActivity(String url) throws Exception {
return startBrowserActionActivity(url, 0);
}
« no previous file with comments | « chrome/android/java_sources.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698