JavaBridgeChildFrameTest.java revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5package org.chromium.content.browser; 6 7import android.test.suitebuilder.annotation.SmallTest; 8 9import org.chromium.base.test.util.Feature; 10 11/** 12 * Part of the test suite for the WebView's Java Bridge. 13 * 14 * Ensures that injected objects are exposed to child frames as well as the 15 * main frame. 16 */ 17public class JavaBridgeChildFrameTest extends JavaBridgeTestBase { 18 private class TestController extends Controller { 19 private String mStringValue; 20 21 public synchronized void setStringValue(String x) { 22 mStringValue = x; 23 notifyResultIsReady(); 24 } 25 public synchronized String waitForStringValue() { 26 waitForResult(); 27 return mStringValue; 28 } 29 } 30 31 TestController mTestController; 32 33 @Override 34 protected void setUp() throws Exception { 35 super.setUp(); 36 mTestController = new TestController(); 37 setUpContentView(mTestController, "testController"); 38 } 39 40 @SmallTest 41 @Feature({"AndroidWebView", "Android-JavaBridge"}) 42 public void testInjectedObjectPresentInChildFrame() throws Throwable { 43 // In the case that the test fails (i.e. the child frame doesn't get the injected object, 44 // the call to testController.setStringValue in the child frame's onload handler will 45 // not be made. 46 loadDataSync(getContentView(), 47 "<html><head></head><body>" + 48 "<iframe id=\"childFrame\" onload=\"testController.setStringValue('PASS');\" />" + 49 "</body></html>", "text/html", false); 50 assertEquals("PASS", mTestController.waitForStringValue()); 51 } 52} 53