Index: base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java |
diff --git a/base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java b/base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ecc69bca8c7a0c0a62dec2fce876b90473c79446 |
--- /dev/null |
+++ b/base/test/android/java/src/org/chromium/base/ContentUriTestUtils.java |
@@ -0,0 +1,45 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.base; |
+ |
+import android.content.ContentResolver; |
+import android.content.Context; |
+import android.net.Uri; |
+import android.provider.MediaStore; |
+import android.util.Log; |
+ |
+import org.chromium.base.CalledByNative; |
+ |
+/** |
+ * Utilities for testing operations on content URI. |
+ */ |
+public class ContentUriTestUtils { |
+ /** |
+ * Insert an image into the MediaStore, and return the content URI. If the |
+ * image already exists in the MediaStore, a new entry will be created to |
+ * replace the old one. |
+ * |
+ * @param context Application context. |
+ * @param path Path to the image file. |
+ * @return Content URI of the image. |
+ */ |
+ @CalledByNative |
+ private static String insertImageIntoMediaStore(Context context, String path) { |
+ // Remove the content URI if it exists. |
+ context.getContentResolver().delete( |
+ MediaStore.Images.Media.EXTERNAL_CONTENT_URI, |
+ MediaStore.Images.Media.DATA + " LIKE ?", |
+ new String[] { path }); |
+ |
+ // Insert the content URI into MediaStore. |
+ String result = null; |
+ try { |
+ result = MediaStore.Images.Media.insertImage(context.getContentResolver(), path, "", ""); |
+ } catch(java.io.FileNotFoundException e) { |
+ Log.e("ContentUriTestUtils", "Cannot insert image into MediaStore", e); |
+ } |
+ return result; |
+ } |
+} |