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.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
| 7 import android.content.ClipData; |
| 8 import android.content.ClipboardManager; |
| 9 import android.content.Context; |
7 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
8 | 11 |
9 import org.chromium.base.ThreadUtils; | 12 import org.chromium.base.ThreadUtils; |
10 import org.chromium.base.test.util.Feature; | 13 import org.chromium.base.test.util.Feature; |
11 import org.chromium.base.test.util.UrlUtils; | 14 import org.chromium.base.test.util.UrlUtils; |
12 import org.chromium.content.browser.test.util.Criteria; | 15 import org.chromium.content.browser.test.util.Criteria; |
13 import org.chromium.content.browser.test.util.CriteriaHelper; | 16 import org.chromium.content.browser.test.util.CriteriaHelper; |
14 import org.chromium.content.browser.test.util.DOMUtils; | 17 import org.chromium.content.browser.test.util.DOMUtils; |
15 import org.chromium.content_shell_apk.ContentShellTestBase; | 18 import org.chromium.content_shell_apk.ContentShellTestBase; |
16 | 19 |
(...skipping 19 matching lines...) Expand all Loading... |
36 @Override | 39 @Override |
37 public void setUp() throws Exception { | 40 public void setUp() throws Exception { |
38 super.setUp(); | 41 super.setUp(); |
39 | 42 |
40 launchContentShellWithUrl(DATA_URL); | 43 launchContentShellWithUrl(DATA_URL); |
41 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); | 44 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); |
42 | 45 |
43 mContentViewCore = getContentViewCore(); | 46 mContentViewCore = getContentViewCore(); |
44 assertWaitForPageScaleFactorMatch(1.1f); | 47 assertWaitForPageScaleFactorMatch(1.1f); |
45 assertWaitForSelectActionBarVisible(false); | 48 assertWaitForSelectActionBarVisible(false); |
| 49 assertWaitForPastePopupStatus(false); |
46 } | 50 } |
47 | 51 |
48 @SmallTest | 52 @SmallTest |
49 @Feature({"TextSelection"}) | 53 @Feature({"TextSelection"}) |
50 public void testSelectionClearedAfterLossOfFocus() throws Throwable { | 54 public void testSelectionClearedAfterLossOfFocus() throws Throwable { |
51 requestFocusOnUiThread(true); | 55 requestFocusOnUiThread(true); |
52 | 56 |
53 DOMUtils.longPressNode(this, mContentViewCore, "textarea"); | 57 DOMUtils.longPressNode(this, mContentViewCore, "textarea"); |
54 assertWaitForSelectActionBarVisible(true); | 58 assertWaitForSelectActionBarVisible(true); |
55 | 59 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 115 |
112 setAttachedOnUiThread(false); | 116 setAttachedOnUiThread(false); |
113 assertWaitForSelectActionBarVisible(false); | 117 assertWaitForSelectActionBarVisible(false); |
114 assertTrue(mContentViewCore.hasSelection()); | 118 assertTrue(mContentViewCore.hasSelection()); |
115 | 119 |
116 setAttachedOnUiThread(true); | 120 setAttachedOnUiThread(true); |
117 assertWaitForSelectActionBarVisible(true); | 121 assertWaitForSelectActionBarVisible(true); |
118 assertTrue(mContentViewCore.hasSelection()); | 122 assertTrue(mContentViewCore.hasSelection()); |
119 } | 123 } |
120 | 124 |
| 125 @SmallTest |
| 126 @Feature({"TextInput"}) |
| 127 public void testPastePopupNotShownOnLongPressingNonEmptyInput() throws Throw
able { |
| 128 copyStringToClipboard(); |
| 129 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 130 assertWaitForPastePopupStatus(true); |
| 131 DOMUtils.longPressNode(this, mContentViewCore, "input_text"); |
| 132 assertWaitForSelectActionBarVisible(true); |
| 133 assertWaitForPastePopupStatus(false); |
| 134 } |
| 135 |
| 136 @SmallTest |
| 137 @Feature({"TextInput"}) |
| 138 public void testPastePopupClearedOnTappingEmptyInput() throws Throwable { |
| 139 copyStringToClipboard(); |
| 140 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 141 assertWaitForPastePopupStatus(true); |
| 142 DOMUtils.clickNode(this, mContentViewCore, "empty_input_text"); |
| 143 assertWaitForPastePopupStatus(false); |
| 144 } |
| 145 |
| 146 @SmallTest |
| 147 @Feature({"TextInput"}) |
| 148 public void testPastePopupClearedOnTappingNonEmptyInput() throws Throwable { |
| 149 copyStringToClipboard(); |
| 150 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 151 assertWaitForPastePopupStatus(true); |
| 152 DOMUtils.clickNode(this, mContentViewCore, "input_text"); |
| 153 assertWaitForPastePopupStatus(false); |
| 154 } |
| 155 |
| 156 @SmallTest |
| 157 @Feature({"TextInput"}) |
| 158 public void testPastePopupClearedOnTappingOutsideInput() throws Throwable { |
| 159 copyStringToClipboard(); |
| 160 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 161 assertWaitForPastePopupStatus(true); |
| 162 DOMUtils.clickNode(this, mContentViewCore, "plain_text_2"); |
| 163 assertWaitForPastePopupStatus(false); |
| 164 } |
| 165 |
| 166 @SmallTest |
| 167 @Feature({"TextInput"}) |
| 168 public void testPastePopupClearedOnLongPressingOutsideInput() throws Throwab
le { |
| 169 copyStringToClipboard(); |
| 170 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 171 assertWaitForPastePopupStatus(true); |
| 172 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_2"); |
| 173 assertWaitForPastePopupStatus(false); |
| 174 } |
| 175 |
121 private void assertWaitForSelectActionBarVisible( | 176 private void assertWaitForSelectActionBarVisible( |
122 final boolean visible) throws InterruptedException { | 177 final boolean visible) throws InterruptedException { |
123 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | 178 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
124 @Override | 179 @Override |
125 public boolean isSatisfied() { | 180 public boolean isSatisfied() { |
126 return visible == mContentViewCore.isSelectActionBarShowing(); | 181 return visible == mContentViewCore.isSelectActionBarShowing(); |
127 } | 182 } |
128 })); | 183 })); |
129 } | 184 } |
130 | 185 |
(...skipping 27 matching lines...) Expand all Loading... |
158 | 213 |
159 private void requestFocusOnUiThread(final boolean gainFocus) { | 214 private void requestFocusOnUiThread(final boolean gainFocus) { |
160 final ContentViewCore contentViewCore = mContentViewCore; | 215 final ContentViewCore contentViewCore = mContentViewCore; |
161 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 216 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
162 @Override | 217 @Override |
163 public void run() { | 218 public void run() { |
164 contentViewCore.onFocusChanged(gainFocus); | 219 contentViewCore.onFocusChanged(gainFocus); |
165 } | 220 } |
166 }); | 221 }); |
167 } | 222 } |
| 223 |
| 224 private void copyStringToClipboard() { |
| 225 ClipboardManager clipboardManager = |
| 226 (ClipboardManager) getActivity().getSystemService( |
| 227 Context.CLIPBOARD_SERVICE); |
| 228 ClipData clip = ClipData.newPlainText("test", "Text to copy"); |
| 229 clipboardManager.setPrimaryClip(clip); |
| 230 } |
| 231 |
| 232 private void assertWaitForPastePopupStatus(final boolean show) throws Interr
uptedException { |
| 233 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| 234 @Override |
| 235 public boolean isSatisfied() { |
| 236 return show == mContentViewCore.getPastePopupForTest().isShowing
(); |
| 237 } |
| 238 })); |
| 239 } |
168 } | 240 } |
OLD | NEW |