| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser.superviseduser; | 5 package org.chromium.chrome.browser.superviseduser; |
| 6 | 6 |
| 7 import android.accounts.Account; | 7 import android.accounts.Account; |
| 8 import android.content.ContentProviderClient; | 8 import android.content.ContentProviderClient; |
| 9 import android.content.ContentResolver; | 9 import android.content.ContentResolver; |
| 10 import android.database.Cursor; | 10 import android.database.Cursor; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 new ChromeActivityTestRule<>(ChromeActivity.class); | 48 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 49 | 49 |
| 50 private static final String DEFAULT_ACCOUNT = "test@gmail.com"; | 50 private static final String DEFAULT_ACCOUNT = "test@gmail.com"; |
| 51 private static final String AUTHORITY_SUFFIX = ".SupervisedUserProvider"; | 51 private static final String AUTHORITY_SUFFIX = ".SupervisedUserProvider"; |
| 52 private ContentResolver mResolver; | 52 private ContentResolver mResolver; |
| 53 private String mAuthority; | 53 private String mAuthority; |
| 54 private Uri mUri; | 54 private Uri mUri; |
| 55 | 55 |
| 56 @Before | 56 @Before |
| 57 public void setUp() throws Exception { | 57 public void setUp() throws Exception { |
| 58 SigninTestUtil.setUpAuthForTest(InstrumentationRegistry.getInstrumentati
on()); | 58 SigninTestUtil.setUpAuthForTest(); |
| 59 | 59 |
| 60 // In principle the SupervisedUserContentProvider should work whenever C
hrome is installed | 60 // In principle the SupervisedUserContentProvider should work whenever C
hrome is installed |
| 61 // (even if it isn't running), but to test it we need to set up a dummy
child, and to do | 61 // (even if it isn't running), but to test it we need to set up a dummy
child, and to do |
| 62 // this within a test we need to start Chrome. | 62 // this within a test we need to start Chrome. |
| 63 mActivityTestRule.startMainActivityOnBlankPage(); | 63 mActivityTestRule.startMainActivityOnBlankPage(); |
| 64 mResolver = InstrumentationRegistry.getInstrumentation() | 64 mResolver = InstrumentationRegistry.getInstrumentation() |
| 65 .getTargetContext() | 65 .getTargetContext() |
| 66 .getContentResolver(); | 66 .getContentResolver(); |
| 67 Assert.assertNotNull(mResolver); | 67 Assert.assertNotNull(mResolver); |
| 68 mAuthority = | 68 mAuthority = |
| 69 InstrumentationRegistry.getInstrumentation().getTargetContext().
getPackageName() | 69 InstrumentationRegistry.getInstrumentation().getTargetContext().
getPackageName() |
| 70 + AUTHORITY_SUFFIX; | 70 + AUTHORITY_SUFFIX; |
| 71 mUri = new Uri.Builder() | 71 mUri = new Uri.Builder() |
| 72 .scheme(ContentResolver.SCHEME_CONTENT) | 72 .scheme(ContentResolver.SCHEME_CONTENT) |
| 73 .authority(mAuthority) | 73 .authority(mAuthority) |
| 74 .path("authorized") | 74 .path("authorized") |
| 75 .build(); | 75 .build(); |
| 76 SigninTestUtil.resetSigninState(); | 76 SigninTestUtil.resetSigninState(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 @After | 79 @After |
| 80 public void tearDown() throws Exception { | 80 public void tearDown() throws Exception { |
| 81 SigninTestUtil.resetSigninState(); | 81 SigninTestUtil.resetSigninState(); |
| 82 SigninTestUtil.tearDownAuthForTest(); | |
| 83 } | 82 } |
| 84 | 83 |
| 85 @Test | 84 @Test |
| 86 @SmallTest | 85 @SmallTest |
| 87 public void testSupervisedUserDisabled() throws RemoteException, ExecutionEx
ception { | 86 public void testSupervisedUserDisabled() throws RemoteException, ExecutionEx
ception { |
| 88 ContentProviderClient client = mResolver.acquireContentProviderClient(mA
uthority); | 87 ContentProviderClient client = mResolver.acquireContentProviderClient(mA
uthority); |
| 89 Assert.assertNotNull(client); | 88 Assert.assertNotNull(client); |
| 90 Cursor cursor = client.query(mUri, null, "url = 'http://google.com'", nu
ll, null); | 89 Cursor cursor = client.query(mUri, null, "url = 'http://google.com'", nu
ll, null); |
| 91 Assert.assertNull(cursor); | 90 Assert.assertNull(cursor); |
| 92 } | 91 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 ContentProviderClient client = mResolver.acquireContentProviderClient(mA
uthority); | 130 ContentProviderClient client = mResolver.acquireContentProviderClient(mA
uthority); |
| 132 Assert.assertNotNull(client); | 131 Assert.assertNotNull(client); |
| 133 SupervisedUserContentProvider.enableContentProviderForTesting(); | 132 SupervisedUserContentProvider.enableContentProviderForTesting(); |
| 134 // setFilter for testing sets a default filter that blocks by default. | 133 // setFilter for testing sets a default filter that blocks by default. |
| 135 mResolver.call(mUri, "setFilterForTesting", null, null); | 134 mResolver.call(mUri, "setFilterForTesting", null, null); |
| 136 Cursor cursor = client.query(mUri, null, "url = 'http://www.google.com'"
, null, null); | 135 Cursor cursor = client.query(mUri, null, "url = 'http://www.google.com'"
, null, null); |
| 137 Assert.assertNotNull(cursor); | 136 Assert.assertNotNull(cursor); |
| 138 Assert.assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getIn
t(0)); | 137 Assert.assertEquals(WebRestrictionsContentProvider.BLOCKED, cursor.getIn
t(0)); |
| 139 } | 138 } |
| 140 } | 139 } |
| OLD | NEW |