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

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

Issue 572013002: Removing ContentViewCore dependencies from direct WebContents functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased the patch and addressed review comments. Created 6 years, 2 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.test.suitebuilder.annotation.MediumTest; 7 import android.test.suitebuilder.annotation.MediumTest;
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.TestCallbackHelperContainer; 11 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
12 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEval uateJavaScriptResultHelper; 12 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnEval uateJavaScriptResultHelper;
13 import org.chromium.content_public.browser.LoadUrlParams; 13 import org.chromium.content_public.browser.LoadUrlParams;
14 import org.chromium.content_public.browser.NavigationController;
14 import org.chromium.content_public.browser.NavigationHistory; 15 import org.chromium.content_public.browser.NavigationHistory;
15 import org.chromium.content_shell_apk.ContentShellActivity; 16 import org.chromium.content_shell_apk.ContentShellActivity;
16 import org.chromium.content_shell_apk.ContentShellTestBase; 17 import org.chromium.content_shell_apk.ContentShellTestBase;
17 18
18 /** 19 /**
19 * Tests for various aspects of navigation. 20 * Tests for various aspects of navigation.
20 */ 21 */
21 public class NavigationTest extends ContentShellTestBase { 22 public class NavigationTest extends ContentShellTestBase {
22 23
23 private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</htm l>"); 24 private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</htm l>");
24 private static final String URL_2 = UrlUtils.encodeHtmlDataUri("<html>2</htm l>"); 25 private static final String URL_2 = UrlUtils.encodeHtmlDataUri("<html>2</htm l>");
25 private static final String URL_3 = UrlUtils.encodeHtmlDataUri("<html>3</htm l>"); 26 private static final String URL_3 = UrlUtils.encodeHtmlDataUri("<html>3</htm l>");
26 private static final String URL_4 = UrlUtils.encodeHtmlDataUri("<html>4</htm l>"); 27 private static final String URL_4 = UrlUtils.encodeHtmlDataUri("<html>4</htm l>");
27 private static final String URL_5 = UrlUtils.encodeHtmlDataUri("<html>5</htm l>"); 28 private static final String URL_5 = UrlUtils.encodeHtmlDataUri("<html>5</htm l>");
28 private static final String URL_6 = UrlUtils.encodeHtmlDataUri("<html>6</htm l>"); 29 private static final String URL_6 = UrlUtils.encodeHtmlDataUri("<html>6</htm l>");
29 private static final String URL_7 = UrlUtils.encodeHtmlDataUri("<html>7</htm l>"); 30 private static final String URL_7 = UrlUtils.encodeHtmlDataUri("<html>7</htm l>");
30 31
31 private void goBack(final ContentViewCore contentViewCore, 32 private void goBack(final NavigationController navigationController,
32 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable { 33 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable {
33 handleBlockingCallbackAction( 34 handleBlockingCallbackAction(
34 testCallbackHelperContainer.getOnPageFinishedHelper(), 35 testCallbackHelperContainer.getOnPageFinishedHelper(),
35 new Runnable() { 36 new Runnable() {
36 @Override 37 @Override
37 public void run() { 38 public void run() {
38 contentViewCore.getWebContents().getNavigationController ().goBack(); 39 navigationController.goBack();
39 } 40 }
40 }); 41 });
41 } 42 }
42 43
43 private void reload(final ContentViewCore contentViewCore, 44 private void reload(final NavigationController navigationController,
44 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable { 45 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable {
45 handleBlockingCallbackAction( 46 handleBlockingCallbackAction(
46 testCallbackHelperContainer.getOnPageFinishedHelper(), 47 testCallbackHelperContainer.getOnPageFinishedHelper(),
47 new Runnable() { 48 new Runnable() {
48 @Override 49 @Override
49 public void run() { 50 public void run() {
50 contentViewCore.getWebContents().getNavigationController ().reload(true); 51 navigationController.reload(true);
51 } 52 }
52 }); 53 });
53 } 54 }
54 55
55 @MediumTest 56 @MediumTest
56 @Feature({"Navigation"}) 57 @Feature({"Navigation"})
57 public void testDirectedNavigationHistory() throws Throwable { 58 public void testDirectedNavigationHistory() throws Throwable {
58 ContentShellActivity activity = launchContentShellWithUrl(URL_1); 59 ContentShellActivity activity = launchContentShellWithUrl(URL_1);
59 waitForActiveShellToBeDoneLoading(); 60 waitForActiveShellToBeDoneLoading();
60 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); 61 ContentViewCore contentViewCore = activity.getActiveContentViewCore();
62 NavigationController navigationController = contentViewCore.getWebConten ts()
63 .getNavigationController();
61 TestCallbackHelperContainer testCallbackHelperContainer = 64 TestCallbackHelperContainer testCallbackHelperContainer =
62 new TestCallbackHelperContainer(contentViewCore); 65 new TestCallbackHelperContainer(contentViewCore);
63 66
64 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_2)); 67 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_2));
65 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_3)); 68 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_3));
66 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_4)); 69 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_4));
67 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_5)); 70 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_5));
68 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_6)); 71 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_6));
69 loadUrl(contentViewCore, testCallbackHelperContainer, new LoadUrlParams( URL_7)); 72 loadUrl(navigationController, testCallbackHelperContainer, new LoadUrlPa rams(URL_7));
70 73
71 NavigationHistory history = contentViewCore.getWebContents().getNavigati onController() 74 NavigationHistory history = navigationController.getDirectedNavigationHi story(false, 3);
72 .getDirectedNavigationHistory(false, 3);
73 assertEquals(3, history.getEntryCount()); 75 assertEquals(3, history.getEntryCount());
74 assertEquals(URL_6, history.getEntryAtIndex(0).getUrl()); 76 assertEquals(URL_6, history.getEntryAtIndex(0).getUrl());
75 assertEquals(URL_5, history.getEntryAtIndex(1).getUrl()); 77 assertEquals(URL_5, history.getEntryAtIndex(1).getUrl());
76 assertEquals(URL_4, history.getEntryAtIndex(2).getUrl()); 78 assertEquals(URL_4, history.getEntryAtIndex(2).getUrl());
77 79
78 history = contentViewCore.getWebContents().getNavigationController() 80 history = navigationController.getDirectedNavigationHistory(true, 3);
79 .getDirectedNavigationHistory(true, 3);
80 assertEquals(history.getEntryCount(), 0); 81 assertEquals(history.getEntryCount(), 0);
81 82
82 goBack(contentViewCore, testCallbackHelperContainer); 83 goBack(navigationController, testCallbackHelperContainer);
83 goBack(contentViewCore, testCallbackHelperContainer); 84 goBack(navigationController, testCallbackHelperContainer);
84 goBack(contentViewCore, testCallbackHelperContainer); 85 goBack(navigationController, testCallbackHelperContainer);
85 86
86 history = contentViewCore.getWebContents().getNavigationController() 87 history = navigationController.getDirectedNavigationHistory(false, 4);
87 .getDirectedNavigationHistory(false, 4);
88 assertEquals(3, history.getEntryCount()); 88 assertEquals(3, history.getEntryCount());
89 assertEquals(URL_3, history.getEntryAtIndex(0).getUrl()); 89 assertEquals(URL_3, history.getEntryAtIndex(0).getUrl());
90 assertEquals(URL_2, history.getEntryAtIndex(1).getUrl()); 90 assertEquals(URL_2, history.getEntryAtIndex(1).getUrl());
91 assertEquals(URL_1, history.getEntryAtIndex(2).getUrl()); 91 assertEquals(URL_1, history.getEntryAtIndex(2).getUrl());
92 92
93 history = contentViewCore.getWebContents().getNavigationController() 93 history = navigationController.getDirectedNavigationHistory(true, 4);
94 .getDirectedNavigationHistory(true, 4);
95 assertEquals(3, history.getEntryCount()); 94 assertEquals(3, history.getEntryCount());
96 assertEquals(URL_5, history.getEntryAtIndex(0).getUrl()); 95 assertEquals(URL_5, history.getEntryAtIndex(0).getUrl());
97 assertEquals(URL_6, history.getEntryAtIndex(1).getUrl()); 96 assertEquals(URL_6, history.getEntryAtIndex(1).getUrl());
98 assertEquals(URL_7, history.getEntryAtIndex(2).getUrl()); 97 assertEquals(URL_7, history.getEntryAtIndex(2).getUrl());
99 } 98 }
100 99
101 /** 100 /**
102 * Tests whether a page was successfully reloaded. 101 * Tests whether a page was successfully reloaded.
103 * Checks to make sure that OnPageFinished events were fired and that the ti mestamps of when 102 * Checks to make sure that OnPageFinished events were fired and that the ti mestamps of when
104 * the page loaded are different after the reload. 103 * the page loaded are different after the reload.
105 */ 104 */
106 @MediumTest 105 @MediumTest
107 @Feature({"Navigation"}) 106 @Feature({"Navigation"})
108 public void testPageReload() throws Throwable { 107 public void testPageReload() throws Throwable {
109 final String htmlLoadTime = "<html><head>" + 108 final String htmlLoadTime = "<html><head>" +
110 "<script type=\"text/javascript\">var loadTimestamp = new Date() .getTime();" + 109 "<script type=\"text/javascript\">var loadTimestamp = new Date() .getTime();" +
111 "function getLoadtime() { return loadTimestamp; }</script></head ></html>"; 110 "function getLoadtime() { return loadTimestamp; }</script></head ></html>";
112 final String urlLoadTime = UrlUtils.encodeHtmlDataUri(htmlLoadTime); 111 final String urlLoadTime = UrlUtils.encodeHtmlDataUri(htmlLoadTime);
113 112
114 ContentShellActivity activity = launchContentShellWithUrl(urlLoadTime); 113 ContentShellActivity activity = launchContentShellWithUrl(urlLoadTime);
115 waitForActiveShellToBeDoneLoading(); 114 waitForActiveShellToBeDoneLoading();
116 ContentViewCore contentViewCore = activity.getActiveContentViewCore(); 115 ContentViewCore contentViewCore = activity.getActiveContentViewCore();
117 TestCallbackHelperContainer testCallbackHelperContainer = 116 TestCallbackHelperContainer testCallbackHelperContainer =
118 new TestCallbackHelperContainer(contentViewCore); 117 new TestCallbackHelperContainer(contentViewCore);
119 OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaSc riptResultHelper(); 118 OnEvaluateJavaScriptResultHelper javascriptHelper = new OnEvaluateJavaSc riptResultHelper();
120 119
121 // Grab the first timestamp. 120 // Grab the first timestamp.
122 javascriptHelper.evaluateJavaScript(contentViewCore, "getLoadtime();"); 121 javascriptHelper.evaluateJavaScript(contentViewCore.getWebContents(), "g etLoadtime();");
123 javascriptHelper.waitUntilHasValue(); 122 javascriptHelper.waitUntilHasValue();
124 String firstTimestamp = javascriptHelper.getJsonResultAndClear(); 123 String firstTimestamp = javascriptHelper.getJsonResultAndClear();
125 assertNotNull("Timestamp was null.", firstTimestamp); 124 assertNotNull("Timestamp was null.", firstTimestamp);
126 125
127 // Grab the timestamp after a reload and make sure they don't match. 126 // Grab the timestamp after a reload and make sure they don't match.
128 reload(contentViewCore, testCallbackHelperContainer); 127 reload(contentViewCore.getWebContents().getNavigationController(),
129 javascriptHelper.evaluateJavaScript(contentViewCore, "getLoadtime();"); 128 testCallbackHelperContainer);
129 javascriptHelper.evaluateJavaScript(contentViewCore.getWebContents(), "g etLoadtime();");
130 javascriptHelper.waitUntilHasValue(); 130 javascriptHelper.waitUntilHasValue();
131 String secondTimestamp = javascriptHelper.getJsonResultAndClear(); 131 String secondTimestamp = javascriptHelper.getJsonResultAndClear();
132 assertNotNull("Timestamp was null.", secondTimestamp); 132 assertNotNull("Timestamp was null.", secondTimestamp);
133 assertFalse("Timestamps matched.", firstTimestamp.equals(secondTimestamp )); 133 assertFalse("Timestamps matched.", firstTimestamp.equals(secondTimestamp ));
134 } 134 }
135 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698