| OLD | NEW |
| 1 // Copyright 2012 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 /** | 5 /** |
| 6 * Content provider for testing content URLs. | 6 * Content provider for testing content URLs. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 package org.chromium.android_webview.test; | 9 package org.chromium.chrome.test; |
| 10 | 10 |
| 11 import android.content.ContentProvider; | 11 import android.content.ContentProvider; |
| 12 import android.content.ContentValues; | 12 import android.content.ContentValues; |
| 13 import android.content.Context; | 13 import android.content.Context; |
| 14 import android.content.res.AssetFileDescriptor; | 14 import android.content.res.AssetFileDescriptor; |
| 15 import android.database.AbstractCursor; | 15 import android.database.AbstractCursor; |
| 16 import android.database.Cursor; | 16 import android.database.Cursor; |
| 17 import android.net.Uri; | 17 import android.net.Uri; |
| 18 import android.os.ParcelFileDescriptor; | 18 import android.os.ParcelFileDescriptor; |
| 19 import android.util.Log; | 19 import android.util.Log; |
| 20 | 20 |
| 21 import java.io.FileOutputStream; | 21 import java.io.FileOutputStream; |
| 22 import java.io.IOException; | 22 import java.io.IOException; |
| 23 import java.util.HashMap; | 23 import java.util.HashMap; |
| 24 import java.util.Map; | 24 import java.util.Map; |
| 25 | 25 |
| 26 // Note: if you move this class, make sure you have also updated AndroidManifest
.xml | 26 // Note: if you move this class, make sure you have also updated AndroidManifest
.xml |
| 27 public class TestContentProvider extends ContentProvider { | 27 public class TestContentProvider extends ContentProvider { |
| 28 private static final String AUTHORITY = | 28 private static final String AUTHORITY = "org.chromium.chrome.test.TestConten
tProvider"; |
| 29 "org.chromium.android_webview.test.TestContentProvider"; | |
| 30 private static final String CONTENT_SCHEME = "content://"; | 29 private static final String CONTENT_SCHEME = "content://"; |
| 31 private static final String CONTENT_TYPE = "image/png"; | 30 private static final String CONTENT_TYPE = "image/png"; |
| 32 private static final String GET_RESOURCE_REQUEST_COUNT = "get_resource_reque
st_count"; | 31 private static final String GET_RESOURCE_REQUEST_COUNT = "get_resource_reque
st_count"; |
| 33 private static final String RESET_RESOURCE_REQUEST_COUNT = "reset_resource_r
equest_count"; | 32 private static final String RESET_RESOURCE_REQUEST_COUNT = "reset_resource_r
equest_count"; |
| 34 private static final String TAG = "TestContentProvider"; | 33 private static final String TAG = "TestContentProvider"; |
| 35 private enum ColumnIndex { | 34 private enum ColumnIndex { |
| 36 RESOURCE_REQUEST_COUNT_COLUMN, | 35 RESOURCE_REQUEST_COUNT_COLUMN, |
| 37 } | 36 } |
| 38 private final Map<String, Integer> mResourceRequestCount; | 37 private final Map<String, Integer> mResourceRequestCount; |
| 39 | 38 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 return new String[] { GET_RESOURCE_REQUEST_COUNT }; | 177 return new String[] { GET_RESOURCE_REQUEST_COUNT }; |
| 179 } | 178 } |
| 180 } | 179 } |
| 181 | 180 |
| 182 @Override | 181 @Override |
| 183 public Cursor query(Uri uri, String[] projection, String selection, | 182 public Cursor query(Uri uri, String[] projection, String selection, |
| 184 String[] selectionArgs, String sortOrder) { | 183 String[] selectionArgs, String sortOrder) { |
| 185 String action = uri.getLastPathSegment(); | 184 String action = uri.getLastPathSegment(); |
| 186 String resource = uri.getQuery(); | 185 String resource = uri.getQuery(); |
| 187 if (GET_RESOURCE_REQUEST_COUNT.equals(action)) { | 186 if (GET_RESOURCE_REQUEST_COUNT.equals(action)) { |
| 188 return new ProviderStateCursor( | 187 return new ProviderStateCursor(mResourceRequestCount.containsKey(res
ource) |
| 189 mResourceRequestCount.containsKey(resource) | |
| 190 ? mResourceRequestCount.get(resource) : 0); | 188 ? mResourceRequestCount.get(resource) : 0); |
| 191 } else if (RESET_RESOURCE_REQUEST_COUNT.equals(action)) { | 189 } else if (RESET_RESOURCE_REQUEST_COUNT.equals(action)) { |
| 192 mResourceRequestCount.put(resource, 0); | 190 mResourceRequestCount.put(resource, 0); |
| 193 } | 191 } |
| 194 return null; | 192 return null; |
| 195 } | 193 } |
| 196 | 194 |
| 197 // 1x1 black dot png image. | 195 // 1x1 black dot png image. |
| 198 private static final byte[] IMAGE = { | 196 private static final byte[] IMAGE = { |
| 199 (byte) 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, | 197 (byte) 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 219 } finally { | 217 } finally { |
| 220 if (fileOut != null) fileOut.close(); | 218 if (fileOut != null) fileOut.close(); |
| 221 if (pfds != null && pfds[1] != null) pfds[1].close(); | 219 if (pfds != null && pfds[1] != null) pfds[1].close(); |
| 222 } | 220 } |
| 223 } catch (IOException e) { | 221 } catch (IOException e) { |
| 224 Log.e(TAG, e.getMessage(), e); | 222 Log.e(TAG, e.getMessage(), e); |
| 225 } | 223 } |
| 226 return null; | 224 return null; |
| 227 } | 225 } |
| 228 } | 226 } |
| OLD | NEW |