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

Side by Side Diff: components/web_restrictions/browser/junit/src/org/chromium/components/webrestrictions/browser/WebRestrictionsContentProviderTest.java

Issue 2713513004: [Webview, Child Accounts] Always Google Play Services to show the reauthentication page. (Closed)
Patch Set: fix Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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.components.webrestrictions.browser; 5 package org.chromium.components.webrestrictions.browser;
6 6
7 import static org.hamcrest.CoreMatchers.is; 7 import static org.hamcrest.CoreMatchers.is;
8 import static org.hamcrest.CoreMatchers.not; 8 import static org.hamcrest.CoreMatchers.not;
9 import static org.hamcrest.CoreMatchers.nullValue; 9 import static org.hamcrest.CoreMatchers.nullValue;
10 import static org.junit.Assert.assertThat; 10 import static org.junit.Assert.assertThat;
11 import static org.mockito.ArgumentMatchers.anyString; 11 import static org.mockito.ArgumentMatchers.anyString;
12 import static org.mockito.ArgumentMatchers.eq;
12 import static org.mockito.Mockito.verify; 13 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.when; 14 import static org.mockito.Mockito.when;
14 15
15 import android.content.ContentResolver; 16 import android.content.ContentResolver;
16 import android.content.ContentValues; 17 import android.content.ContentValues;
17 import android.content.pm.ProviderInfo; 18 import android.content.pm.ProviderInfo;
18 import android.database.Cursor; 19 import android.database.Cursor;
19 import android.net.Uri; 20 import android.net.Uri;
20 21
21 import org.chromium.components.webrestrictions.browser.WebRestrictionsContentPro vider.WebRestrictionsResult;
22 import org.chromium.testing.local.LocalRobolectricTestRunner;
23 import org.junit.Before; 22 import org.junit.Before;
24 import org.junit.Test; 23 import org.junit.Test;
25 import org.junit.runner.RunWith; 24 import org.junit.runner.RunWith;
25 import org.mockito.ArgumentMatchers;
26 import org.mockito.Mockito; 26 import org.mockito.Mockito;
27 import org.robolectric.RuntimeEnvironment; 27 import org.robolectric.RuntimeEnvironment;
28 import org.robolectric.annotation.Config; 28 import org.robolectric.annotation.Config;
29 import org.robolectric.shadows.ShadowContentResolver; 29 import org.robolectric.shadows.ShadowContentResolver;
30 30
31 import org.chromium.components.webrestrictions.browser.WebRestrictionsContentPro vider.WebRestrictionsResult;
32 import org.chromium.testing.local.LocalRobolectricTestRunner;
33
31 /** 34 /**
32 * Tests of WebRestrictionsContentProvider. 35 * Tests of WebRestrictionsContentProvider.
33 */ 36 */
34 @RunWith(LocalRobolectricTestRunner.class) 37 @RunWith(LocalRobolectricTestRunner.class)
35 @Config(manifest = Config.NONE) 38 @Config(manifest = Config.NONE)
36 public class WebRestrictionsContentProviderTest { 39 public class WebRestrictionsContentProviderTest {
37 private static final String AUTHORITY = "org.chromium.browser.DummyProvider" ; 40 private static final String AUTHORITY = "org.chromium.browser.DummyProvider" ;
38 41
39 private WebRestrictionsContentProvider mContentProvider; 42 private WebRestrictionsContentProvider mContentProvider;
40 private ContentResolver mContentResolver; 43 private ContentResolver mContentResolver;
41 private Uri mUri; 44 private Uri mUri;
42 45
43 @Before 46 @Before
44 public void setUp() { 47 public void setUp() {
45 // The test needs a concrete version of the test class, but mocks the ad ditional members as 48 // The test needs a concrete version of the test class, but mocks the ad ditional members as
46 // necessary. 49 // necessary.
47 mContentProvider = Mockito.spy(new WebRestrictionsContentProvider() { 50 mContentProvider = Mockito.spy(new WebRestrictionsContentProvider() {
48 @Override 51 @Override
49 protected WebRestrictionsResult shouldProceed(String url) { 52 protected WebRestrictionsResult shouldProceed(String callingPackage, String url) {
50 return null; 53 return null;
51 } 54 }
52 55
53 @Override 56 @Override
54 protected boolean canInsert() { 57 protected boolean canInsert() {
55 return false; 58 return false;
56 } 59 }
57 60
58 @Override 61 @Override
59 protected boolean requestInsert(String url) { 62 protected boolean requestInsert(String url) {
(...skipping 25 matching lines...) Expand all
85 @Test 88 @Test
86 public void testQuery() { 89 public void testQuery() {
87 when(mContentProvider.contentProviderEnabled()).thenReturn(false); 90 when(mContentProvider.contentProviderEnabled()).thenReturn(false);
88 assertThat(mContentResolver.query(mUri.buildUpon().appendPath("authorize d").build(), null, 91 assertThat(mContentResolver.query(mUri.buildUpon().appendPath("authorize d").build(), null,
89 "url = 'dummy'", null, null), 92 "url = 'dummy'", null, null),
90 is(nullValue())); 93 is(nullValue()));
91 when(mContentProvider.contentProviderEnabled()).thenReturn(true); 94 when(mContentProvider.contentProviderEnabled()).thenReturn(true);
92 int errorInt[] = {42}; 95 int errorInt[] = {42};
93 String errorString[] = {"Error Message"}; 96 String errorString[] = {"Error Message"};
94 WebRestrictionsResult result = new WebRestrictionsResult(false, errorInt , errorString); 97 WebRestrictionsResult result = new WebRestrictionsResult(false, errorInt , errorString);
95 when(mContentProvider.shouldProceed(anyString())).thenReturn(result); 98 when(mContentProvider.shouldProceed(ArgumentMatchers.<String>isNull(), a nyString()))
99 .thenReturn(result);
96 Cursor cursor = mContentResolver.query(mUri.buildUpon().appendPath("auth orized").build(), 100 Cursor cursor = mContentResolver.query(mUri.buildUpon().appendPath("auth orized").build(),
97 null, "url = 'dummy'", null, null); 101 null, "url = 'dummy'", null, null);
98 verify(mContentProvider).shouldProceed("dummy"); 102 verify(mContentProvider).shouldProceed(ArgumentMatchers.<String>isNull() , eq("dummy"));
dgn 2017/02/23 12:19:49 doesn't `.shouldProceed(null, "dummy")` work here?
Bernhard Bauer 2017/02/23 16:36:21 Yes, if I don't use eq() for the second argument.
99 assertThat(cursor, is(not(nullValue()))); 103 assertThat(cursor, is(not(nullValue())));
100 assertThat(cursor.getInt(0), is(WebRestrictionsContentProvider.BLOCKED)) ; 104 assertThat(cursor.getInt(0), is(WebRestrictionsContentProvider.BLOCKED)) ;
101 assertThat(cursor.getInt(1), is(42)); 105 assertThat(cursor.getInt(1), is(42));
102 assertThat(cursor.getString(2), is("Error Message")); 106 assertThat(cursor.getString(2), is("Error Message"));
103 result = new WebRestrictionsResult(true, null, null); 107 result = new WebRestrictionsResult(true, null, null);
104 when(mContentProvider.shouldProceed(anyString())).thenReturn(result); 108 when(mContentProvider.shouldProceed(ArgumentMatchers.<String>isNull(), a nyString()))
109 .thenReturn(result);
105 cursor = mContentResolver.query(mUri.buildUpon().appendPath("authorized" ).build(), null, 110 cursor = mContentResolver.query(mUri.buildUpon().appendPath("authorized" ).build(), null,
106 "url = 'dummy'", null, null); 111 "url = 'dummy'", null, null);
107 assertThat(cursor, is(not(nullValue()))); 112 assertThat(cursor, is(not(nullValue())));
108 assertThat(cursor.getInt(0), is(WebRestrictionsContentProvider.PROCEED)) ; 113 assertThat(cursor.getInt(0), is(WebRestrictionsContentProvider.PROCEED)) ;
109 } 114 }
110 115
111 @Test 116 @Test
112 public void testInsert() { 117 public void testInsert() {
113 ContentValues values = new ContentValues(); 118 ContentValues values = new ContentValues();
114 values.put("url", "dummy2"); 119 values.put("url", "dummy2");
(...skipping 24 matching lines...) Expand all
139 assertThat(mContentResolver.getType(mUri.buildUpon().appendPath("request ed").build()), 144 assertThat(mContentResolver.getType(mUri.buildUpon().appendPath("request ed").build()),
140 is(nullValue())); 145 is(nullValue()));
141 when(mContentProvider.canInsert()).thenReturn(true); 146 when(mContentProvider.canInsert()).thenReturn(true);
142 assertThat(mContentResolver.getType(mUri.buildUpon().appendPath("request ed").build()), 147 assertThat(mContentResolver.getType(mUri.buildUpon().appendPath("request ed").build()),
143 is(not(nullValue()))); 148 is(not(nullValue())));
144 when(mContentProvider.contentProviderEnabled()).thenReturn(false); 149 when(mContentProvider.contentProviderEnabled()).thenReturn(false);
145 assertThat(mContentResolver.getType(mUri.buildUpon().appendPath("junk"). build()), 150 assertThat(mContentResolver.getType(mUri.buildUpon().appendPath("junk"). build()),
146 is(nullValue())); 151 is(nullValue()));
147 } 152 }
148 } 153 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698