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.android_webview.test.util; | 5 package org.chromium.android_webview.test.util; |
6 | 6 |
7 import android.test.InstrumentationTestCase; | 7 import android.test.InstrumentationTestCase; |
8 | 8 |
9 import junit.framework.Assert; | 9 import junit.framework.Assert; |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 t.printStackTrace(); | 40 t.printStackTrace(); |
41 Assert.fail("Failed to check if DOM is loaded: " + t.toStrin
g()); | 41 Assert.fail("Failed to check if DOM is loaded: " + t.toStrin
g()); |
42 return false; | 42 return false; |
43 } | 43 } |
44 } | 44 } |
45 }, WAIT_TIMEOUT_MS, CHECK_INTERVAL)); | 45 }, WAIT_TIMEOUT_MS, CHECK_INTERVAL)); |
46 | 46 |
47 testCase.getInstrumentation().runOnMainSync(new Runnable() { | 47 testCase.getInstrumentation().runOnMainSync(new Runnable() { |
48 @Override | 48 @Override |
49 public void run() { | 49 public void run() { |
50 awContents.getWebContents().evaluateJavaScriptForTests( | 50 awContents.getWebContents().evaluateJavaScript( |
51 "var evObj = document.createEvent('Events'); " | 51 "var evObj = document.createEvent('Events'); " |
52 + "evObj.initEvent('click', true, false); " | 52 + "evObj.initEvent('click', true, false); " |
53 + "document.getElementById('" + linkId + "').dis
patchEvent(evObj);" | 53 + "document.getElementById('" + linkId + "').dis
patchEvent(evObj);" |
54 + "console.log('element with id [" + linkId + "]
clicked');", | 54 + "console.log('element with id [" + linkId + "]
clicked');", |
55 null); | 55 null); |
56 } | 56 } |
57 }); | 57 }); |
58 } | 58 } |
59 | 59 |
60 public static String executeJavaScriptAndWaitForResult( | 60 public static String executeJavaScriptAndWaitForResult( |
61 InstrumentationTestCase testCase, | 61 InstrumentationTestCase testCase, |
62 final AwContents awContents, | 62 final AwContents awContents, |
63 final OnEvaluateJavaScriptResultHelper onEvaluateJavaScriptResultHel
per, | 63 final OnEvaluateJavaScriptResultHelper onEvaluateJavaScriptResultHel
per, |
64 final String code) throws Exception { | 64 final String code) throws Exception { |
65 testCase.getInstrumentation().runOnMainSync(new Runnable() { | 65 testCase.getInstrumentation().runOnMainSync(new Runnable() { |
66 @Override | 66 @Override |
67 public void run() { | 67 public void run() { |
68 onEvaluateJavaScriptResultHelper.evaluateJavaScriptForTests( | 68 onEvaluateJavaScriptResultHelper.evaluateJavaScript( |
69 awContents.getWebContents(), code); | 69 awContents.getWebContents(), code); |
70 } | 70 } |
71 }); | 71 }); |
72 onEvaluateJavaScriptResultHelper.waitUntilHasValue(); | 72 onEvaluateJavaScriptResultHelper.waitUntilHasValue(); |
73 Assert.assertTrue("Failed to retrieve JavaScript evaluation results.", | 73 Assert.assertTrue("Failed to retrieve JavaScript evaluation results.", |
74 onEvaluateJavaScriptResultHelper.hasValue()); | 74 onEvaluateJavaScriptResultHelper.hasValue()); |
75 return onEvaluateJavaScriptResultHelper.getJsonResultAndClear(); | 75 return onEvaluateJavaScriptResultHelper.getJsonResultAndClear(); |
76 } | 76 } |
77 } | 77 } |
OLD | NEW |