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.
5 package org.chromium.content.browser;
7 import junit.framework.Assert;
10 * Common functionality for testing the Java Bridge.
12 public class JavaBridgeTestBase extends ContentViewTestBase {
13 protected class Controller {
14 private boolean mIsResultReady;
16 protected synchronized void notifyResultIsReady() {
17 mIsResultReady = true;
20 protected synchronized void waitForResult() {
21 while (!mIsResultReady) {
24 } catch (Exception e) {
27 if (!mIsResultReady) {
28 Assert.fail("Wait timed out");
31 mIsResultReady = false;
35 protected void executeJavaScript(final String script) throws Throwable {
36 runTestOnUiThread(new Runnable() {
39 // When a JavaScript URL is executed, if the value of the last
40 // expression evaluated is not 'undefined', this value is
41 // converted to a string and used as the new document for the
42 // frame. We don't want this behaviour, so wrap the script in
43 // an anonymous function.
44 getContentViewCore().loadUrl(new LoadUrlParams(
45 "javascript:(function() { " + script + " })()"));