OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.input; | 5 package org.chromium.content.browser.input; |
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.ClipData; | 9 import android.content.ClipData; |
10 import android.content.ClipboardManager; | 10 import android.content.ClipboardManager; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 int restartCount = mInputMethodManagerWrapper.getRestartInputCounter(); | 190 int restartCount = mInputMethodManagerWrapper.getRestartInputCounter(); |
191 Integer[] history = mConnectionFactory.getTextInputTypeHistory(); | 191 Integer[] history = mConnectionFactory.getTextInputTypeHistory(); |
192 return stringifyKeyboardStates(showCount, hideCount, restartCount, histo
ry); | 192 return stringifyKeyboardStates(showCount, hideCount, restartCount, histo
ry); |
193 } | 193 } |
194 | 194 |
195 String stringifyKeyboardStates(int show, int hide, int restart, Integer[] hi
story) { | 195 String stringifyKeyboardStates(int show, int hide, int restart, Integer[] hi
story) { |
196 return "show count: " + show + ", hide count: " + hide + ", restart coun
t: " + restart | 196 return "show count: " + show + ", hide count: " + hide + ", restart coun
t: " + restart |
197 + ", input type history: " + Arrays.deepToString(history); | 197 + ", input type history: " + Arrays.deepToString(history); |
198 } | 198 } |
199 | 199 |
| 200 void performEditorAction(final int action) { |
| 201 mConnection.performEditorAction(action); |
| 202 } |
| 203 |
200 void performGo(TestCallbackHelperContainer testCallbackHelperContainer) thro
ws Throwable { | 204 void performGo(TestCallbackHelperContainer testCallbackHelperContainer) thro
ws Throwable { |
201 final InputConnection inputConnection = mConnection; | 205 final InputConnection inputConnection = mConnection; |
202 final Callable<Void> callable = new Callable<Void>() { | 206 final Callable<Void> callable = new Callable<Void>() { |
203 @Override | 207 @Override |
204 public Void call() throws Exception { | 208 public Void call() throws Exception { |
205 inputConnection.performEditorAction(EditorInfo.IME_ACTION_GO); | 209 inputConnection.performEditorAction(EditorInfo.IME_ACTION_GO); |
206 return null; | 210 return null; |
207 } | 211 } |
208 }; | 212 }; |
209 | 213 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 return states.size() > index; | 259 return states.size() > index; |
256 } | 260 } |
257 }); | 261 }); |
258 Pair<Range, Range> selection = states.get(index); | 262 Pair<Range, Range> selection = states.get(index); |
259 Assert.assertEquals(selectionStart, selection.first.start()); | 263 Assert.assertEquals(selectionStart, selection.first.start()); |
260 Assert.assertEquals(selectionEnd, selection.first.end()); | 264 Assert.assertEquals(selectionEnd, selection.first.end()); |
261 Assert.assertEquals(compositionStart, selection.second.start()); | 265 Assert.assertEquals(compositionStart, selection.second.start()); |
262 Assert.assertEquals(compositionEnd, selection.second.end()); | 266 Assert.assertEquals(compositionEnd, selection.second.end()); |
263 } | 267 } |
264 | 268 |
265 void resetUpdateSelectionList() { | |
266 mInputMethodManagerWrapper.getUpdateSelectionList().clear(); | |
267 } | |
268 | |
269 void assertClipboardContents(final Activity activity, final String expectedC
ontents) { | 269 void assertClipboardContents(final Activity activity, final String expectedC
ontents) { |
270 CriteriaHelper.pollUiThread(new Criteria() { | 270 CriteriaHelper.pollUiThread(new Criteria() { |
271 @Override | 271 @Override |
272 public boolean isSatisfied() { | 272 public boolean isSatisfied() { |
273 ClipboardManager clipboardManager = | 273 ClipboardManager clipboardManager = |
274 (ClipboardManager) activity.getSystemService(Context.CLI
PBOARD_SERVICE); | 274 (ClipboardManager) activity.getSystemService(Context.CLI
PBOARD_SERVICE); |
275 ClipData clip = clipboardManager.getPrimaryClip(); | 275 ClipData clip = clipboardManager.getPrimaryClip(); |
276 return clip != null && clip.getItemCount() == 1 | 276 return clip != null && clip.getItemCount() == 1 |
277 && TextUtils.equals(clip.getItemAt(0).getText(), expecte
dContents); | 277 && TextUtils.equals(clip.getItemAt(0).getText(), expecte
dContents); |
278 } | 278 } |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 523 } |
524 }); | 524 }); |
525 } | 525 } |
526 | 526 |
527 /** | 527 /** |
528 * Focus element, wait for a single state update, reset state update list. | 528 * Focus element, wait for a single state update, reset state update list. |
529 * @param id ID of the element to focus. | 529 * @param id ID of the element to focus. |
530 */ | 530 */ |
531 void focusElementAndWaitForStateUpdate(String id) | 531 void focusElementAndWaitForStateUpdate(String id) |
532 throws InterruptedException, TimeoutException { | 532 throws InterruptedException, TimeoutException { |
533 resetUpdateSelectionList(); | 533 resetAllStates(); |
534 focusElement(id); | 534 focusElement(id); |
535 waitAndVerifyUpdateSelection(0, 0, 0, -1, -1); | 535 waitAndVerifyUpdateSelection(0, 0, 0, -1, -1); |
536 resetUpdateSelectionList(); | 536 resetAllStates(); |
537 } | 537 } |
538 | 538 |
539 void focusElement(final String id) throws InterruptedException, TimeoutExcep
tion { | 539 void focusElement(final String id) throws InterruptedException, TimeoutExcep
tion { |
540 focusElement(id, true); | 540 focusElement(id, true); |
541 } | 541 } |
542 | 542 |
543 void focusElement(final String id, boolean shouldShowKeyboard) | 543 void focusElement(final String id, boolean shouldShowKeyboard) |
544 throws InterruptedException, TimeoutException { | 544 throws InterruptedException, TimeoutException { |
545 DOMUtils.focusNode(getWebContents(), id); | 545 DOMUtils.focusNode(getWebContents(), id); |
546 assertWaitForKeyboardStatus(shouldShowKeyboard); | 546 assertWaitForKeyboardStatus(shouldShowKeyboard); |
(...skipping 16 matching lines...) Expand all Loading... |
563 public TestInputConnectionFactory(ChromiumBaseInputConnection.Factory fa
ctory) { | 563 public TestInputConnectionFactory(ChromiumBaseInputConnection.Factory fa
ctory) { |
564 mFactory = factory; | 564 mFactory = factory; |
565 } | 565 } |
566 | 566 |
567 @Override | 567 @Override |
568 public ChromiumBaseInputConnection initializeAndGet(View view, ImeAdapte
r imeAdapter, | 568 public ChromiumBaseInputConnection initializeAndGet(View view, ImeAdapte
r imeAdapter, |
569 int inputType, int inputFlags, int inputMode, int selectionStart
, int selectionEnd, | 569 int inputType, int inputFlags, int inputMode, int selectionStart
, int selectionEnd, |
570 EditorInfo outAttrs) { | 570 EditorInfo outAttrs) { |
571 mTextInputTypeList.add(inputType); | 571 mTextInputTypeList.add(inputType); |
572 mOutAttrs = outAttrs; | 572 mOutAttrs = outAttrs; |
573 return mFactory.initializeAndGet(view, imeAdapter, inputType, inputM
ode, inputFlags, | 573 return mFactory.initializeAndGet(view, imeAdapter, inputType, inputF
lags, inputMode, |
574 selectionStart, selectionEnd, outAttrs); | 574 selectionStart, selectionEnd, outAttrs); |
575 } | 575 } |
576 | 576 |
577 @Override | 577 @Override |
578 public Handler getHandler() { | 578 public Handler getHandler() { |
579 return mFactory.getHandler(); | 579 return mFactory.getHandler(); |
580 } | 580 } |
581 | 581 |
582 public Integer[] getTextInputTypeHistory() { | 582 public Integer[] getTextInputTypeHistory() { |
583 Integer[] result = new Integer[mTextInputTypeList.size()]; | 583 Integer[] result = new Integer[mTextInputTypeList.size()]; |
(...skipping 23 matching lines...) Expand all Loading... |
607 public void onViewAttachedToWindow() { | 607 public void onViewAttachedToWindow() { |
608 mFactory.onViewAttachedToWindow(); | 608 mFactory.onViewAttachedToWindow(); |
609 } | 609 } |
610 | 610 |
611 @Override | 611 @Override |
612 public void onViewDetachedFromWindow() { | 612 public void onViewDetachedFromWindow() { |
613 mFactory.onViewDetachedFromWindow(); | 613 mFactory.onViewDetachedFromWindow(); |
614 } | 614 } |
615 } | 615 } |
616 } | 616 } |
OLD | NEW |