Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/ContentDetectionTestBase.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: Remove test that failed Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
8 8
9 import android.app.Activity; 9 import android.app.Activity;
10 import android.net.Uri; 10 import android.net.Uri;
11 11
12 import org.chromium.base.Log;
12 import org.chromium.base.test.util.CallbackHelper; 13 import org.chromium.base.test.util.CallbackHelper;
13 import org.chromium.base.test.util.UrlUtils; 14 import org.chromium.base.test.util.UrlUtils;
14 import org.chromium.content.browser.test.util.DOMUtils; 15 import org.chromium.content.browser.test.util.DOMUtils;
15 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; 16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
16 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage FinishedHelper; 17 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage FinishedHelper;
17 import org.chromium.content_shell.ShellViewAndroidDelegate.ContentIntentHandler; 18 import org.chromium.content_shell.ShellViewAndroidDelegate.ContentIntentHandler;
19 import org.chromium.content_shell_apk.ContentShellActivity;
18 import org.chromium.content_shell_apk.ContentShellTestBase; 20 import org.chromium.content_shell_apk.ContentShellTestBase;
19 21
20 import java.util.concurrent.TimeUnit; 22 import java.util.concurrent.TimeUnit;
21 23
22 /** 24 /**
23 * Base class for content detection test suites. 25 * Base class for content detection test suites.
24 */ 26 */
25 public class ContentDetectionTestBase extends ContentShellTestBase { 27 public class ContentDetectionTestBase extends ContentShellTestBase {
26 28
27 private static final long WAIT_TIMEOUT_SECONDS = scaleTimeout(10); 29 private static final long WAIT_TIMEOUT_SECONDS = 60;
28 30
29 private TestCallbackHelperContainer mCallbackHelper; 31 private TestCallbackHelperContainer mCallbackHelper;
30 private TestContentIntentHandler mContentIntentHandler; 32 private TestContentIntentHandler mContentIntentHandler;
31 33
32 /** 34 /**
33 * CallbackHelper for OnStartContentIntent. 35 * CallbackHelper for OnStartContentIntent.
34 */ 36 */
35 private static class OnStartContentIntentHelper extends CallbackHelper { 37 private static class OnStartContentIntentHelper extends CallbackHelper {
36 private String mIntentUrl; 38 private String mIntentUrl;
37 public void notifyCalled(String intentUrl) { 39 public void notifyCalled(String intentUrl) {
(...skipping 14 matching lines...) Expand all
52 54
53 public OnStartContentIntentHelper getOnStartContentIntentHelper() { 55 public OnStartContentIntentHelper getOnStartContentIntentHelper() {
54 if (mOnStartContentIntentHelper == null) { 56 if (mOnStartContentIntentHelper == null) {
55 mOnStartContentIntentHelper = new OnStartContentIntentHelper(); 57 mOnStartContentIntentHelper = new OnStartContentIntentHelper();
56 } 58 }
57 return mOnStartContentIntentHelper; 59 return mOnStartContentIntentHelper;
58 } 60 }
59 61
60 @Override 62 @Override
61 public void onIntentUrlReceived(String intentUrl) { 63 public void onIntentUrlReceived(String intentUrl) {
64 Log.d("#YOLAND", "called onIntentUrlReceived");
62 mOnStartContentIntentHelper.notifyCalled(intentUrl); 65 mOnStartContentIntentHelper.notifyCalled(intentUrl);
63 } 66 }
64 } 67 }
65 68
66 /** 69 /**
67 * Returns the TestCallbackHelperContainer associated with this ContentView, 70 * Returns the TestCallbackHelperContainer associated with this ContentView,
68 * or creates it lazily. 71 * or creates it lazily.
69 */ 72 */
70 protected TestCallbackHelperContainer getTestCallbackHelperContainer() { 73 protected TestCallbackHelperContainer getTestCallbackHelperContainer() {
71 if (mCallbackHelper == null) { 74 if (mCallbackHelper == null) {
72 mCallbackHelper = new TestCallbackHelperContainer(getContentViewCore ()); 75 mCallbackHelper = new TestCallbackHelperContainer(getContentViewCore ());
73 } 76 }
74 return mCallbackHelper; 77 return mCallbackHelper;
75 } 78 }
76 79
77 @Override 80 @Override
78 protected void setUp() throws Exception { 81 protected void setUp() throws Exception {
79 super.setUp(); 82 super.setUp();
83 Log.d("#YOLAND", "instantiating handler");
80 mContentIntentHandler = new TestContentIntentHandler(); 84 mContentIntentHandler = new TestContentIntentHandler();
81 } 85 }
82 86
83 @Override 87 @Override
84 protected void setActivity(Activity activity) { 88 protected void setActivity(Activity activity) {
89 Log.d("#YOLAND", "setActivity called");
85 super.setActivity(activity); 90 super.setActivity(activity);
91 Log.d("#YOLAND", "super.setActivity called");
86 getActivity() 92 getActivity()
87 .getShellManager() 93 .getShellManager()
88 .getActiveShell() 94 .getActiveShell()
89 .getViewAndroidDelegate() 95 .getViewAndroidDelegate()
90 .setContentIntentHandler(mContentIntentHandler); 96 .setContentIntentHandler(mContentIntentHandler);
91 } 97 }
92 98
99 @Override
100 public ContentShellActivity getActivity() {
101 Log.d("#YOLAND", "getActivity called");
102 return super.getActivity();
103 }
104
93 /** 105 /**
94 * Encodes the provided content string into an escaped url as intents do. 106 * Encodes the provided content string into an escaped url as intents do.
95 * @param content Content to escape into a url. 107 * @param content Content to escape into a url.
96 * @return Escaped url. 108 * @return Escaped url.
97 */ 109 */
98 protected static String urlForContent(String content) { 110 protected static String urlForContent(String content) {
99 return Uri.encode(content).replaceAll("%20", "+"); 111 return Uri.encode(content).replaceAll("%20", "+");
100 } 112 }
101 113
102 /** 114 /**
103 * Checks if the provided test url is the current url in the content view. 115 * Checks if the provided test url is the current url in the content view.
104 * @param testUrl Test url to check. 116 * @param testUrl Test url to check.
105 * @return true if the test url is the current one, false otherwise. 117 * @return true if the test url is the current one, false otherwise.
106 */ 118 */
107 protected boolean isCurrentTestUrl(String testUrl) { 119 protected boolean isCurrentTestUrl(String testUrl) {
108 return UrlUtils.getIsolatedTestFileUrl(testUrl).equals(getContentViewCor e() 120 return UrlUtils.getIsolatedTestFileUrl(testUrl).equals(getContentViewCor e()
109 .getWebContents().getUrl()); 121 .getWebContents().getUrl());
110 } 122 }
111 123
112 /** 124 /**
113 * Scrolls to the node with the provided id, taps on it and waits for an int ent to come. 125 * Scrolls to the node with the provided id, taps on it and waits for an int ent to come.
114 * @param id Id of the node to scroll and tap. 126 * @param id Id of the node to scroll and tap.
115 * @return The content url of the received intent or null if none. 127 * @return The content url of the received intent or null if none.
116 */ 128 */
117 protected String scrollAndTapExpectingIntent(String id) throws Throwable { 129 protected String scrollAndTapExpectingIntent(String id) throws Throwable {
118 OnStartContentIntentHelper onStartContentIntentHelper = 130 OnStartContentIntentHelper onStartContentIntentHelper =
119 mContentIntentHandler.getOnStartContentIntentHelper(); 131 mContentIntentHandler.getOnStartContentIntentHelper();
120 int currentCallCount = onStartContentIntentHelper.getCallCount(); 132 int currentCallCount = onStartContentIntentHelper.getCallCount();
121 133
122 DOMUtils.clickNode(getContentViewCore(), id); 134 Log.d("#YOLAND", "about to click, current count: " + Integer.toString(cu rrentCallCount));
135 //DOMUtils.clickNode(getContentViewCore(), id);
123 136
124 onStartContentIntentHelper.waitForCallback(currentCallCount, 1, WAIT_TIM EOUT_SECONDS, 137 onStartContentIntentHelper.waitForCallback(currentCallCount, 1, WAIT_TIM EOUT_SECONDS,
125 TimeUnit.SECONDS); 138 TimeUnit.SECONDS);
126 getInstrumentation().waitForIdleSync(); 139 getInstrumentation().waitForIdleSync();
127 return onStartContentIntentHelper.getIntentUrl(); 140 return onStartContentIntentHelper.getIntentUrl();
128 } 141 }
129 142
130 /** 143 /**
131 * Scrolls to the node with the provided id, taps on it and waits for a new page load to finish. 144 * Scrolls to the node with the provided id, taps on it and waits for a new page load to finish.
132 * Useful when tapping on links that take to other pages. 145 * Useful when tapping on links that take to other pages.
133 * @param id Id of the node to scroll and tap. 146 * @param id Id of the node to scroll and tap.
134 * @return The content url of the received intent or null if none. 147 * @return The content url of the received intent or null if none.
135 */ 148 */
136 protected void scrollAndTapNavigatingOut(String id) throws Throwable { 149 protected void scrollAndTapNavigatingOut(String id) throws Throwable {
137 TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHel perContainer(); 150 TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHel perContainer();
138 OnPageFinishedHelper onPageFinishedHelper = 151 OnPageFinishedHelper onPageFinishedHelper =
139 callbackHelperContainer.getOnPageFinishedHelper(); 152 callbackHelperContainer.getOnPageFinishedHelper();
140 int currentCallCount = onPageFinishedHelper.getCallCount(); 153 int currentCallCount = onPageFinishedHelper.getCallCount();
141 154
142 DOMUtils.clickNode(getContentViewCore(), id); 155 DOMUtils.clickNode(getContentViewCore(), id);
143 156
144 onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_S ECONDS, 157 onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_S ECONDS,
145 TimeUnit.SECONDS); 158 TimeUnit.SECONDS);
146 getInstrumentation().waitForIdleSync(); 159 getInstrumentation().waitForIdleSync();
147 } 160 }
148 } 161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698