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 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; | 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; |
8 | 8 |
9 import junit.framework.Assert; | 9 import junit.framework.Assert; |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 final TimeUnit timeoutUnits) | 43 final TimeUnit timeoutUnits) |
44 throws InterruptedException, TimeoutException { | 44 throws InterruptedException, TimeoutException { |
45 final OnEvaluateJavaScriptResultHelper helper = new OnEvaluateJavaScript
ResultHelper(); | 45 final OnEvaluateJavaScriptResultHelper helper = new OnEvaluateJavaScript
ResultHelper(); |
46 // Calling this from the UI thread causes it to time-out: the UI thread
being blocked won't | 46 // Calling this from the UI thread causes it to time-out: the UI thread
being blocked won't |
47 // have a chance to process the JavaScript eval response). | 47 // have a chance to process the JavaScript eval response). |
48 Assert.assertFalse("Executing JavaScript should be done from the test th
read, " | 48 Assert.assertFalse("Executing JavaScript should be done from the test th
read, " |
49 + " not the UI thread", ThreadUtils.runningOnUiThread()); | 49 + " not the UI thread", ThreadUtils.runningOnUiThread()); |
50 ThreadUtils.runOnUiThread(new Runnable() { | 50 ThreadUtils.runOnUiThread(new Runnable() { |
51 @Override | 51 @Override |
52 public void run() { | 52 public void run() { |
53 helper.evaluateJavaScriptForTests(webContents, code); | 53 helper.evaluateJavaScript(webContents, code); |
54 } | 54 } |
55 }); | 55 }); |
56 helper.waitUntilHasValue(timeout, timeoutUnits); | 56 helper.waitUntilHasValue(timeout, timeoutUnits); |
57 Assert.assertTrue("Failed to retrieve JavaScript evaluation results.", h
elper.hasValue()); | 57 Assert.assertTrue("Failed to retrieve JavaScript evaluation results.", h
elper.hasValue()); |
58 return helper.getJsonResultAndClear(); | 58 return helper.getJsonResultAndClear(); |
59 } | 59 } |
60 | 60 |
61 /** | 61 /** |
62 * Executes the given snippet of JavaScript code but does not wait for the r
esult. | 62 * Executes the given snippet of JavaScript code but does not wait for the r
esult. |
63 */ | 63 */ |
64 public static void executeJavaScript(final WebContents webContents, final St
ring code) { | 64 public static void executeJavaScript(final WebContents webContents, final St
ring code) { |
65 ThreadUtils.runOnUiThread(new Runnable() { | 65 ThreadUtils.runOnUiThread(new Runnable() { |
66 @Override | 66 @Override |
67 public void run() { | 67 public void run() { |
68 webContents.evaluateJavaScriptForTests(code, null); | 68 webContents.evaluateJavaScript(code, null); |
69 } | 69 } |
70 }); | 70 }); |
71 } | 71 } |
72 } | 72 } |
OLD | NEW |