Commit ae366fd6 authored by John Mellor's avatar John Mellor Committed by Commit Bot

Revert "Convert TabsTests and IncognitoNotificationServiceTest to JUnit4"

This reverts commit 793d799b.

Reason for revert - made TabsTest very flaky on the following bots:
https://build.chromium.org/p/chromium.android/builders/Lollipop%20Phone%20Tester/builds/15045
https://build.chromium.org/p/chromium.linux/builders/Android%20Tests%20(dbg)/builds/45549

Original change's description:
> Convert TabsTests and IncognitoNotificationServiceTest to JUnit4
> 
> For more on JUnit4 migration, please check src/testing/android/docs/junit4.md
> 
> Bug: 640116
> Change-Id: I508ee1b6512a4a96175d1747a0f8ebe1764f11e6
> Reviewed-on: https://chromium-review.googlesource.com/662241
> Commit-Queue: Yoland Yan <yolandyan@chromium.org>
> Reviewed-by: Ted Choc <tedchoc@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#501446}

TBR=tedchoc@chromium.org,yolandyan@chromium.org

Change-Id: I86ba1b7776b734a9150a09a3b6994c46732ac1e4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 640116
Reviewed-on: https://chromium-review.googlesource.com/664717Reviewed-by: default avatarJohn Mellor <johnme@chromium.org>
Commit-Queue: John Mellor <johnme@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501593}
parent e095db10
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -7,30 +7,20 @@ package org.chromium.chrome.browser.incognito; ...@@ -7,30 +7,20 @@ package org.chromium.chrome.browser.incognito;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException; import android.app.PendingIntent.CanceledException;
import android.content.Context; import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.util.Pair; import android.util.Pair;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.library_loader.LibraryLoader; import org.chromium.base.library_loader.LibraryLoader;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.TabState; import org.chromium.chrome.browser.TabState;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
import org.chromium.chrome.browser.tabmodel.TabPersistentStore; import org.chromium.chrome.browser.tabmodel.TabPersistentStore;
import org.chromium.chrome.browser.tabmodel.TestTabModelDirectory; import org.chromium.chrome.browser.tabmodel.TestTabModelDirectory;
import org.chromium.chrome.browser.tabmodel.TestTabModelDirectory.TabStateInfo; import org.chromium.chrome.browser.tabmodel.TestTabModelDirectory.TabStateInfo;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
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.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper; import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
...@@ -41,37 +31,36 @@ import java.util.concurrent.Callable; ...@@ -41,37 +31,36 @@ import java.util.concurrent.Callable;
/** /**
* Tests for the Incognito Notification service. * Tests for the Incognito Notification service.
*/ */
@RunWith(ChromeJUnit4ClassRunner.class) public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBase {
@CommandLineFlags.Add({
ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, @Override
ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG, public void startMainActivity() throws InterruptedException {
}) // Each test will start its own activity as needed.
public class IncognitoNotificationServiceTest { }
@Rule
public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
private void createTabOnUiThread() { private void createTabOnUiThread() {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
mActivityTestRule.getActivity().getTabCreator(true).createNewTab( getActivity().getTabCreator(true).createNewTab(new LoadUrlParams("about:blank"),
new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHROME_UI, null); TabLaunchType.FROM_CHROME_UI, null);
} }
}); });
} }
private void sendClearIncognitoIntent() throws CanceledException { private void sendClearIncognitoIntent() throws CanceledException {
PendingIntent clearIntent = IncognitoNotificationService.getRemoveAllIncognitoTabsIntent( PendingIntent clearIntent =
InstrumentationRegistry.getTargetContext()); IncognitoNotificationService.getRemoveAllIncognitoTabsIntent(
getInstrumentation().getTargetContext());
clearIntent.send(); clearIntent.send();
} }
@Test
@Feature("Incognito") @Feature("Incognito")
@MediumTest @MediumTest
public void testSingleRunningChromeTabbedActivity() public void testSingleRunningChromeTabbedActivity()
throws InterruptedException, CanceledException { throws InterruptedException, CanceledException {
mActivityTestRule.startMainActivityOnBlankPage(); startMainActivityOnBlankPage();
createTabOnUiThread(); createTabOnUiThread();
createTabOnUiThread(); createTabOnUiThread();
...@@ -79,10 +68,7 @@ public class IncognitoNotificationServiceTest { ...@@ -79,10 +68,7 @@ public class IncognitoNotificationServiceTest {
CriteriaHelper.pollUiThread(Criteria.equals(2, new Callable<Integer>() { CriteriaHelper.pollUiThread(Criteria.equals(2, new Callable<Integer>() {
@Override @Override
public Integer call() throws Exception { public Integer call() throws Exception {
return mActivityTestRule.getActivity() return getActivity().getTabModelSelector().getModel(true).getCount();
.getTabModelSelector()
.getModel(true)
.getCount();
} }
})); }));
...@@ -90,17 +76,14 @@ public class IncognitoNotificationServiceTest { ...@@ -90,17 +76,14 @@ public class IncognitoNotificationServiceTest {
new Callable<Profile>() { new Callable<Profile>() {
@Override @Override
public Profile call() throws Exception { public Profile call() throws Exception {
return mActivityTestRule.getActivity() return getActivity().getTabModelSelector().getModel(true).getProfile();
.getTabModelSelector()
.getModel(true)
.getProfile();
} }
}); });
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
Assert.assertTrue(incognitoProfile.isOffTheRecord()); assertTrue(incognitoProfile.isOffTheRecord());
Assert.assertTrue(incognitoProfile.isNativeInitialized()); assertTrue(incognitoProfile.isNativeInitialized());
} }
}); });
...@@ -109,10 +92,7 @@ public class IncognitoNotificationServiceTest { ...@@ -109,10 +92,7 @@ public class IncognitoNotificationServiceTest {
CriteriaHelper.pollUiThread(Criteria.equals(0, new Callable<Integer>() { CriteriaHelper.pollUiThread(Criteria.equals(0, new Callable<Integer>() {
@Override @Override
public Integer call() throws Exception { public Integer call() throws Exception {
return mActivityTestRule.getActivity() return getActivity().getTabModelSelector().getModel(true).getCount();
.getTabModelSelector()
.getModel(true)
.getCount();
} }
})); }));
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
...@@ -123,12 +103,11 @@ public class IncognitoNotificationServiceTest { ...@@ -123,12 +103,11 @@ public class IncognitoNotificationServiceTest {
}); });
} }
@Test
@Feature("Incognito") @Feature("Incognito")
@MediumTest @MediumTest
@RetryOnFailure @RetryOnFailure
public void testNoAliveProcess() throws Exception { public void testNoAliveProcess() throws Exception {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext(); Context context = getInstrumentation().getTargetContext();
final TestTabModelDirectory tabbedModeDirectory = new TestTabModelDirectory( final TestTabModelDirectory tabbedModeDirectory = new TestTabModelDirectory(
context, "tabs", String.valueOf(0)); context, "tabs", String.valueOf(0));
...@@ -153,8 +132,8 @@ public class IncognitoNotificationServiceTest { ...@@ -153,8 +132,8 @@ public class IncognitoNotificationServiceTest {
TabPersistentStore.setBaseStateDirectoryForTests(tabbedModeDirectory.getBaseDirectory()); TabPersistentStore.setBaseStateDirectoryForTests(tabbedModeDirectory.getBaseDirectory());
File[] tabbedModeFiles = tabbedModeDirectory.getDataDirectory().listFiles(); File[] tabbedModeFiles = tabbedModeDirectory.getDataDirectory().listFiles();
Assert.assertNotNull(tabbedModeFiles); assertNotNull(tabbedModeFiles);
Assert.assertEquals(5, tabbedModeFiles.length); assertEquals(5, tabbedModeFiles.length);
int incognitoCount = 0; int incognitoCount = 0;
int normalCount = 0; int normalCount = 0;
...@@ -164,8 +143,8 @@ public class IncognitoNotificationServiceTest { ...@@ -164,8 +143,8 @@ public class IncognitoNotificationServiceTest {
if (tabFileInfo.second) incognitoCount++; if (tabFileInfo.second) incognitoCount++;
else normalCount++; else normalCount++;
} }
Assert.assertEquals(2, normalCount); assertEquals(2, normalCount);
Assert.assertEquals(3, incognitoCount); assertEquals(3, incognitoCount);
sendClearIncognitoIntent(); sendClearIncognitoIntent();
...@@ -202,8 +181,9 @@ public class IncognitoNotificationServiceTest { ...@@ -202,8 +181,9 @@ public class IncognitoNotificationServiceTest {
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
Assert.assertFalse(LibraryLoader.isInitialized()); assertFalse(LibraryLoader.isInitialized());
} }
}); });
} }
} }
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