OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.annotation.TargetApi; |
7 import android.content.ClipData; | 8 import android.content.ClipData; |
8 import android.content.ClipboardManager; | 9 import android.content.ClipboardManager; |
9 import android.content.Context; | 10 import android.content.Context; |
10 import android.os.Build; | 11 import android.os.Build; |
11 import android.test.suitebuilder.annotation.LargeTest; | 12 import android.test.suitebuilder.annotation.LargeTest; |
12 import android.text.TextUtils; | 13 import android.text.TextUtils; |
13 | 14 |
14 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
15 import org.chromium.base.test.util.Feature; | 16 import org.chromium.base.test.util.Feature; |
16 import org.chromium.base.test.util.UrlUtils; | 17 import org.chromium.base.test.util.UrlUtils; |
(...skipping 23 matching lines...) Expand all Loading... |
40 launchContentShellWithUrl(TEST_PAGE_DATA_URL); | 41 launchContentShellWithUrl(TEST_PAGE_DATA_URL); |
41 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); | 42 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); |
42 } | 43 } |
43 | 44 |
44 /** | 45 /** |
45 * Tests that copying document fragments will put at least a plain-text repr
esentation | 46 * Tests that copying document fragments will put at least a plain-text repr
esentation |
46 * of the contents on the clipboard. For Android JellyBean and higher, we al
so expect | 47 * of the contents on the clipboard. For Android JellyBean and higher, we al
so expect |
47 * the HTML representation of the fragment to be available. | 48 * the HTML representation of the fragment to be available. |
48 */ | 49 */ |
49 @LargeTest | 50 @LargeTest |
| 51 @TargetApi(Build.VERSION_CODES.JELLY_BEAN) |
50 @Feature({"Clipboard","TextInput"}) | 52 @Feature({"Clipboard","TextInput"}) |
51 @RerunWithUpdatedContainerView | 53 @RerunWithUpdatedContainerView |
52 public void testCopyDocumentFragment() throws Throwable { | 54 public void testCopyDocumentFragment() throws Throwable { |
53 final ClipboardManager clipboardManager = (ClipboardManager) | 55 final ClipboardManager clipboardManager = (ClipboardManager) |
54 getActivity().getSystemService(Context.CLIPBOARD_SERVICE); | 56 getActivity().getSystemService(Context.CLIPBOARD_SERVICE); |
55 assertNotNull(clipboardManager); | 57 assertNotNull(clipboardManager); |
56 | 58 |
57 // Clear the clipboard to make sure we start with a clean state. | 59 // Clear the clipboard to make sure we start with a clean state. |
58 clipboardManager.setPrimaryClip(ClipData.newPlainText(null, "")); | 60 clipboardManager.setPrimaryClip(ClipData.newPlainText(null, "")); |
59 assertFalse(hasPrimaryClip(clipboardManager)); | 61 assertFalse(hasPrimaryClip(clipboardManager)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 111 |
110 // Returns whether there is a primary clip with content on the current clipb
oard. | 112 // Returns whether there is a primary clip with content on the current clipb
oard. |
111 private Boolean hasPrimaryClip(ClipboardManager clipboardManager) { | 113 private Boolean hasPrimaryClip(ClipboardManager clipboardManager) { |
112 final ClipData clip = clipboardManager.getPrimaryClip(); | 114 final ClipData clip = clipboardManager.getPrimaryClip(); |
113 if (clip != null && clip.getItemCount() > 0) { | 115 if (clip != null && clip.getItemCount() > 0) { |
114 return !TextUtils.isEmpty(clip.getItemAt(0).getText()); | 116 return !TextUtils.isEmpty(clip.getItemAt(0).getText()); |
115 } | 117 } |
116 | 118 |
117 return false; | 119 return false; |
118 } | 120 } |
119 } | 121 } |
OLD | NEW |