1 // Copyright 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.chrome.browser.test; 6 7 import android.content.ContentProvider; 8 import android.content.ContentResolver; 9 import android.test.IsolatedContext; 10 import android.test.mock.MockContentResolver; 11 12 import org.chromium.chrome.browser.ChromeBrowserProvider; 13 import org.chromium.chrome.shell.ChromeShellActivity; 14 import org.chromium.chrome.shell.ChromeShellTestBase; 15 16 /** 17 * Base class for Chrome's ContentProvider tests. 18 * Sets up a local ChromeBrowserProvider associated to a mock resolver in an isolated context. 19 */ 20 public class ProviderTestBase extends ChromeShellTestBase { 21 22 private IsolatedContext mContext; 23 24 @Override 25 protected void setUp() throws Exception { 26 super.setUp(); 27 28 ChromeShellActivity activity = launchChromeShellWithUrl(null); 29 assertNotNull(activity); 30 31 ContentProvider provider = new ChromeBrowserProvider(); 32 provider.attachInfo(activity, null); 33 34 MockContentResolver resolver = new MockContentResolver(); 35 resolver.addProvider(ChromeBrowserProvider.getApiAuthority(activity), provider); 36 resolver.addProvider(ChromeBrowserProvider.getInternalAuthority(activity), provider); 37 38 mContext = new IsolatedContext(resolver, activity); 39 assertTrue(getContentResolver() instanceof MockContentResolver); 40 } 41 42 protected ContentResolver getContentResolver() { 43 return mContext.getContentResolver(); 44 } 45 } 46