| 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; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.SmallTest; | 7 import android.test.suitebuilder.annotation.SmallTest; |
| 8 | 8 |
| 9 import org.chromium.base.test.util.Feature; | 9 import org.chromium.base.test.util.Feature; |
| 10 import org.chromium.content_public.browser.JavaScriptCallback; |
| 10 | 11 |
| 11 /** | 12 /** |
| 12 * Part of the test suite for the WebView's Java Bridge. | 13 * Part of the test suite for the WebView's Java Bridge. |
| 13 * | 14 * |
| 14 * Ensures that injected objects are exposed to child frames as well as the | 15 * Ensures that injected objects are exposed to child frames as well as the |
| 15 * main frame. | 16 * main frame. |
| 16 */ | 17 */ |
| 17 public class JavaBridgeChildFrameTest extends JavaBridgeTestBase { | 18 public class JavaBridgeChildFrameTest extends JavaBridgeTestBase { |
| 18 private class TestController extends Controller { | 19 private class TestController extends Controller { |
| 19 private String mStringValue; | 20 private String mStringValue; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 executeJavaScriptAndGetResult(getContentViewCore(), "queryProper
ties(window)")); | 97 executeJavaScriptAndGetResult(getContentViewCore(), "queryProper
ties(window)")); |
| 97 assertEquals("\"undefined / undefined\"", | 98 assertEquals("\"undefined / undefined\"", |
| 98 executeJavaScriptAndGetResult(getContentViewCore(), | 99 executeJavaScriptAndGetResult(getContentViewCore(), |
| 99 "queryProperties(window.frames[0])")); | 100 "queryProperties(window.frames[0])")); |
| 100 } | 101 } |
| 101 | 102 |
| 102 private String executeJavaScriptAndGetResult(final ContentViewCore contentVi
ewCore, | 103 private String executeJavaScriptAndGetResult(final ContentViewCore contentVi
ewCore, |
| 103 final String script) throws Throwable { | 104 final String script) throws Throwable { |
| 104 final String[] result = new String[1]; | 105 final String[] result = new String[1]; |
| 105 class ResultCallback extends JavaBridgeTestBase.Controller | 106 class ResultCallback extends JavaBridgeTestBase.Controller |
| 106 implements ContentViewCore.JavaScriptCallback { | 107 implements JavaScriptCallback { |
| 107 @Override | 108 @Override |
| 108 public void handleJavaScriptResult(String jsonResult) { | 109 public void handleJavaScriptResult(String jsonResult) { |
| 109 result[0] = jsonResult; | 110 result[0] = jsonResult; |
| 110 notifyResultIsReady(); | 111 notifyResultIsReady(); |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 final ResultCallback resultCallback = new ResultCallback(); | 114 final ResultCallback resultCallback = new ResultCallback(); |
| 114 runTestOnUiThread(new Runnable() { | 115 runTestOnUiThread(new Runnable() { |
| 115 @Override | 116 @Override |
| 116 public void run() { | 117 public void run() { |
| 117 contentViewCore.evaluateJavaScript(script, resultCallback); | 118 contentViewCore.evaluateJavaScript(script, resultCallback); |
| 118 } | 119 } |
| 119 }); | 120 }); |
| 120 resultCallback.waitForResult(); | 121 resultCallback.waitForResult(); |
| 121 return result[0]; | 122 return result[0]; |
| 122 } | 123 } |
| 123 } | 124 } |
| OLD | NEW |