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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/autofill/AutofillPopupWithKeyboardTest.java

Issue 2831823003: Convert ChromeActivityTestCaseBase direct children to JUnit4 (Closed)
Patch Set: fix findbug issues Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 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 package org.chromium.chrome.browser.autofill; 5 package org.chromium.chrome.browser.autofill;
6 6
7 import android.support.test.filters.MediumTest; 7 import android.support.test.filters.MediumTest;
8 import android.view.ViewGroup; 8 import android.view.ViewGroup;
9 9
10 import org.junit.Assert;
11 import org.junit.Rule;
12 import org.junit.Test;
13 import org.junit.runner.RunWith;
14
10 import org.chromium.base.ThreadUtils; 15 import org.chromium.base.ThreadUtils;
16 import org.chromium.base.test.util.CommandLineFlags;
11 import org.chromium.base.test.util.Feature; 17 import org.chromium.base.test.util.Feature;
12 import org.chromium.base.test.util.RetryOnFailure; 18 import org.chromium.base.test.util.RetryOnFailure;
13 import org.chromium.base.test.util.UrlUtils; 19 import org.chromium.base.test.util.UrlUtils;
14 import org.chromium.chrome.browser.ChromeActivity; 20 import org.chromium.chrome.browser.ChromeActivity;
21 import org.chromium.chrome.browser.ChromeSwitches;
15 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; 22 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile;
16 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 23 import org.chromium.chrome.test.ChromeActivityTestRule;
24 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
17 import org.chromium.components.autofill.AutofillPopup; 25 import org.chromium.components.autofill.AutofillPopup;
18 import org.chromium.content.browser.ContentViewCore; 26 import org.chromium.content.browser.ContentViewCore;
19 import org.chromium.content.browser.test.util.Criteria; 27 import org.chromium.content.browser.test.util.Criteria;
20 import org.chromium.content.browser.test.util.CriteriaHelper; 28 import org.chromium.content.browser.test.util.CriteriaHelper;
21 import org.chromium.content.browser.test.util.DOMUtils; 29 import org.chromium.content.browser.test.util.DOMUtils;
22 import org.chromium.content_public.browser.WebContents; 30 import org.chromium.content_public.browser.WebContents;
23 import org.chromium.ui.R; 31 import org.chromium.ui.R;
24 import org.chromium.ui.UiUtils; 32 import org.chromium.ui.UiUtils;
25 33
26 import java.util.concurrent.Callable; 34 import java.util.concurrent.Callable;
27 import java.util.concurrent.ExecutionException; 35 import java.util.concurrent.ExecutionException;
28 import java.util.concurrent.TimeoutException; 36 import java.util.concurrent.TimeoutException;
29 import java.util.concurrent.atomic.AtomicReference; 37 import java.util.concurrent.atomic.AtomicReference;
30 38
31 /** 39 /**
32 * Integration tests for interaction of the AutofillPopup and a keyboard. 40 * Integration tests for interaction of the AutofillPopup and a keyboard.
33 */ 41 */
34 public class AutofillPopupWithKeyboardTest extends ChromeActivityTestCaseBase<Ch romeActivity> { 42 @RunWith(ChromeJUnit4ClassRunner.class)
35 43 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
36 public AutofillPopupWithKeyboardTest() { 44 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
37 super(ChromeActivity.class); 45 public class AutofillPopupWithKeyboardTest {
38 } 46 @Rule
39 47 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
40 @Override 48 new ChromeActivityTestRule<>(ChromeActivity.class);
41 public void startMainActivity() throws InterruptedException {
42 // Don't launch activity automatically.
43 }
44 49
45 /** 50 /**
46 * Test that showing autofill popup and keyboard will not hide the autofill popup. 51 * Test that showing autofill popup and keyboard will not hide the autofill popup.
47 */ 52 */
53 @Test
48 @MediumTest 54 @MediumTest
49 @Feature({"autofill-keyboard"}) 55 @Feature({"autofill-keyboard"})
50 @RetryOnFailure 56 @RetryOnFailure
51 public void testShowAutofillPopupAndKeyboardimultaneously() 57 public void testShowAutofillPopupAndKeyboardimultaneously()
52 throws InterruptedException, ExecutionException, TimeoutException { 58 throws InterruptedException, ExecutionException, TimeoutException {
53 startMainActivityWithURL(UrlUtils.encodeHtmlDataUri("<html><head>" 59 mActivityTestRule.startMainActivityWithURL(UrlUtils.encodeHtmlDataUri("< html><head>"
54 + "<meta name=\"viewport\"" 60 + "<meta name=\"viewport\""
55 + "content=\"width=device-width, initial-scale=1.0, maximum-scal e=1.0\" /></head>" 61 + "content=\"width=device-width, initial-scale=1.0, maximum-scal e=1.0\" /></head>"
56 + "<body><form method=\"POST\">" 62 + "<body><form method=\"POST\">"
57 + "<input type=\"text\" id=\"fn\" autocomplete=\"given-name\" /> <br>" 63 + "<input type=\"text\" id=\"fn\" autocomplete=\"given-name\" /> <br>"
58 + "<input type=\"text\" id=\"ln\" autocomplete=\"family-name\" / ><br>" 64 + "<input type=\"text\" id=\"ln\" autocomplete=\"family-name\" / ><br>"
59 + "<textarea id=\"sa\" autocomplete=\"street-address\"></textare a><br>" 65 + "<textarea id=\"sa\" autocomplete=\"street-address\"></textare a><br>"
60 + "<input type=\"text\" id=\"a1\" autocomplete=\"address-line1\" /><br>" 66 + "<input type=\"text\" id=\"a1\" autocomplete=\"address-line1\" /><br>"
61 + "<input type=\"text\" id=\"a2\" autocomplete=\"address-line2\" /><br>" 67 + "<input type=\"text\" id=\"a2\" autocomplete=\"address-line2\" /><br>"
62 + "<input type=\"text\" id=\"ct\" autocomplete=\"locality\" /><b r>" 68 + "<input type=\"text\" id=\"ct\" autocomplete=\"locality\" /><b r>"
63 + "<input type=\"text\" id=\"zc\" autocomplete=\"postal-code\" / ><br>" 69 + "<input type=\"text\" id=\"zc\" autocomplete=\"postal-code\" / ><br>"
64 + "<input type=\"text\" id=\"em\" autocomplete=\"email\" /><br>" 70 + "<input type=\"text\" id=\"em\" autocomplete=\"email\" /><br>"
65 + "<input type=\"text\" id=\"ph\" autocomplete=\"tel\" /><br>" 71 + "<input type=\"text\" id=\"ph\" autocomplete=\"tel\" /><br>"
66 + "<input type=\"text\" id=\"fx\" autocomplete=\"fax\" /><br>" 72 + "<input type=\"text\" id=\"fx\" autocomplete=\"fax\" /><br>"
67 + "<select id=\"co\" autocomplete=\"country\"><br>" 73 + "<select id=\"co\" autocomplete=\"country\"><br>"
68 + "<option value=\"BR\">Brazil</option>" 74 + "<option value=\"BR\">Brazil</option>"
69 + "<option value=\"US\">United States</option>" 75 + "<option value=\"US\">United States</option>"
70 + "</select>" 76 + "</select>"
71 + "<input type=\"submit\" />" 77 + "<input type=\"submit\" />"
72 + "</form></body></html>")); 78 + "</form></body></html>"));
73 new AutofillTestHelper().setProfile(new AutofillProfile("", "https://www .example.com", 79 new AutofillTestHelper().setProfile(new AutofillProfile("", "https://www .example.com",
74 "John Smith", "Acme Inc", "1 Main\nApt A", "CA", "San Francisco" , "", "94102", "", 80 "John Smith", "Acme Inc", "1 Main\nApt A", "CA", "San Francisco" , "", "94102", "",
75 "US", "(415) 888-9999", "john@acme.inc", "en")); 81 "US", "(415) 888-9999", "john@acme.inc", "en"));
76 final AtomicReference<ContentViewCore> viewCoreRef = new AtomicReference <ContentViewCore>(); 82 final AtomicReference<ContentViewCore> viewCoreRef = new AtomicReference <ContentViewCore>();
77 final AtomicReference<WebContents> webContentsRef = new AtomicReference< WebContents>(); 83 final AtomicReference<WebContents> webContentsRef = new AtomicReference< WebContents>();
78 final AtomicReference<ViewGroup> viewRef = new AtomicReference<ViewGroup >(); 84 final AtomicReference<ViewGroup> viewRef = new AtomicReference<ViewGroup >();
79 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 85 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
80 @Override 86 @Override
81 public void run() { 87 public void run() {
82 viewCoreRef.set(getActivity().getCurrentContentViewCore()); 88 viewCoreRef.set(mActivityTestRule.getActivity().getCurrentConten tViewCore());
83 webContentsRef.set(viewCoreRef.get().getWebContents()); 89 webContentsRef.set(viewCoreRef.get().getWebContents());
84 viewRef.set(viewCoreRef.get().getContainerView()); 90 viewRef.set(viewCoreRef.get().getContainerView());
85 } 91 }
86 }); 92 });
87 DOMUtils.waitForNonZeroNodeBounds(webContentsRef.get(), "fn"); 93 DOMUtils.waitForNonZeroNodeBounds(webContentsRef.get(), "fn");
88 94
89 // Click on the unfocused input element for the first time to focus on i t. This brings up 95 // Click on the unfocused input element for the first time to focus on i t. This brings up
90 // the autofill popup and shows the keyboard at the same time. Showing t he keyboard should 96 // the autofill popup and shows the keyboard at the same time. Showing t he keyboard should
91 // not hide the autofill popup. 97 // not hide the autofill popup.
92 DOMUtils.clickNode(viewCoreRef.get(), "fn"); 98 DOMUtils.clickNode(viewCoreRef.get(), "fn");
93 99
94 // Wait until the keyboard is showing. 100 // Wait until the keyboard is showing.
95 CriteriaHelper.pollUiThread(new Criteria("Keyboard was never shown.") { 101 CriteriaHelper.pollUiThread(new Criteria("Keyboard was never shown.") {
96 @Override 102 @Override
97 public boolean isSatisfied() { 103 public boolean isSatisfied() {
98 return UiUtils.isKeyboardShowing( 104 return UiUtils.isKeyboardShowing(mActivityTestRule.getActivity() ,
99 getActivity(), 105 mActivityTestRule.getActivity()
100 getActivity().getCurrentContentViewCore().getContainerVi ew()); 106 .getCurrentContentViewCore()
107 .getContainerView());
101 } 108 }
102 }); 109 });
103 110
104 // Verify that the autofill popup is showing. 111 // Verify that the autofill popup is showing.
105 CriteriaHelper.pollUiThread( 112 CriteriaHelper.pollUiThread(
106 new Criteria("Autofill Popup anchor view was never added.") { 113 new Criteria("Autofill Popup anchor view was never added.") {
107 @Override 114 @Override
108 public boolean isSatisfied() { 115 public boolean isSatisfied() {
109 return viewRef.get().findViewById(R.id.dropdown_popup_wi ndow) != null; 116 return viewRef.get().findViewById(R.id.dropdown_popup_wi ndow) != null;
110 } 117 }
111 }); 118 });
112 Object popupObject = ThreadUtils.runOnUiThreadBlocking(new Callable<Obje ct>() { 119 Object popupObject = ThreadUtils.runOnUiThreadBlocking(new Callable<Obje ct>() {
113 @Override 120 @Override
114 public Object call() { 121 public Object call() {
115 return viewRef.get().findViewById(R.id.dropdown_popup_window).ge tTag(); 122 return viewRef.get().findViewById(R.id.dropdown_popup_window).ge tTag();
116 } 123 }
117 }); 124 });
118 assertTrue(popupObject instanceof AutofillPopup); 125 Assert.assertTrue(popupObject instanceof AutofillPopup);
119 final AutofillPopup popup = (AutofillPopup) popupObject; 126 final AutofillPopup popup = (AutofillPopup) popupObject;
120 CriteriaHelper.pollUiThread(new Criteria("Autofill Popup was never shown .") { 127 CriteriaHelper.pollUiThread(new Criteria("Autofill Popup was never shown .") {
121 @Override 128 @Override
122 public boolean isSatisfied() { 129 public boolean isSatisfied() {
123 return popup.isShowing(); 130 return popup.isShowing();
124 } 131 }
125 }); 132 });
126 } 133 }
127 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698