Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / public / android / javatests / src / org / chromium / content / browser / JavaBridgeChildFrameTest.java
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
3 // found in the LICENSE file.
4
5 package org.chromium.content.browser;
6
7 import android.test.suitebuilder.annotation.SmallTest;
8
9 import 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  */
17 public class JavaBridgeChildFrameTest extends JavaBridgeTestBase {
18     private class TestController extends Controller {
19         private String mStringValue;
20
21     @SuppressWarnings("unused")  // Called via reflection
22     public synchronized void setStringValue(String x) {
23             mStringValue = x;
24             notifyResultIsReady();
25         }
26        public synchronized String waitForStringValue() {
27             waitForResult();
28             return mStringValue;
29         }
30     }
31
32     TestController mTestController;
33
34     @Override
35     protected void setUp() throws Exception {
36         super.setUp();
37         mTestController = new TestController();
38         setUpContentView(mTestController, "testController");
39     }
40
41     @SmallTest
42     @Feature({"AndroidWebView", "Android-JavaBridge"})
43     public void testInjectedObjectPresentInChildFrame() throws Throwable {
44         // In the case that the test fails (i.e. the child frame doesn't get the injected object,
45         // the call to testController.setStringValue in the child frame's onload handler will
46         // not be made.
47         loadDataSync(getContentViewCore(),
48                 "<html><head></head><body>" +
49                 "<iframe id=\"childFrame\" onload=\"testController.setStringValue('PASS');\" />" +
50                 "</body></html>", "text/html", false);
51         assertEquals("PASS", mTestController.waitForStringValue());
52     }
53 }