Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/NavigationTest.java

Issue 2708243004: Auto convert content shell tests to JUnit4 (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.MediumTest; 7 import android.support.test.filters.MediumTest;
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.FlakyTest; 16 import org.chromium.base.test.util.FlakyTest;
11 import org.chromium.base.test.util.UrlUtils; 17 import org.chromium.base.test.util.UrlUtils;
12 import org.chromium.content.browser.test.util.TestCallbackHelperContainer; 18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
13 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEval uateJavaScriptResultHelper; 19 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEval uateJavaScriptResultHelper;
14 import org.chromium.content_public.browser.LoadUrlParams; 20 import org.chromium.content_public.browser.LoadUrlParams;
15 import org.chromium.content_public.browser.NavigationController; 21 import org.chromium.content_public.browser.NavigationController;
16 import org.chromium.content_public.browser.NavigationHistory; 22 import org.chromium.content_public.browser.NavigationHistory;
17 import org.chromium.content_shell_apk.ContentShellActivity; 23 import org.chromium.content_shell_apk.ContentShellActivity;
18 import org.chromium.content_shell_apk.ContentShellTestBase; 24 import org.chromium.content_shell_apk.ContentShellActivityTestRule;
19 25
20 /** 26 /**
21 * Tests for various aspects of navigation. 27 * Tests for various aspects of navigation.
22 */ 28 */
23 public class NavigationTest extends ContentShellTestBase { 29 @RunWith(BaseJUnit4ClassRunner.class)
30 public class NavigationTest {
31 @Rule
32 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi vityTestRule();
24 33
25 private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</htm l>"); 34 private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</htm l>");
26 private static final String URL_2 = UrlUtils.encodeHtmlDataUri("<html>2</htm l>"); 35 private static final String URL_2 = UrlUtils.encodeHtmlDataUri("<html>2</htm l>");
27 private static final String URL_3 = UrlUtils.encodeHtmlDataUri("<html>3</htm l>"); 36 private static final String URL_3 = UrlUtils.encodeHtmlDataUri("<html>3</htm l>");
28 private static final String URL_4 = UrlUtils.encodeHtmlDataUri("<html>4</htm l>"); 37 private static final String URL_4 = UrlUtils.encodeHtmlDataUri("<html>4</htm l>");
29 private static final String URL_5 = UrlUtils.encodeHtmlDataUri("<html>5</htm l>"); 38 private static final String URL_5 = UrlUtils.encodeHtmlDataUri("<html>5</htm l>");
30 private static final String URL_6 = UrlUtils.encodeHtmlDataUri("<html>6</htm l>"); 39 private static final String URL_6 = UrlUtils.encodeHtmlDataUri("<html>6</htm l>");
31 private static final String URL_7 = UrlUtils.encodeHtmlDataUri("<html>7</htm l>"); 40 private static final String URL_7 = UrlUtils.encodeHtmlDataUri("<html>7</htm l>");
32 41
33 private void goBack(final NavigationController navigationController, 42 private void goBack(final NavigationController navigationController,
34 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable { 43 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable {
35 handleBlockingCallbackAction( 44 mActivityTestRule.handleBlockingCallbackAction(
36 testCallbackHelperContainer.getOnPageFinishedHelper(), 45 testCallbackHelperContainer.getOnPageFinishedHelper(), new Runna ble() {
37 new Runnable() {
38 @Override 46 @Override
39 public void run() { 47 public void run() {
40 navigationController.goBack(); 48 navigationController.goBack();
41 } 49 }
42 }); 50 });
43 } 51 }
44 52
45 private void reload(final NavigationController navigationController, 53 private void reload(final NavigationController navigationController,
46 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable { 54 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable {
47 handleBlockingCallbackAction( 55 mActivityTestRule.handleBlockingCallbackAction(
48 testCallbackHelperContainer.getOnPageFinishedHelper(), 56 testCallbackHelperContainer.getOnPageFinishedHelper(), new Runna ble() {
49 new Runnable() {
50 @Override 57 @Override
51 public void run() { 58 public void run() {
52 navigationController.reload(true); 59 navigationController.reload(true);
53 } 60 }
54 }); 61 });
55 } 62 }
56 63
64 @Test
57 @MediumTest 65 @MediumTest
58 @Feature({"Navigation"}) 66 @Feature({"Navigation"})
59 @FlakyTest 67 @FlakyTest
60 public void testDirectedNavigationHistory() throws Throwable { 68 public void testDirectedNavigationHistory() throws Throwable {
61 ContentShellActivity activity = launchContentShellWithUrl(URL_1); 69 ContentShellActivity activity = mActivityTestRule.launchContentShellWith Url(URL_1);
62 waitForActiveShellToBeDoneLoading(); 70 mActivityTestRule.waitForActiveShellToBeDoneLoading();
63 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); 71 ContentViewCore contentViewCore = activity.getActiveContentViewCore();
64 NavigationController navigationController = contentViewCore.getWebConten ts() 72 NavigationController navigationController = contentViewCore.getWebConten ts()
65 .getNavigationController(); 73 .getNavigationController();
66 TestCallbackHelperContainer testCallbackHelperContainer = 74 TestCallbackHelperContainer testCallbackHelperContainer =
67 new TestCallbackHelperContainer(contentViewCore); 75 new TestCallbackHelperContainer(contentViewCore);
68 76
69 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_2)); 77 mActivityTestRule.loadUrl(
70 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_3)); 78 navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_2));
71 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_4)); 79 mActivityTestRule.loadUrl(
72 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_5)); 80 navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_3));
73 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_6)); 81 mActivityTestRule.loadUrl(
74 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_7)); 82 navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_4));
83 mActivityTestRule.loadUrl(
84 navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_5));
85 mActivityTestRule.loadUrl(
86 navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_6));
87 mActivityTestRule.loadUrl(
88 navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_7));
75 89
76 NavigationHistory history = navigationController.getDirectedNavigationHi story(false, 3); 90 NavigationHistory history = navigationController.getDirectedNavigationHi story(false, 3);
77 assertEquals(3, history.getEntryCount()); 91 Assert.assertEquals(3, history.getEntryCount());
78 assertEquals(URL_6, history.getEntryAtIndex(0).getUrl()); 92 Assert.assertEquals(URL_6, history.getEntryAtIndex(0).getUrl());
79 assertEquals(URL_5, history.getEntryAtIndex(1).getUrl()); 93 Assert.assertEquals(URL_5, history.getEntryAtIndex(1).getUrl());
80 assertEquals(URL_4, history.getEntryAtIndex(2).getUrl()); 94 Assert.assertEquals(URL_4, history.getEntryAtIndex(2).getUrl());
81 95
82 history = navigationController.getDirectedNavigationHistory(true, 3); 96 history = navigationController.getDirectedNavigationHistory(true, 3);
83 assertEquals(history.getEntryCount(), 0); 97 Assert.assertEquals(history.getEntryCount(), 0);
84 98
85 goBack(navigationController, testCallbackHelperContainer); 99 goBack(navigationController, testCallbackHelperContainer);
86 goBack(navigationController, testCallbackHelperContainer); 100 goBack(navigationController, testCallbackHelperContainer);
87 goBack(navigationController, testCallbackHelperContainer); 101 goBack(navigationController, testCallbackHelperContainer);
88 102
89 history = navigationController.getDirectedNavigationHistory(false, 4); 103 history = navigationController.getDirectedNavigationHistory(false, 4);
90 assertEquals(3, history.getEntryCount()); 104 Assert.assertEquals(3, history.getEntryCount());
91 assertEquals(URL_3, history.getEntryAtIndex(0).getUrl()); 105 Assert.assertEquals(URL_3, history.getEntryAtIndex(0).getUrl());
92 assertEquals(URL_2, history.getEntryAtIndex(1).getUrl()); 106 Assert.assertEquals(URL_2, history.getEntryAtIndex(1).getUrl());
93 assertEquals(URL_1, history.getEntryAtIndex(2).getUrl()); 107 Assert.assertEquals(URL_1, history.getEntryAtIndex(2).getUrl());
94 108
95 history = navigationController.getDirectedNavigationHistory(true, 4); 109 history = navigationController.getDirectedNavigationHistory(true, 4);
96 assertEquals(3, history.getEntryCount()); 110 Assert.assertEquals(3, history.getEntryCount());
97 assertEquals(URL_5, history.getEntryAtIndex(0).getUrl()); 111 Assert.assertEquals(URL_5, history.getEntryAtIndex(0).getUrl());
98 assertEquals(URL_6, history.getEntryAtIndex(1).getUrl()); 112 Assert.assertEquals(URL_6, history.getEntryAtIndex(1).getUrl());
99 assertEquals(URL_7, history.getEntryAtIndex(2).getUrl()); 113 Assert.assertEquals(URL_7, history.getEntryAtIndex(2).getUrl());
100 } 114 }
101 115
102 /** 116 /**
103 * Tests whether a page was successfully reloaded. 117 * Tests whether a page was successfully reloaded.
104 * Checks to make sure that OnPageFinished events were fired and that the ti mestamps of when 118 * Checks to make sure that OnPageFinished events were fired and that the ti mestamps of when
105 * the page loaded are different after the reload. 119 * the page loaded are different after the reload.
106 */ 120 */
121 @Test
107 @MediumTest 122 @MediumTest
108 @Feature({"Navigation"}) 123 @Feature({"Navigation"})
109 public void testPageReload() throws Throwable { 124 public void testPageReload() throws Throwable {
110 final String htmlLoadTime = "<html><head>" 125 final String htmlLoadTime = "<html><head>"
111 + "<script type=\"text/javascript\">var loadTimestamp = new Date ().getTime();" 126 + "<script type=\"text/javascript\">var loadTimestamp = new Date ().getTime();"
112 + "function getLoadtime() { return loadTimestamp; }</script></he ad></html>"; 127 + "function getLoadtime() { return loadTimestamp; }</script></he ad></html>";
113 final String urlLoadTime = UrlUtils.encodeHtmlDataUri(htmlLoadTime); 128 final String urlLoadTime = UrlUtils.encodeHtmlDataUri(htmlLoadTime);
114 129
115 ContentShellActivity activity = launchContentShellWithUrl(urlLoadTime); 130 ContentShellActivity activity = mActivityTestRule.launchContentShellWith Url(urlLoadTime);
116 waitForActiveShellToBeDoneLoading(); 131 mActivityTestRule.waitForActiveShellToBeDoneLoading();
117 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); 132 ContentViewCore contentViewCore = activity.getActiveContentViewCore();
118 TestCallbackHelperContainer testCallbackHelperContainer = 133 TestCallbackHelperContainer testCallbackHelperContainer =
119 new TestCallbackHelperContainer(contentViewCore); 134 new TestCallbackHelperContainer(contentViewCore);
120 OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaSc riptResultHelper(); 135 OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaSc riptResultHelper();
121 136
122 // Grab the first timestamp. 137 // Grab the first timestamp.
123 javascriptHelper.evaluateJavaScriptForTests( 138 javascriptHelper.evaluateJavaScriptForTests(
124 contentViewCore.getWebContents(), "getLoadtime();"); 139 contentViewCore.getWebContents(), "getLoadtime();");
125 javascriptHelper.waitUntilHasValue(); 140 javascriptHelper.waitUntilHasValue();
126 String firstTimestamp = javascriptHelper.getJsonResultAndClear(); 141 String firstTimestamp = javascriptHelper.getJsonResultAndClear();
127 assertNotNull("Timestamp was null.", firstTimestamp); 142 Assert.assertNotNull("Timestamp was null.", firstTimestamp);
128 143
129 // Grab the timestamp after a reload and make sure they don't match. 144 // Grab the timestamp after a reload and make sure they don't match.
130 reload(contentViewCore.getWebContents().getNavigationController(), 145 reload(contentViewCore.getWebContents().getNavigationController(),
131 testCallbackHelperContainer); 146 testCallbackHelperContainer);
132 javascriptHelper.evaluateJavaScriptForTests( 147 javascriptHelper.evaluateJavaScriptForTests(
133 contentViewCore.getWebContents(), "getLoadtime();"); 148 contentViewCore.getWebContents(), "getLoadtime();");
134 javascriptHelper.waitUntilHasValue(); 149 javascriptHelper.waitUntilHasValue();
135 String secondTimestamp = javascriptHelper.getJsonResultAndClear(); 150 String secondTimestamp = javascriptHelper.getJsonResultAndClear();
136 assertNotNull("Timestamp was null.", secondTimestamp); 151 Assert.assertNotNull("Timestamp was null.", secondTimestamp);
137 assertFalse("Timestamps matched.", firstTimestamp.equals(secondTimestamp )); 152 Assert.assertFalse("Timestamps matched.", firstTimestamp.equals(secondTi mestamp));
138 } 153 }
139 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698