| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.content.browser; | 5 package org.chromium.content.browser; |
| 6 | 6 |
| 7 import android.test.suitebuilder.annotation.LargeTest; | 7 import android.test.suitebuilder.annotation.LargeTest; |
| 8 | 8 |
| 9 import org.chromium.base.test.util.Feature; | 9 import org.chromium.base.test.util.Feature; |
| 10 import org.chromium.base.test.util.UrlUtils; | 10 import org.chromium.base.test.util.UrlUtils; |
| 11 import org.chromium.content.browser.test.util.DOMUtils; | 11 import org.chromium.content.browser.test.util.DOMUtils; |
| 12 import org.chromium.content_public.browser.WebContents; |
| 12 import org.chromium.content_shell_apk.ContentShellTestBase; | 13 import org.chromium.content_shell_apk.ContentShellTestBase; |
| 13 | 14 |
| 15 /** |
| 16 * Integration tests for JavaScript execution. |
| 17 */ |
| 14 public class TestsJavaScriptEvalTest extends ContentShellTestBase { | 18 public class TestsJavaScriptEvalTest extends ContentShellTestBase { |
| 15 private static final String JSTEST_URL = UrlUtils.encodeHtmlDataUri( | 19 private static final String JSTEST_URL = UrlUtils.encodeHtmlDataUri( |
| 16 "<html><head><script>" + | 20 "<html><head><script>" + |
| 17 " function foobar() { return 'foobar'; }" + | 21 " function foobar() { return 'foobar'; }" + |
| 18 "</script></head>" + | 22 "</script></head>" + |
| 19 "<body><button id=\"test\">Test button</button></body></html>"); | 23 "<body><button id=\"test\">Test button</button></body></html>"); |
| 20 | 24 |
| 21 public TestsJavaScriptEvalTest() { | 25 public TestsJavaScriptEvalTest() { |
| 22 } | 26 } |
| 23 | 27 |
| 24 /** | 28 /** |
| 25 * Tests that evaluation of JavaScript for test purposes (using JavaScriptUt
ils, DOMUtils etc) | 29 * Tests that evaluation of JavaScript for test purposes (using JavaScriptUt
ils, DOMUtils etc) |
| 26 * works even in presence of "background" (non-test-initiated) JavaScript ev
aluation activity. | 30 * works even in presence of "background" (non-test-initiated) JavaScript ev
aluation activity. |
| 27 */ | 31 */ |
| 28 @LargeTest | 32 @LargeTest |
| 29 @Feature({"Browser"}) | 33 @Feature({"Browser"}) |
| 30 public void testJavaScriptEvalIsCorrectlyOrdered() | 34 public void testJavaScriptEvalIsCorrectlyOrdered() |
| 31 throws InterruptedException, Exception, Throwable { | 35 throws InterruptedException, Exception, Throwable { |
| 32 launchContentShellWithUrl(JSTEST_URL); | 36 launchContentShellWithUrl(JSTEST_URL); |
| 33 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); | 37 assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading()); |
| 34 | 38 |
| 35 final ContentViewCore contentViewCore = getContentViewCore(); | 39 final WebContents webContents = getWebContents(); |
| 36 for (int i = 0; i < 30; ++i) { | 40 for (int i = 0; i < 30; ++i) { |
| 37 for (int j = 0; j < 10; ++j) { | 41 for (int j = 0; j < 10; ++j) { |
| 38 // Start evaluation of a JavaScript script -- we don't need a re
sult. | 42 // Start evaluation of a JavaScript script -- we don't need a re
sult. |
| 39 contentViewCore.evaluateJavaScript("foobar();", null); | 43 webContents.evaluateJavaScript("foobar();", null); |
| 40 } | 44 } |
| 41 // DOMUtils does need to evaluate a JavaScript and get its result to
get DOM bounds. | 45 // DOMUtils does need to evaluate a JavaScript and get its result to
get DOM bounds. |
| 42 assertNotNull("Failed to get bounds", | 46 assertNotNull("Failed to get bounds", |
| 43 DOMUtils.getNodeBounds(contentViewCore, "test")); | 47 DOMUtils.getNodeBounds(webContents, "test")); |
| 44 } | 48 } |
| 45 } | 49 } |
| 46 } | 50 } |
| OLD | NEW |