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.chrome.browser; | 5 package org.chromium.chrome.browser; |
6 | 6 |
| 7 import android.graphics.Rect; |
7 import android.os.Bundle; | 8 import android.os.Bundle; |
8 import android.os.Handler; | 9 import android.os.Handler; |
9 import android.os.HandlerThread; | 10 import android.os.HandlerThread; |
10 import android.os.Message; | 11 import android.os.Message; |
11 import android.test.suitebuilder.annotation.MediumTest; | 12 import android.test.suitebuilder.annotation.MediumTest; |
12 | 13 |
13 import org.chromium.base.ThreadUtils; | 14 import org.chromium.base.ThreadUtils; |
14 import org.chromium.base.test.util.Feature; | 15 import org.chromium.base.test.util.Feature; |
15 import org.chromium.chrome.shell.ChromeShellActivity; | 16 import org.chromium.chrome.shell.ChromeShellActivity; |
16 import org.chromium.chrome.shell.ChromeShellTestBase; | 17 import org.chromium.chrome.shell.ChromeShellTestBase; |
17 import org.chromium.content.browser.ContentView; | 18 import org.chromium.content.browser.ContentView; |
18 import org.chromium.content.browser.test.util.CallbackHelper; | 19 import org.chromium.content.browser.test.util.CallbackHelper; |
19 | 20 |
20 import java.util.concurrent.TimeoutException; | 21 import java.util.concurrent.TimeoutException; |
21 | 22 |
22 /** | 23 /** |
23 * Tests for the ContentView. | 24 * Tests for the ContentView. |
24 */ | 25 */ |
25 public class ContentViewTest extends ChromeShellTestBase implements Handler.Call
back { | 26 public class ContentViewTest extends ChromeShellTestBase implements Handler.Call
back { |
26 | 27 |
27 private static class MyCallbackHelper extends CallbackHelper { | 28 private static class MyCallbackHelper extends CallbackHelper { |
28 public String getTitle() { | 29 public String getTitle() { |
29 return mTitle; | 30 return mTitle; |
30 } | 31 } |
31 | 32 |
32 public String getUrl() { | 33 public String getUrl() { |
33 return mUrl; | 34 return mUrl; |
34 } | 35 } |
35 | 36 |
36 public void notifyCalled(String title, String url) { | 37 public String getText() { |
| 38 return mText; |
| 39 } |
| 40 |
| 41 public String getHtml() { |
| 42 return mHtml; |
| 43 } |
| 44 |
| 45 public Rect getRect() { |
| 46 return mRect; |
| 47 } |
| 48 |
| 49 public void notifyCalled(String title, String url, String text, String h
tml, Rect rect) { |
37 mTitle = title; | 50 mTitle = title; |
38 mUrl = url; | 51 mUrl = url; |
| 52 mText = text; |
| 53 mHtml = html; |
| 54 mRect = rect; |
39 super.notifyCalled(); | 55 super.notifyCalled(); |
40 } | 56 } |
41 | 57 |
42 private String mTitle; | 58 private String mTitle; |
43 private String mUrl; | 59 private String mUrl; |
| 60 private String mText; |
| 61 private String mHtml; |
| 62 private Rect mRect; |
44 } | 63 } |
45 | 64 |
46 private ChromeShellActivity mActivity; | 65 private ChromeShellActivity mActivity; |
47 private MyCallbackHelper mCallbackHelper; | 66 private MyCallbackHelper mCallbackHelper; |
48 private HandlerThread mHandlerThread; | 67 private HandlerThread mHandlerThread; |
49 private Handler mHandler; | 68 private Handler mHandler; |
50 | 69 |
51 @Override | 70 @Override |
52 public void setUp() throws Exception { | 71 public void setUp() throws Exception { |
53 super.setUp(); | 72 super.setUp(); |
(...skipping 13 matching lines...) Expand all Loading... |
67 } | 86 } |
68 } | 87 } |
69 | 88 |
70 // Implements Handler.Callback | 89 // Implements Handler.Callback |
71 @Override | 90 @Override |
72 public boolean handleMessage(Message msg) { | 91 public boolean handleMessage(Message msg) { |
73 Bundle bundle = msg.getData(); | 92 Bundle bundle = msg.getData(); |
74 assertNotNull(bundle); | 93 assertNotNull(bundle); |
75 String url = bundle.getString("url"); | 94 String url = bundle.getString("url"); |
76 String title = bundle.getString("title"); | 95 String title = bundle.getString("title"); |
| 96 String text = bundle.getString("text"); |
| 97 String html = bundle.getString("html"); |
| 98 Rect rect = bundle.getParcelable("rect"); |
77 // We don't care about other values for now. | 99 // We don't care about other values for now. |
78 mCallbackHelper.notifyCalled(title, url); | 100 mCallbackHelper.notifyCalled(title, url, text, html, rect); |
79 return true; | 101 return true; |
80 } | 102 } |
81 | 103 |
82 @MediumTest | 104 @MediumTest |
83 @Feature({"SmartClip"}) | 105 @Feature({"SmartClip"}) |
84 public void testSmartClipDataCallback() throws InterruptedException, Timeout
Exception { | 106 public void testSmartClipDataCallback() throws InterruptedException, Timeout
Exception { |
85 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 107 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
86 @Override | 108 @Override |
87 public void run() { | 109 public void run() { |
88 ContentView cv = (ContentView) getActivity().getActiveTab().getV
iew(); | 110 ContentView cv = (ContentView) getActivity().getActiveTab().getV
iew(); |
89 assertNotNull(cv); | 111 assertNotNull(cv); |
90 cv.setSmartClipResultHandler(mHandler); | 112 cv.setSmartClipResultHandler(mHandler); |
91 cv.extractSmartClipData(10, 20, 100, 70); | 113 cv.extractSmartClipData(10, 20, 100, 70); |
92 } | 114 } |
93 }); | 115 }); |
94 mCallbackHelper.waitForCallback(0, 1); // call count: 0 --> 1 | 116 mCallbackHelper.waitForCallback(0, 1); // call count: 0 --> 1 |
95 assertNotNull("about:blank", mCallbackHelper.getTitle()); | 117 assertEquals("about:blank", mCallbackHelper.getTitle()); |
96 assertNotNull("about:blank", mCallbackHelper.getUrl()); | 118 assertEquals("about:blank", mCallbackHelper.getUrl()); |
| 119 assertNotNull(mCallbackHelper.getText()); |
| 120 assertNotNull(mCallbackHelper.getHtml()); |
| 121 assertNotNull(mCallbackHelper.getRect()); |
97 } | 122 } |
98 } | 123 } |
OLD | NEW |