OLD | NEW |
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.test.util; | 5 package org.chromium.content.browser.test.util; |
6 | 6 |
7 | 7 |
8 import org.chromium.base.ThreadUtils; | 8 import org.chromium.base.ThreadUtils; |
9 import org.chromium.content.browser.ContentViewCore; | 9 import org.chromium.content.browser.ContentViewCore; |
10 import org.chromium.content_public.browser.JavaScriptCallback; | 10 import org.chromium.content_public.browser.JavaScriptCallback; |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 * synchronously evaluate JavaScript and then test the result. | 119 * synchronously evaluate JavaScript and then test the result. |
120 */ | 120 */ |
121 public static class OnEvaluateJavaScriptResultHelper extends CallbackHelper
{ | 121 public static class OnEvaluateJavaScriptResultHelper extends CallbackHelper
{ |
122 private String mJsonResult; | 122 private String mJsonResult; |
123 | 123 |
124 /** | 124 /** |
125 * Starts evaluation of a given JavaScript code on a given webContents. | 125 * Starts evaluation of a given JavaScript code on a given webContents. |
126 * @param webContents A WebContents instance to be used. | 126 * @param webContents A WebContents instance to be used. |
127 * @param code A JavaScript code to be evaluated. | 127 * @param code A JavaScript code to be evaluated. |
128 */ | 128 */ |
129 public void evaluateJavaScriptForTests(WebContents webContents, String c
ode) { | 129 public void evaluateJavaScript(WebContents webContents, String code) { |
130 JavaScriptCallback callback = | 130 JavaScriptCallback callback = |
131 new JavaScriptCallback() { | 131 new JavaScriptCallback() { |
132 @Override | 132 @Override |
133 public void handleJavaScriptResult(String jsonResult) { | 133 public void handleJavaScriptResult(String jsonResult) { |
134 notifyCalled(jsonResult); | 134 notifyCalled(jsonResult); |
135 } | 135 } |
136 }; | 136 }; |
137 webContents.evaluateJavaScriptForTests(code, callback); | 137 webContents.evaluateJavaScript(code, callback); |
138 mJsonResult = null; | 138 mJsonResult = null; |
139 } | 139 } |
140 | 140 |
141 /** | 141 /** |
142 * Returns true if the evaluation started by evaluateJavaScriptForTests(
) has completed. | 142 * Returns true if the evaluation started by evaluateJavaScript() has co
mpleted. |
143 */ | 143 */ |
144 public boolean hasValue() { | 144 public boolean hasValue() { |
145 return mJsonResult != null; | 145 return mJsonResult != null; |
146 } | 146 } |
147 | 147 |
148 /** | 148 /** |
149 * Returns the JSON result of a previously completed JavaScript evaluati
on and | 149 * Returns the JSON result of a previously completed JavaScript evaluati
on and |
150 * resets the helper to accept new evaluations. | 150 * resets the helper to accept new evaluations. |
151 * @return String JSON result of a previously completed JavaScript evalu
ation. | 151 * @return String JSON result of a previously completed JavaScript evalu
ation. |
152 */ | 152 */ |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 216 } |
217 | 217 |
218 public OnReceivedErrorHelper getOnReceivedErrorHelper() { | 218 public OnReceivedErrorHelper getOnReceivedErrorHelper() { |
219 return mTestWebContentsObserver.getOnReceivedErrorHelper(); | 219 return mTestWebContentsObserver.getOnReceivedErrorHelper(); |
220 } | 220 } |
221 | 221 |
222 public OnStartContentIntentHelper getOnStartContentIntentHelper() { | 222 public OnStartContentIntentHelper getOnStartContentIntentHelper() { |
223 return mTestContentViewClient.getOnStartContentIntentHelper(); | 223 return mTestContentViewClient.getOnStartContentIntentHelper(); |
224 } | 224 } |
225 } | 225 } |
OLD | NEW |