Commit 793d799b authored by Yoland Yan's avatar Yoland Yan Committed by Commit Bot

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: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501446}
parent 2da59fe3
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -7,20 +7,30 @@ package org.chromium.chrome.browser.incognito; ...@@ -7,20 +7,30 @@ 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.ChromeTabbedActivityTestBase; import org.chromium.chrome.test.ChromeActivityTestRule;
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;
...@@ -31,36 +41,37 @@ import java.util.concurrent.Callable; ...@@ -31,36 +41,37 @@ import java.util.concurrent.Callable;
/** /**
* Tests for the Incognito Notification service. * Tests for the Incognito Notification service.
*/ */
public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBase { @RunWith(ChromeJUnit4ClassRunner.class)
@CommandLineFlags.Add({
@Override ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
public void startMainActivity() throws InterruptedException { ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
// 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() {
getActivity().getTabCreator(true).createNewTab(new LoadUrlParams("about:blank"), mActivityTestRule.getActivity().getTabCreator(true).createNewTab(
TabLaunchType.FROM_CHROME_UI, null); new LoadUrlParams("about:blank"), TabLaunchType.FROM_CHROME_UI, null);
} }
}); });
} }
private void sendClearIncognitoIntent() throws CanceledException { private void sendClearIncognitoIntent() throws CanceledException {
PendingIntent clearIntent = PendingIntent clearIntent = IncognitoNotificationService.getRemoveAllIncognitoTabsIntent(
IncognitoNotificationService.getRemoveAllIncognitoTabsIntent( InstrumentationRegistry.getTargetContext());
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 {
startMainActivityOnBlankPage(); mActivityTestRule.startMainActivityOnBlankPage();
createTabOnUiThread(); createTabOnUiThread();
createTabOnUiThread(); createTabOnUiThread();
...@@ -68,7 +79,10 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa ...@@ -68,7 +79,10 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa
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 getActivity().getTabModelSelector().getModel(true).getCount(); return mActivityTestRule.getActivity()
.getTabModelSelector()
.getModel(true)
.getCount();
} }
})); }));
...@@ -76,14 +90,17 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa ...@@ -76,14 +90,17 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa
new Callable<Profile>() { new Callable<Profile>() {
@Override @Override
public Profile call() throws Exception { public Profile call() throws Exception {
return getActivity().getTabModelSelector().getModel(true).getProfile(); return mActivityTestRule.getActivity()
.getTabModelSelector()
.getModel(true)
.getProfile();
} }
}); });
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
assertTrue(incognitoProfile.isOffTheRecord()); Assert.assertTrue(incognitoProfile.isOffTheRecord());
assertTrue(incognitoProfile.isNativeInitialized()); Assert.assertTrue(incognitoProfile.isNativeInitialized());
} }
}); });
...@@ -92,7 +109,10 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa ...@@ -92,7 +109,10 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa
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 getActivity().getTabModelSelector().getModel(true).getCount(); return mActivityTestRule.getActivity()
.getTabModelSelector()
.getModel(true)
.getCount();
} }
})); }));
CriteriaHelper.pollUiThread(new Criteria() { CriteriaHelper.pollUiThread(new Criteria() {
...@@ -103,11 +123,12 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa ...@@ -103,11 +123,12 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa
}); });
} }
@Test
@Feature("Incognito") @Feature("Incognito")
@MediumTest @MediumTest
@RetryOnFailure @RetryOnFailure
public void testNoAliveProcess() throws Exception { public void testNoAliveProcess() throws Exception {
Context context = getInstrumentation().getTargetContext(); Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
final TestTabModelDirectory tabbedModeDirectory = new TestTabModelDirectory( final TestTabModelDirectory tabbedModeDirectory = new TestTabModelDirectory(
context, "tabs", String.valueOf(0)); context, "tabs", String.valueOf(0));
...@@ -132,8 +153,8 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa ...@@ -132,8 +153,8 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa
TabPersistentStore.setBaseStateDirectoryForTests(tabbedModeDirectory.getBaseDirectory()); TabPersistentStore.setBaseStateDirectoryForTests(tabbedModeDirectory.getBaseDirectory());
File[] tabbedModeFiles = tabbedModeDirectory.getDataDirectory().listFiles(); File[] tabbedModeFiles = tabbedModeDirectory.getDataDirectory().listFiles();
assertNotNull(tabbedModeFiles); Assert.assertNotNull(tabbedModeFiles);
assertEquals(5, tabbedModeFiles.length); Assert.assertEquals(5, tabbedModeFiles.length);
int incognitoCount = 0; int incognitoCount = 0;
int normalCount = 0; int normalCount = 0;
...@@ -143,8 +164,8 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa ...@@ -143,8 +164,8 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa
if (tabFileInfo.second) incognitoCount++; if (tabFileInfo.second) incognitoCount++;
else normalCount++; else normalCount++;
} }
assertEquals(2, normalCount); Assert.assertEquals(2, normalCount);
assertEquals(3, incognitoCount); Assert.assertEquals(3, incognitoCount);
sendClearIncognitoIntent(); sendClearIncognitoIntent();
...@@ -181,9 +202,8 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa ...@@ -181,9 +202,8 @@ public class IncognitoNotificationServiceTest extends ChromeTabbedActivityTestBa
ThreadUtils.runOnUiThreadBlocking(new Runnable() { ThreadUtils.runOnUiThreadBlocking(new Runnable() {
@Override @Override
public void run() { public void run() {
assertFalse(LibraryLoader.isInitialized()); Assert.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