OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.os.Build; | 10 import android.os.Build; |
11 import android.provider.MediaStore; | 11 import android.provider.MediaStore; |
12 import android.support.test.filters.MediumTest; | 12 import android.support.test.filters.MediumTest; |
13 | 13 |
| 14 import org.junit.Assert; |
| 15 import org.junit.Before; |
| 16 import org.junit.Rule; |
| 17 import org.junit.Test; |
| 18 import org.junit.runner.RunWith; |
| 19 |
14 import org.chromium.base.ThreadUtils; | 20 import org.chromium.base.ThreadUtils; |
| 21 import org.chromium.base.test.util.CommandLineFlags; |
15 import org.chromium.base.test.util.Feature; | 22 import org.chromium.base.test.util.Feature; |
16 import org.chromium.base.test.util.RetryOnFailure; | 23 import org.chromium.base.test.util.RetryOnFailure; |
17 import org.chromium.base.test.util.UrlUtils; | 24 import org.chromium.base.test.util.UrlUtils; |
18 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 25 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 26 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
19 import org.chromium.content.browser.ContentViewCore; | 27 import org.chromium.content.browser.ContentViewCore; |
20 import org.chromium.content.browser.test.util.Criteria; | 28 import org.chromium.content.browser.test.util.Criteria; |
21 import org.chromium.content.browser.test.util.CriteriaHelper; | 29 import org.chromium.content.browser.test.util.CriteriaHelper; |
22 import org.chromium.content.browser.test.util.DOMUtils; | 30 import org.chromium.content.browser.test.util.DOMUtils; |
23 import org.chromium.ui.base.ActivityWindowAndroid; | 31 import org.chromium.ui.base.ActivityWindowAndroid; |
24 import org.chromium.ui.base.SelectFileDialog; | 32 import org.chromium.ui.base.SelectFileDialog; |
25 | 33 |
26 /** | 34 /** |
27 * Integration test for select file dialog used for <input type="file" /> | 35 * Integration test for select file dialog used for <input type="file" /> |
28 */ | 36 */ |
29 public class SelectFileDialogTest extends ChromeActivityTestCaseBase<ChromeActiv
ity> { | 37 @RunWith(ChromeJUnit4ClassRunner.class) |
| 38 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 39 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| 40 public class SelectFileDialogTest { |
| 41 @Rule |
| 42 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| 43 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 44 |
30 private static final String DATA_URL = UrlUtils.encodeHtmlDataUri( | 45 private static final String DATA_URL = UrlUtils.encodeHtmlDataUri( |
31 "<html><head><meta name=\"viewport\"" | 46 "<html><head><meta name=\"viewport\"" |
32 + "content=\"width=device-width, initial-scale=2.0, maximum-scale=2.
0\" /></head>" | 47 + "content=\"width=device-width, initial-scale=2.0, maximum-scale=2.
0\" /></head>" |
33 + "<body><form action=\"about:blank\">" | 48 + "<body><form action=\"about:blank\">" |
34 + "<input id=\"input_file\" type=\"file\" /><br/>" | 49 + "<input id=\"input_file\" type=\"file\" /><br/>" |
35 + "<input id=\"input_text\" type=\"file\" accept=\"text/plain\" /><b
r/>" | 50 + "<input id=\"input_text\" type=\"file\" accept=\"text/plain\" /><b
r/>" |
36 + "<input id=\"input_any\" type=\"file\" accept=\"*/*\" /><br/>" | 51 + "<input id=\"input_any\" type=\"file\" accept=\"*/*\" /><br/>" |
37 + "<input id=\"input_file_multiple\" type=\"file\" multiple /><br />
" | 52 + "<input id=\"input_file_multiple\" type=\"file\" multiple /><br />
" |
38 + "<input id=\"input_image\" type=\"file\" accept=\"image/*\" captur
e /><br/>" | 53 + "<input id=\"input_image\" type=\"file\" accept=\"image/*\" captur
e /><br/>" |
39 + "<input id=\"input_audio\" type=\"file\" accept=\"audio/*\" captur
e />" | 54 + "<input id=\"input_audio\" type=\"file\" accept=\"audio/*\" captur
e />" |
(...skipping 30 matching lines...) Expand all Loading... |
70 | 85 |
71 @Override | 86 @Override |
72 public boolean isSatisfied() { | 87 public boolean isSatisfied() { |
73 return mActivityWindowAndroidForTest.lastIntent != null; | 88 return mActivityWindowAndroidForTest.lastIntent != null; |
74 } | 89 } |
75 } | 90 } |
76 | 91 |
77 private ContentViewCore mContentViewCore; | 92 private ContentViewCore mContentViewCore; |
78 private ActivityWindowAndroidForTest mActivityWindowAndroidForTest; | 93 private ActivityWindowAndroidForTest mActivityWindowAndroidForTest; |
79 | 94 |
80 public SelectFileDialogTest() { | 95 @Before |
81 super(ChromeActivity.class); | 96 public void setUp() throws Exception { |
82 } | 97 mActivityTestRule.startMainActivityWithURL(DATA_URL); |
83 | 98 |
84 @Override | 99 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
85 public void startMainActivity() throws InterruptedException { | 100 @Override |
86 startMainActivityWithURL(DATA_URL); | 101 public void run() { |
87 } | 102 mActivityWindowAndroidForTest = |
| 103 new ActivityWindowAndroidForTest(mActivityTestRule.getAc
tivity()); |
| 104 SelectFileDialog.setWindowAndroidForTests(mActivityWindowAndroid
ForTest); |
88 | 105 |
89 @Override | 106 mContentViewCore = mActivityTestRule.getActivity().getCurrentCon
tentViewCore(); |
90 public void setUp() throws Exception { | 107 // TODO(aurimas) remove this wait once crbug.com/179511 is fixed
. |
91 super.setUp(); | 108 mActivityTestRule.assertWaitForPageScaleFactorMatch(2); |
92 | 109 } |
93 mActivityWindowAndroidForTest = new ActivityWindowAndroidForTest(getActi
vity()); | 110 }); |
94 SelectFileDialog.setWindowAndroidForTests(mActivityWindowAndroidForTest)
; | |
95 | |
96 mContentViewCore = getActivity().getCurrentContentViewCore(); | |
97 // TODO(aurimas) remove this wait once crbug.com/179511 is fixed. | |
98 assertWaitForPageScaleFactorMatch(2); | |
99 DOMUtils.waitForNonZeroNodeBounds(mContentViewCore.getWebContents(), "in
put_file"); | 111 DOMUtils.waitForNonZeroNodeBounds(mContentViewCore.getWebContents(), "in
put_file"); |
100 } | 112 } |
101 | 113 |
102 /** | 114 /** |
103 * Tests that clicks on <input type="file" /> trigger intent calls to Activi
tyWindowAndroid. | 115 * Tests that clicks on <input type="file" /> trigger intent calls to Activi
tyWindowAndroid. |
104 */ | 116 */ |
| 117 @Test |
105 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) | 118 @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) |
106 @MediumTest | 119 @MediumTest |
107 @Feature({"TextInput", "Main"}) | 120 @Feature({"TextInput", "Main"}) |
108 @RetryOnFailure | 121 @RetryOnFailure |
109 public void testSelectFileAndCancelRequest() throws Throwable { | 122 public void testSelectFileAndCancelRequest() throws Throwable { |
110 { | 123 { |
111 DOMUtils.clickNode(mContentViewCore, "input_file"); | 124 DOMUtils.clickNode(mContentViewCore, "input_file"); |
112 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); | 125 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); |
113 assertEquals( | 126 Assert.assertEquals( |
114 Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastInt
ent.getAction()); | 127 Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastInt
ent.getAction()); |
115 Intent contentIntent = | 128 Intent contentIntent = |
116 (Intent) mActivityWindowAndroidForTest.lastIntent.getParcela
bleExtra( | 129 (Intent) mActivityWindowAndroidForTest.lastIntent.getParcela
bleExtra( |
117 Intent.EXTRA_INTENT); | 130 Intent.EXTRA_INTENT); |
118 assertNotNull(contentIntent); | 131 Assert.assertNotNull(contentIntent); |
119 assertFalse(contentIntent.hasCategory(Intent.CATEGORY_OPENABLE)); | 132 Assert.assertFalse(contentIntent.hasCategory(Intent.CATEGORY_OPENABL
E)); |
120 resetActivityWindowAndroidForTest(); | 133 resetActivityWindowAndroidForTest(); |
121 } | 134 } |
122 | 135 |
123 { | 136 { |
124 DOMUtils.clickNode(mContentViewCore, "input_text"); | 137 DOMUtils.clickNode(mContentViewCore, "input_text"); |
125 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); | 138 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); |
126 assertEquals( | 139 Assert.assertEquals( |
127 Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastInt
ent.getAction()); | 140 Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastInt
ent.getAction()); |
128 Intent contentIntent = | 141 Intent contentIntent = |
129 (Intent) mActivityWindowAndroidForTest.lastIntent.getParcela
bleExtra( | 142 (Intent) mActivityWindowAndroidForTest.lastIntent.getParcela
bleExtra( |
130 Intent.EXTRA_INTENT); | 143 Intent.EXTRA_INTENT); |
131 assertNotNull(contentIntent); | 144 Assert.assertNotNull(contentIntent); |
132 assertTrue(contentIntent.hasCategory(Intent.CATEGORY_OPENABLE)); | 145 Assert.assertTrue(contentIntent.hasCategory(Intent.CATEGORY_OPENABLE
)); |
133 resetActivityWindowAndroidForTest(); | 146 resetActivityWindowAndroidForTest(); |
134 } | 147 } |
135 | 148 |
136 { | 149 { |
137 DOMUtils.clickNode(mContentViewCore, "input_any"); | 150 DOMUtils.clickNode(mContentViewCore, "input_any"); |
138 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); | 151 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); |
139 assertEquals( | 152 Assert.assertEquals( |
140 Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastInt
ent.getAction()); | 153 Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastInt
ent.getAction()); |
141 Intent contentIntent = | 154 Intent contentIntent = |
142 (Intent) mActivityWindowAndroidForTest.lastIntent.getParcela
bleExtra( | 155 (Intent) mActivityWindowAndroidForTest.lastIntent.getParcela
bleExtra( |
143 Intent.EXTRA_INTENT); | 156 Intent.EXTRA_INTENT); |
144 assertNotNull(contentIntent); | 157 Assert.assertNotNull(contentIntent); |
145 assertFalse(contentIntent.hasCategory(Intent.CATEGORY_OPENABLE)); | 158 Assert.assertFalse(contentIntent.hasCategory(Intent.CATEGORY_OPENABL
E)); |
146 resetActivityWindowAndroidForTest(); | 159 resetActivityWindowAndroidForTest(); |
147 } | 160 } |
148 | 161 |
149 { | 162 { |
150 DOMUtils.clickNode(mContentViewCore, "input_file_multiple"); | 163 DOMUtils.clickNode(mContentViewCore, "input_file_multiple"); |
151 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); | 164 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); |
152 assertEquals( | 165 Assert.assertEquals( |
153 Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastInt
ent.getAction()); | 166 Intent.ACTION_CHOOSER, mActivityWindowAndroidForTest.lastInt
ent.getAction()); |
154 Intent contentIntent = | 167 Intent contentIntent = |
155 (Intent) mActivityWindowAndroidForTest.lastIntent.getParcela
bleExtra( | 168 (Intent) mActivityWindowAndroidForTest.lastIntent.getParcela
bleExtra( |
156 Intent.EXTRA_INTENT); | 169 Intent.EXTRA_INTENT); |
157 assertNotNull(contentIntent); | 170 Assert.assertNotNull(contentIntent); |
158 assertFalse(contentIntent.hasCategory(Intent.CATEGORY_OPENABLE)); | 171 Assert.assertFalse(contentIntent.hasCategory(Intent.CATEGORY_OPENABL
E)); |
159 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { | 172 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { |
160 assertTrue(contentIntent.hasExtra(Intent.EXTRA_ALLOW_MULTIPLE)); | 173 Assert.assertTrue(contentIntent.hasExtra(Intent.EXTRA_ALLOW_MULT
IPLE)); |
161 } | 174 } |
162 resetActivityWindowAndroidForTest(); | 175 resetActivityWindowAndroidForTest(); |
163 } | 176 } |
164 | 177 |
165 DOMUtils.clickNode(mContentViewCore, "input_image"); | 178 DOMUtils.clickNode(mContentViewCore, "input_image"); |
166 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); | 179 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); |
167 assertEquals(MediaStore.ACTION_IMAGE_CAPTURE, | 180 Assert.assertEquals(MediaStore.ACTION_IMAGE_CAPTURE, |
168 mActivityWindowAndroidForTest.lastIntent.getAction()); | 181 mActivityWindowAndroidForTest.lastIntent.getAction()); |
169 resetActivityWindowAndroidForTest(); | 182 resetActivityWindowAndroidForTest(); |
170 | 183 |
171 DOMUtils.clickNode(mContentViewCore, "input_audio"); | 184 DOMUtils.clickNode(mContentViewCore, "input_audio"); |
172 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); | 185 CriteriaHelper.pollInstrumentationThread(new IntentSentCriteria()); |
173 assertEquals(MediaStore.Audio.Media.RECORD_SOUND_ACTION, | 186 Assert.assertEquals(MediaStore.Audio.Media.RECORD_SOUND_ACTION, |
174 mActivityWindowAndroidForTest.lastIntent.getAction()); | 187 mActivityWindowAndroidForTest.lastIntent.getAction()); |
175 resetActivityWindowAndroidForTest(); | 188 resetActivityWindowAndroidForTest(); |
176 } | 189 } |
177 | 190 |
178 private void resetActivityWindowAndroidForTest() { | 191 private void resetActivityWindowAndroidForTest() { |
179 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 192 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
180 @Override | 193 @Override |
181 public void run() { | 194 public void run() { |
182 mActivityWindowAndroidForTest.lastCallback.onIntentCompleted( | 195 mActivityWindowAndroidForTest.lastCallback.onIntentCompleted( |
183 mActivityWindowAndroidForTest, Activity.RESULT_CANCELED,
null); | 196 mActivityWindowAndroidForTest, Activity.RESULT_CANCELED,
null); |
184 } | 197 } |
185 }); | 198 }); |
186 mActivityWindowAndroidForTest.lastCallback = null; | 199 mActivityWindowAndroidForTest.lastCallback = null; |
187 mActivityWindowAndroidForTest.lastIntent = null; | 200 mActivityWindowAndroidForTest.lastIntent = null; |
188 } | 201 } |
189 } | 202 } |
OLD | NEW |