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

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

Issue 185563010: Adding a test for SelectFileDialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 9 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
« no previous file with comments | « no previous file | chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellActivity.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/input/SelectFileDialogTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/input/SelectFileDialogTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/input/SelectFileDialogTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..3d01024c823e7b23953689009ac28599ed2d007a
--- /dev/null
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/input/SelectFileDialogTest.java
@@ -0,0 +1,128 @@
+// Copyright 2014 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.input;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.provider.MediaStore;
+import android.test.suitebuilder.annotation.MediumTest;
+
+import org.chromium.base.test.util.Feature;
+import org.chromium.base.test.util.UrlUtils;
+import org.chromium.chrome.shell.ChromeShellActivity;
+import org.chromium.chrome.shell.ChromeShellActivity.WindowAndroidFactoryForTest;
+import org.chromium.chrome.shell.ChromeShellTestBase;
+import org.chromium.content.browser.ContentView;
+import org.chromium.content.browser.test.util.Criteria;
+import org.chromium.content.browser.test.util.CriteriaHelper;
+import org.chromium.content.browser.test.util.DOMUtils;
+import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
+import org.chromium.content.browser.test.util.UiUtils;
+import org.chromium.ui.base.ActivityWindowAndroid;
+
+/**
+ * Integration test for select file dialog used for <input type="file" />
+ */
+public class SelectFileDialogTest extends ChromeShellTestBase {
+ private static final String DATA_URL = UrlUtils.encodeHtmlDataUri(
+ "<html><head><meta name=\"viewport\"" +
+ "content=\"width=device-width, initial-scale=2.0, maximum-scale=2.0\" /></head>" +
+ "<body><form action=\"about:blank\">" +
+ "<input id=\"input_file\" type=\"file\" /><br/>" +
+ "<input id=\"input_image\" type=\"file\" accept=\"image/*\" capture /><br/>" +
+ "<input id=\"input_audio\" type=\"file\" accept=\"audio/*\" capture />" +
+ "</form>" +
+ "</body></html>");
+
+ private ContentView mContentView;
+ private TestCallbackHelperContainer mCallbackContainer;
+ private ActivityWindowAndroidForTest mActivityWindowAndroidForTest;
+
+ private static class ActivityWindowAndroidForTest extends ActivityWindowAndroid {
+ public Intent lastIntent;
+ public IntentCallback lastCallback;
+ /**
+ * @param activity
+ */
+ public ActivityWindowAndroidForTest(Activity activity) {
+ super(activity);
+ }
+
+ @Override
+ public int showCancelableIntent(Intent intent, IntentCallback callback, int errorId) {
+ lastIntent = intent;
+ lastCallback = callback;
+ return 1;
+ }
+ }
+
+ private class IntentSentCriteria implements Criteria {
+ @Override
+ public boolean isSatisfied() {
+ return mActivityWindowAndroidForTest.lastIntent != null;
+ }
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ ChromeShellActivity.setActivityWindowAndroidFactory(new WindowAndroidFactoryForTest() {
+ @Override
+ public ActivityWindowAndroid getActivityWindowAndroid(Activity activity) {
+ mActivityWindowAndroidForTest = new ActivityWindowAndroidForTest(activity);
+ return mActivityWindowAndroidForTest;
+ }
+ });
+ launchChromeShellWithUrl(DATA_URL);
+ assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
+
+ mContentView = getActivity().getActiveContentView();
+ mCallbackContainer = new TestCallbackHelperContainer(mContentView);
+ // TODO(aurimas) remove this wait once crbug.com/179511 is fixed.
+ assertWaitForPageScaleFactorMatch(2);
+ assertTrue(
+ DOMUtils.waitForNonZeroNodeBounds(mContentView, mCallbackContainer, "input_file"));
+ }
+
+ /**
+ * Tests that clicks on <input type="file" /> trigger intent calls to ActivityWindowAndroid.
+ */
+ @MediumTest
+ @Feature({"TextInput", "Main"})
+ public void testSelectFileAndCancelRequest() throws Throwable {
+ DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_file");
+ assertTrue("SelectFileDialog never sent an intent.",
+ CriteriaHelper.pollForCriteria(new IntentSentCriteria()));
+ assertEquals(Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastIntent.getAction());
+ resetActivityWindowAndroidForTest();
+
+ DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_image");
+ assertTrue("SelectFileDialog never sent an intent.",
+ CriteriaHelper.pollForCriteria(new IntentSentCriteria()));
+ assertEquals(MediaStore.ACTION_IMAGE_CAPTURE,
+ mActivityWindowAndroidForTest.lastIntent.getAction());
+ resetActivityWindowAndroidForTest();
+
+ DOMUtils.clickNode(this, mContentView, mCallbackContainer, "input_audio");
+ assertTrue("SelectFileDialog never sent an intent.",
+ CriteriaHelper.pollForCriteria(new IntentSentCriteria()));
+ assertEquals(MediaStore.Audio.Media.RECORD_SOUND_ACTION,
+ mActivityWindowAndroidForTest.lastIntent.getAction());
+ resetActivityWindowAndroidForTest();
+ }
+
+ private void resetActivityWindowAndroidForTest() {
+ UiUtils.runOnUiThread(getActivity(), new Runnable() {
+ @Override
+ public void run() {
+ mActivityWindowAndroidForTest.lastCallback.onIntentCompleted(
+ mActivityWindowAndroidForTest, Activity.RESULT_CANCELED, null, null);
+ }
+ });
+ mActivityWindowAndroidForTest.lastCallback = null;
+ mActivityWindowAndroidForTest.lastIntent = null;
+ }
+}
« no previous file with comments | « no previous file | chrome/android/shell/java/src/org/chromium/chrome/shell/ChromeShellActivity.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698