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.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
10 import org.chromium.base.test.util.UrlUtils; | 13 import org.chromium.base.test.util.UrlUtils; |
11 import org.chromium.content.browser.test.util.Criteria; | 14 import org.chromium.content.browser.test.util.Criteria; |
12 import org.chromium.content.browser.test.util.CriteriaHelper; | 15 import org.chromium.content.browser.test.util.CriteriaHelper; |
13 import org.chromium.content.browser.test.util.DOMUtils; | 16 import org.chromium.content.browser.test.util.DOMUtils; |
14 import org.chromium.content_shell_apk.ContentShellTestBase; | 17 import org.chromium.content_shell_apk.ContentShellTestBase; |
15 | 18 |
16 /** | 19 /** |
(...skipping 18 matching lines...) Expand all Loading... |
35 @Override | 38 @Override |
36 public void setUp() throws Exception { | 39 public void setUp() throws Exception { |
37 super.setUp(); | 40 super.setUp(); |
38 | 41 |
39 launchContentShellWithUrl(DATA_URL); | 42 launchContentShellWithUrl(DATA_URL); |
40 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); | 43 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); |
41 | 44 |
42 mContentViewCore = getContentViewCore(); | 45 mContentViewCore = getContentViewCore(); |
43 assertWaitForPageScaleFactorMatch(1.1f); | 46 assertWaitForPageScaleFactorMatch(1.1f); |
44 assertWaitForSelectActionBarStatus(false); | 47 assertWaitForSelectActionBarStatus(false); |
| 48 assertWaitForPastePopupStatus(false); |
45 } | 49 } |
46 | 50 |
47 @SmallTest | 51 @SmallTest |
48 @Feature({"TextSelection"}) | 52 @Feature({"TextSelection"}) |
49 public void testSelectActionBarShownOnLongPressingPlainText() throws Excepti
on { | 53 public void testSelectActionBarShownOnLongPressingPlainText() throws Excepti
on { |
50 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); | 54 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); |
51 assertWaitForSelectActionBarStatus(true); | 55 assertWaitForSelectActionBarStatus(true); |
52 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); | 56 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
53 assertWaitForSelectActionBarStatus(false); | 57 assertWaitForSelectActionBarStatus(false); |
54 } | 58 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); | 90 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); |
87 assertWaitForSelectActionBarStatus(true); | 91 assertWaitForSelectActionBarStatus(true); |
88 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); | 92 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
89 assertWaitForSelectActionBarStatus(false); | 93 assertWaitForSelectActionBarStatus(false); |
90 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_2"); | 94 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_2"); |
91 assertWaitForSelectActionBarStatus(true); | 95 assertWaitForSelectActionBarStatus(true); |
92 DOMUtils.longPressNode(this, mContentViewCore, "empty_textarea"); | 96 DOMUtils.longPressNode(this, mContentViewCore, "empty_textarea"); |
93 assertWaitForSelectActionBarStatus(false); | 97 assertWaitForSelectActionBarStatus(false); |
94 } | 98 } |
95 | 99 |
| 100 @SmallTest |
| 101 @Feature({"TextInput"}) |
| 102 public void testPastePopupNotShownOnLongPressingNonEmptyInput() throws Throw
able { |
| 103 copyStringToClipboard(); |
| 104 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 105 assertWaitForPastePopupStatus(true); |
| 106 DOMUtils.longPressNode(this, mContentViewCore, "input_text"); |
| 107 assertWaitForSelectActionBarStatus(true); |
| 108 assertWaitForPastePopupStatus(false); |
| 109 } |
| 110 |
| 111 @SmallTest |
| 112 @Feature({"TextInput"}) |
| 113 public void testPastePopupClearedOnTappingEmptyInput() throws Throwable { |
| 114 copyStringToClipboard(); |
| 115 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 116 assertWaitForPastePopupStatus(true); |
| 117 DOMUtils.clickNode(this, mContentViewCore, "empty_input_text"); |
| 118 assertWaitForPastePopupStatus(false); |
| 119 } |
| 120 |
| 121 @SmallTest |
| 122 @Feature({"TextInput"}) |
| 123 public void testPastePopupClearedOnTappingNonEmptyInput() throws Throwable { |
| 124 copyStringToClipboard(); |
| 125 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 126 assertWaitForPastePopupStatus(true); |
| 127 DOMUtils.clickNode(this, mContentViewCore, "input_text"); |
| 128 assertWaitForPastePopupStatus(false); |
| 129 } |
| 130 |
| 131 @SmallTest |
| 132 @Feature({"TextInput"}) |
| 133 public void testPastePopupClearedOnTappingOutsideInput() throws Throwable { |
| 134 copyStringToClipboard(); |
| 135 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 136 assertWaitForPastePopupStatus(true); |
| 137 DOMUtils.clickNode(this, mContentViewCore, "plain_text_2"); |
| 138 assertWaitForPastePopupStatus(false); |
| 139 } |
| 140 |
| 141 @SmallTest |
| 142 @Feature({"TextInput"}) |
| 143 public void testPastePopupClearedOnLongPressingOutsideInput() throws Throwab
le { |
| 144 copyStringToClipboard(); |
| 145 DOMUtils.longPressNode(this, mContentViewCore, "empty_input_text"); |
| 146 assertWaitForPastePopupStatus(true); |
| 147 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_2"); |
| 148 assertWaitForPastePopupStatus(false); |
| 149 } |
| 150 |
| 151 private void copyStringToClipboard() { |
| 152 ClipboardManager clipboardManager = |
| 153 (ClipboardManager) getActivity().getSystemService( |
| 154 Context.CLIPBOARD_SERVICE); |
| 155 ClipData clip = ClipData.newPlainText("test", "Text to copy"); |
| 156 clipboardManager.setPrimaryClip(clip); |
| 157 } |
| 158 |
| 159 private void assertWaitForPastePopupStatus(final boolean show) throws Interr
uptedException { |
| 160 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| 161 @Override |
| 162 public boolean isSatisfied() { |
| 163 return show == mContentViewCore.getPastePopupForTest().isShowing
(); |
| 164 } |
| 165 })); |
| 166 } |
| 167 |
96 private void assertWaitForSelectActionBarStatus( | 168 private void assertWaitForSelectActionBarStatus( |
97 final boolean show) throws InterruptedException { | 169 final boolean show) throws InterruptedException { |
98 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | 170 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
99 @Override | 171 @Override |
100 public boolean isSatisfied() { | 172 public boolean isSatisfied() { |
101 return show == mContentViewCore.isSelectActionBarShowing(); | 173 return show == mContentViewCore.isSelectActionBarShowing(); |
102 } | 174 } |
103 })); | 175 })); |
104 } | 176 } |
105 } | 177 } |
OLD | NEW |