| 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.support.test.filters.LargeTest; | 7 import android.support.test.filters.LargeTest; |
| 8 | 8 |
| 9 import org.junit.Assert; |
| 10 import org.junit.Rule; |
| 11 import org.junit.Test; |
| 12 import org.junit.runner.RunWith; |
| 13 |
| 14 import org.chromium.base.test.BaseJUnit4ClassRunner; |
| 9 import org.chromium.base.test.util.Feature; | 15 import org.chromium.base.test.util.Feature; |
| 10 import org.chromium.base.test.util.UrlUtils; | 16 import org.chromium.base.test.util.UrlUtils; |
| 11 import org.chromium.content.browser.test.util.DOMUtils; | 17 import org.chromium.content.browser.test.util.DOMUtils; |
| 12 import org.chromium.content_public.browser.WebContents; | 18 import org.chromium.content_public.browser.WebContents; |
| 13 import org.chromium.content_shell_apk.ContentShellTestBase; | 19 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
| 14 | 20 |
| 15 /** | 21 /** |
| 16 * Integration tests for JavaScript execution. | 22 * Integration tests for JavaScript execution. |
| 17 */ | 23 */ |
| 18 public class TestsJavaScriptEvalTest extends ContentShellTestBase { | 24 @RunWith(BaseJUnit4ClassRunner.class) |
| 25 public class TestsJavaScriptEvalTest { |
| 26 @Rule |
| 27 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 28 |
| 19 private static final String JSTEST_URL = UrlUtils.encodeHtmlDataUri("<html><
head><script>" | 29 private static final String JSTEST_URL = UrlUtils.encodeHtmlDataUri("<html><
head><script>" |
| 20 + " function foobar() { return 'foobar'; }" | 30 + " function foobar() { return 'foobar'; }" |
| 21 + "</script></head>" | 31 + "</script></head>" |
| 22 + "<body><button id=\"test\">Test button</button></body></html>"); | 32 + "<body><button id=\"test\">Test button</button></body></html>"); |
| 23 | 33 |
| 24 public TestsJavaScriptEvalTest() { | 34 public TestsJavaScriptEvalTest() { |
| 25 } | 35 } |
| 26 | 36 |
| 27 /** | 37 /** |
| 28 * Tests that evaluation of JavaScript for test purposes (using JavaScriptUt
ils, DOMUtils etc) | 38 * Tests that evaluation of JavaScript for test purposes (using JavaScriptUt
ils, DOMUtils etc) |
| 29 * works even in presence of "background" (non-test-initiated) JavaScript ev
aluation activity. | 39 * works even in presence of "background" (non-test-initiated) JavaScript ev
aluation activity. |
| 30 */ | 40 */ |
| 41 @Test |
| 31 @LargeTest | 42 @LargeTest |
| 32 @Feature({"Browser"}) | 43 @Feature({"Browser"}) |
| 33 public void testJavaScriptEvalIsCorrectlyOrdered() | 44 public void testJavaScriptEvalIsCorrectlyOrdered() |
| 34 throws InterruptedException, Exception, Throwable { | 45 throws InterruptedException, Exception, Throwable { |
| 35 launchContentShellWithUrl(JSTEST_URL); | 46 mActivityTestRule.launchContentShellWithUrl(JSTEST_URL); |
| 36 waitForActiveShellToBeDoneLoading(); | 47 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
| 37 | 48 |
| 38 final WebContents webContents = getWebContents(); | 49 final WebContents webContents = mActivityTestRule.getWebContents(); |
| 39 for (int i = 0; i < 30; ++i) { | 50 for (int i = 0; i < 30; ++i) { |
| 40 for (int j = 0; j < 10; ++j) { | 51 for (int j = 0; j < 10; ++j) { |
| 41 // Start evaluation of a JavaScript script -- we don't need a re
sult. | 52 // Start evaluation of a JavaScript script -- we don't need a re
sult. |
| 42 webContents.evaluateJavaScriptForTests("foobar();", null); | 53 webContents.evaluateJavaScriptForTests("foobar();", null); |
| 43 } | 54 } |
| 44 // DOMUtils does need to evaluate a JavaScript and get its result to
get DOM bounds. | 55 // DOMUtils does need to evaluate a JavaScript and get its result to
get DOM bounds. |
| 45 assertNotNull("Failed to get bounds", | 56 Assert.assertNotNull( |
| 46 DOMUtils.getNodeBounds(webContents, "test")); | 57 "Failed to get bounds", DOMUtils.getNodeBounds(webContents,
"test")); |
| 47 } | 58 } |
| 48 } | 59 } |
| 49 } | 60 } |
| OLD | NEW |