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 android.test.suitebuilder.annotation.LargeTest;
9 import org.chromium.base.test.util.Feature;
10 import org.chromium.base.test.util.UrlUtils;
11 import org.chromium.content.browser.test.util.DOMUtils;
12 import org.chromium.content_public.browser.WebContents;
13 import org.chromium.content_shell_apk.ContentShellTestBase;
16 * Integration tests for JavaScript execution.
18 public class TestsJavaScriptEvalTest extends ContentShellTestBase {
19 private static final String JSTEST_URL = UrlUtils.encodeHtmlDataUri(
20 "<html><head><script>" +
21 " function foobar() { return 'foobar'; }" +
23 "<body><button id=\"test\">Test button</button></body></html>");
25 public TestsJavaScriptEvalTest() {
29 * Tests that evaluation of JavaScript for test purposes (using JavaScriptUtils, DOMUtils etc)
30 * works even in presence of "background" (non-test-initiated) JavaScript evaluation activity.
34 public void testJavaScriptEvalIsCorrectlyOrdered()
35 throws InterruptedException, Exception, Throwable {
36 launchContentShellWithUrl(JSTEST_URL);
37 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
39 final WebContents webContents = getWebContents();
40 for (int i = 0; i < 30; ++i) {
41 for (int j = 0; j < 10; ++j) {
42 // Start evaluation of a JavaScript script -- we don't need a result.
43 webContents.evaluateJavaScript("foobar();", null);
45 // DOMUtils does need to evaluate a JavaScript and get its result to get DOM bounds.
46 assertNotNull("Failed to get bounds",
47 DOMUtils.getNodeBounds(webContents, "test"));