TestsJavaScriptEvalTest.java revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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 5package org.chromium.content.browser; 6 7import android.test.suitebuilder.annotation.LargeTest; 8 9import org.chromium.base.test.util.Feature; 10import org.chromium.base.test.util.UrlUtils; 11import org.chromium.content.browser.test.util.DOMUtils; 12import org.chromium.content.browser.test.util.TestCallbackHelperContainer; 13import org.chromium.content_shell_apk.ContentShellTestBase; 14 15public class TestsJavaScriptEvalTest extends ContentShellTestBase { 16 private static final String JSTEST_URL = UrlUtils.encodeHtmlDataUri( 17 "<html><head><script>" + 18 " function foobar() { return 'foobar'; }" + 19 "</script></head>" + 20 "<body><button id=\"test\">Test button</button></body></html>"); 21 22 public TestsJavaScriptEvalTest() { 23 } 24 25 /** 26 * Tests that evaluation of JavaScript for test purposes (using JavaScriptUtils, DOMUtils etc) 27 * works even in presence of "background" (non-test-initiated) JavaScript evaluation activity. 28 */ 29 @LargeTest 30 @Feature({"Browser"}) 31 public void testJavaScriptEvalIsCorrectlyOrdered() 32 throws InterruptedException, Exception, Throwable { 33 launchContentShellWithUrl(JSTEST_URL); 34 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); 35 36 final ContentView view = getActivity().getActiveContentView(); 37 final TestCallbackHelperContainer viewClient = 38 new TestCallbackHelperContainer(view); 39 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 view.evaluateJavaScript("foobar();"); 44 } 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(view, viewClient, "test")); 48 } 49 } 50} 51