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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java

Issue 2831823003: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: rebase and convert newly added test Created 3 years, 8 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
Index: chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java
index b69e51ce59e6186bf502d1cdc6a327b0d1296c78..209bb2eaa9f3910b649ed92533a61721a7024069 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/superviseduser/SupervisedUserContentProviderTest.java
@@ -10,14 +10,25 @@ import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.os.RemoteException;
+import android.support.test.InstrumentationRegistry;
import android.support.test.filters.SmallTest;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
import org.chromium.base.ThreadUtils;
+import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.chrome.browser.ChromeActivity;
+import org.chromium.chrome.browser.ChromeSwitches;
import org.chromium.chrome.browser.childaccounts.ChildAccountService;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
-import org.chromium.chrome.test.ChromeActivityTestCaseBase;
+import org.chromium.chrome.test.ChromeActivityTestRule;
+import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
import org.chromium.chrome.test.util.browser.signin.SigninTestUtil;
import org.chromium.components.webrestrictions.browser.WebRestrictionsContentProvider;
@@ -27,24 +38,36 @@ import java.util.concurrent.ExecutionException;
/**
* Instrumentation test for SupervisedUserContentProvider.
*/
+@RunWith(ChromeJUnit4ClassRunner.class)
@RetryOnFailure
-public class SupervisedUserContentProviderTest extends ChromeActivityTestCaseBase<ChromeActivity> {
+@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
+ ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
+public class SupervisedUserContentProviderTest {
+ @Rule
+ public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
+ new ChromeActivityTestRule<>(ChromeActivity.class);
+
private static final String DEFAULT_ACCOUNT = "test@gmail.com";
private static final String AUTHORITY_SUFFIX = ".SupervisedUserProvider";
private ContentResolver mResolver;
private String mAuthority;
private Uri mUri;
- public SupervisedUserContentProviderTest() {
- super(ChromeActivity.class);
- }
-
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
- mResolver = getInstrumentation().getTargetContext().getContentResolver();
- assertNotNull(mResolver);
- mAuthority = getInstrumentation().getTargetContext().getPackageName() + AUTHORITY_SUFFIX;
+ SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentation());
+
+ // In principle the SupervisedUserContentProvider should work whenever Chrome is installed
+ // (even if it isn't running), but to test it we need to set up a dummy child, and to do
+ // this within a test we need to start Chrome.
+ mActivityTestRule.startMainActivityOnBlankPage();
+ mResolver = InstrumentationRegistry.getInstrumentation()
+ .getTargetContext()
+ .getContentResolver();
+ Assert.assertNotNull(mResolver);
+ mAuthority =
+ InstrumentationRegistry.getInstrumentation().getTargetContext().getPackageName()
+ + AUTHORITY_SUFFIX;
mUri = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(mAuthority)
@@ -53,34 +76,25 @@ public class SupervisedUserContentProviderTest extends ChromeActivityTestCaseBas
SigninTestUtil.resetSigninState();
}
- @Override
+ @After
public void tearDown() throws Exception {
SigninTestUtil.resetSigninState();
SigninTestUtil.tearDownAuthForTest();
- super.tearDown();
- }
-
- @Override
- public void startMainActivity() throws InterruptedException {
- SigninTestUtil.setUpAuthForTest(getInstrumentation());
-
- // In principle the SupervisedUserContentProvider should work whenever Chrome is installed
- // (even if it isn't running), but to test it we need to set up a dummy child, and to do
- // this within a test we need to start Chrome.
- startMainActivityOnBlankPage();
}
+ @Test
@SmallTest
public void testSupervisedUserDisabled() throws RemoteException, ExecutionException {
ContentProviderClient client = mResolver.acquireContentProviderClient(mAuthority);
- assertNotNull(client);
+ Assert.assertNotNull(client);
Cursor cursor = client.query(mUri, null, "url = 'http://google.com'", null, null);
- assertNull(cursor);
+ Assert.assertNull(cursor);
}
+ @Test
@SmallTest
public void testNoSupervisedUser() throws RemoteException, ExecutionException {
- assertFalse(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
+ Assert.assertFalse(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
@@ -90,21 +104,22 @@ public class SupervisedUserContentProviderTest extends ChromeActivityTestCaseBas
}));
ContentProviderClient client = mResolver.acquireContentProviderClient(mAuthority);
- assertNotNull(client);
+ Assert.assertNotNull(client);
SupervisedUserContentProvider.enableContentProviderForTesting();
Cursor cursor = client.query(mUri, null, "url = 'http://google.com'", null, null);
- assertNotNull(cursor);
- assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
+ Assert.assertNotNull(cursor);
+ Assert.assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
cursor = client.query(mUri, null, "url = 'http://www.notgoogle.com'", null, null);
- assertNotNull(cursor);
- assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
+ Assert.assertNotNull(cursor);
+ Assert.assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
}
+ @Test
@SmallTest
public void testWithSupervisedUser() throws RemoteException, ExecutionException {
final Account account = SigninTestUtil.addAndSignInTestAccount();
- assertNotNull(account);
- assertTrue(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
+ Assert.assertNotNull(account);
+ Assert.assertTrue(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
@@ -114,12 +129,12 @@ public class SupervisedUserContentProviderTest extends ChromeActivityTestCaseBas
}));
ContentProviderClient client = mResolver.acquireContentProviderClient(mAuthority);
- assertNotNull(client);
+ Assert.assertNotNull(client);
SupervisedUserContentProvider.enableContentProviderForTesting();
// setFilter for testing sets a default filter that blocks by default.
mResolver.call(mUri, "setFilterForTesting", null, null);
Cursor cursor = client.query(mUri, null, "url = 'http://www.google.com'", null, null);
- assertNotNull(cursor);
- assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
+ Assert.assertNotNull(cursor);
+ Assert.assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
}
}

Powered by Google App Engine
This is Rietveld 408576698