| 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 209bb2eaa9f3910b649ed92533a61721a7024069..b69e51ce59e6186bf502d1cdc6a327b0d1296c78 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,25 +10,14 @@
|
| 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.ChromeActivityTestRule;
|
| -import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| +import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| import org.chromium.chrome.test.util.browser.signin.SigninTestUtil;
|
| import org.chromium.components.webrestrictions.browser.WebRestrictionsContentProvider;
|
|
|
| @@ -38,36 +27,24 @@
|
| /**
|
| * Instrumentation test for SupervisedUserContentProvider.
|
| */
|
| -@RunWith(ChromeJUnit4ClassRunner.class)
|
| @RetryOnFailure
|
| -@CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| - ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| -public class SupervisedUserContentProviderTest {
|
| - @Rule
|
| - public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| - new ChromeActivityTestRule<>(ChromeActivity.class);
|
| -
|
| +public class SupervisedUserContentProviderTest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| 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;
|
|
|
| - @Before
|
| + public SupervisedUserContentProviderTest() {
|
| + super(ChromeActivity.class);
|
| + }
|
| +
|
| + @Override
|
| public void setUp() throws Exception {
|
| - 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;
|
| + super.setUp();
|
| + mResolver = getInstrumentation().getTargetContext().getContentResolver();
|
| + assertNotNull(mResolver);
|
| + mAuthority = getInstrumentation().getTargetContext().getPackageName() + AUTHORITY_SUFFIX;
|
| mUri = new Uri.Builder()
|
| .scheme(ContentResolver.SCHEME_CONTENT)
|
| .authority(mAuthority)
|
| @@ -76,25 +53,34 @@
|
| SigninTestUtil.resetSigninState();
|
| }
|
|
|
| - @After
|
| + @Override
|
| public void tearDown() throws Exception {
|
| SigninTestUtil.resetSigninState();
|
| SigninTestUtil.tearDownAuthForTest();
|
| + super.tearDown();
|
| }
|
|
|
| - @Test
|
| + @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();
|
| + }
|
| +
|
| @SmallTest
|
| public void testSupervisedUserDisabled() throws RemoteException, ExecutionException {
|
| ContentProviderClient client = mResolver.acquireContentProviderClient(mAuthority);
|
| - Assert.assertNotNull(client);
|
| + assertNotNull(client);
|
| Cursor cursor = client.query(mUri, null, "url = 'http://google.com'", null, null);
|
| - Assert.assertNull(cursor);
|
| + assertNull(cursor);
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| public void testNoSupervisedUser() throws RemoteException, ExecutionException {
|
| - Assert.assertFalse(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
|
| + assertFalse(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
|
|
|
| @Override
|
| public Boolean call() throws Exception {
|
| @@ -104,22 +90,21 @@
|
|
|
| }));
|
| ContentProviderClient client = mResolver.acquireContentProviderClient(mAuthority);
|
| - Assert.assertNotNull(client);
|
| + assertNotNull(client);
|
| SupervisedUserContentProvider.enableContentProviderForTesting();
|
| Cursor cursor = client.query(mUri, null, "url = 'http://google.com'", null, null);
|
| - Assert.assertNotNull(cursor);
|
| - Assert.assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
|
| + assertNotNull(cursor);
|
| + assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
|
| cursor = client.query(mUri, null, "url = 'http://www.notgoogle.com'", null, null);
|
| - Assert.assertNotNull(cursor);
|
| - Assert.assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
|
| + assertNotNull(cursor);
|
| + assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
|
| }
|
|
|
| - @Test
|
| @SmallTest
|
| public void testWithSupervisedUser() throws RemoteException, ExecutionException {
|
| final Account account = SigninTestUtil.addAndSignInTestAccount();
|
| - Assert.assertNotNull(account);
|
| - Assert.assertTrue(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
|
| + assertNotNull(account);
|
| + assertTrue(ThreadUtils.runOnUiThreadBlocking(new Callable<Boolean>() {
|
|
|
| @Override
|
| public Boolean call() throws Exception {
|
| @@ -129,12 +114,12 @@
|
|
|
| }));
|
| ContentProviderClient client = mResolver.acquireContentProviderClient(mAuthority);
|
| - Assert.assertNotNull(client);
|
| + 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);
|
| - Assert.assertNotNull(cursor);
|
| - Assert.assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
|
| + assertNotNull(cursor);
|
| + assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getInt(0));
|
| }
|
| }
|
|
|