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

Side by Side Diff: android_webview/javatests/src/org/chromium/android_webview/test/util/JSUtils.java

Issue 1257603003: Revert of Add ExecuteJavaScriptForTest and make all tests use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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.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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698