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

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/ChromeFileProviderTest.java

Issue 2143133002: Do screenshot capture async for share intents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments and rebase. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/android/javatests/src/org/chromium/chrome/browser/ChromeFileProviderTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeFileProviderTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeFileProviderTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..e8c09ce4f795e1cb20e918585fffde1e1cdb83a1
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/ChromeFileProviderTest.java
@@ -0,0 +1,99 @@
+// Copyright 2016 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.chrome.browser;
+
+import android.content.Context;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.ParcelFileDescriptor;
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import org.chromium.content.browser.test.NativeLibraryTestBase;
+
+import java.io.FileNotFoundException;
+
+/**
+ * Tests working of ChromeFileProvider.
+ *
+ * The openFile should be blocked till notify is called. These tests can timeout if the notify does
+ * not work correctly.
+ */
+public class ChromeFileProviderTest extends NativeLibraryTestBase {
+ private ParcelFileDescriptor openFileFromProvider(Uri uri) {
+ ChromeFileProvider provider = new ChromeFileProvider();
+ ParcelFileDescriptor file = null;
+ try {
+ provider.openFile(uri, "r");
+ } catch (FileNotFoundException e) {
+ assert false : "Failed to open file.";
+ }
+ return file;
+ }
+
+ @SmallTest
+ public void testOpenFileWhenReady() {
+ Uri uri = ChromeFileProvider.generateUriAndBlockAccess(getInstrumentation().getContext());
+ Uri fileUri = new Uri.Builder().path("1").build();
+ ChromeFileProvider.notifyFileReady(uri, fileUri);
+ Uri result = ChromeFileProvider.getFileUriWhenReady(uri);
+ assertEquals(result, fileUri);
+ }
+
+ @LargeTest
+ public void testOpenOnAsyncNotify() {
+ final Context context = getInstrumentation().getContext();
+ final Uri uri = ChromeFileProvider.generateUriAndBlockAccess(context);
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... params) {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ // Ignore exception.
+ }
+ ChromeFileProvider.notifyFileReady(uri, null);
+ return null;
+ }
+ }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Ted C 2016/09/07 00:30:08 if you want to just do the doInBackground bits wit
ssid 2016/09/07 00:51:23 Tommy suggested that I should always call executeO
Ted C 2016/09/07 17:30:13 I just chatted to Tommy and I think there was a bi
ssid 2016/09/08 03:56:56 Thanks for explanation. Fixed.
+ ParcelFileDescriptor file = openFileFromProvider(uri);
+ // File should be null because the notify passes a null file uri.
+ assertNull(file);
+ }
+
+ @LargeTest
+ public void testFileChanged() {
+ final Context context = getInstrumentation().getContext();
+ Uri uri1 = ChromeFileProvider.generateUriAndBlockAccess(context);
+ final Uri uri2 = ChromeFileProvider.generateUriAndBlockAccess(context);
+ final Uri fileUri2 = new Uri.Builder().path("2").build();
+ new AsyncTask<Void, Void, Void>() {
+ @Override
+ protected Void doInBackground(Void... params) {
+ try {
+ Thread.sleep(10);
+ } catch (InterruptedException e) {
+ // Ignore exception.
+ }
+ ChromeFileProvider.notifyFileReady(uri2, fileUri2);
+ return null;
+ }
+ }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+
+ // This should not be blocked even without a notify since file was changed.
+ Uri file1 = ChromeFileProvider.getFileUriWhenReady(uri1);
+ // File should be null because the notify passes a null file uri.
+ assertNull(file1);
+
+ // This should be unblocked when the notify is called.
+ Uri file2 = ChromeFileProvider.getFileUriWhenReady(uri2);
+ assertEquals(fileUri2, file2);
+
+ // This should not be blocked even without a notify since file was changed.
+ file1 = ChromeFileProvider.getFileUriWhenReady(uri1);
+ // File should be null because the notify passes a null file uri.
+ assertNull(file1);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698