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

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

Issue 12313070: [Android] Add a reload navigation test for ContentShell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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_shell.ContentShellTestBase; 12 import org.chromium.content_shell.ContentShellTestBase;
13 import org.chromium.content_shell_apk.ContentShellActivity; 13 import org.chromium.content_shell_apk.ContentShellActivity;
14 14
15 import java.util.concurrent.TimeUnit;
16
15 /** 17 /**
16 * Tests for various aspects of navigation. 18 * Tests for various aspects of navigation.
17 */ 19 */
18 public class NavigationTest extends ContentShellTestBase { 20 public class NavigationTest extends ContentShellTestBase {
19 21
20 private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</htm l>"); 22 private static final String URL_1 = UrlUtils.encodeHtmlDataUri("<html>1</htm l>");
21 private static final String URL_2 = UrlUtils.encodeHtmlDataUri("<html>2</htm l>"); 23 private static final String URL_2 = UrlUtils.encodeHtmlDataUri("<html>2</htm l>");
22 private static final String URL_3 = UrlUtils.encodeHtmlDataUri("<html>3</htm l>"); 24 private static final String URL_3 = UrlUtils.encodeHtmlDataUri("<html>3</htm l>");
23 private static final String URL_4 = UrlUtils.encodeHtmlDataUri("<html>4</htm l>"); 25 private static final String URL_4 = UrlUtils.encodeHtmlDataUri("<html>4</htm l>");
24 private static final String URL_5 = UrlUtils.encodeHtmlDataUri("<html>5</htm l>"); 26 private static final String URL_5 = UrlUtils.encodeHtmlDataUri("<html>5</htm l>");
25 private static final String URL_6 = UrlUtils.encodeHtmlDataUri("<html>6</htm l>"); 27 private static final String URL_6 = UrlUtils.encodeHtmlDataUri("<html>6</htm l>");
26 private static final String URL_7 = UrlUtils.encodeHtmlDataUri("<html>7</htm l>"); 28 private static final String URL_7 = UrlUtils.encodeHtmlDataUri("<html>7</htm l>");
27 29
28 private void goBack(final ContentView contentView, 30 private void goBack(final ContentView contentView,
29 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable { 31 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable {
30 handleBlockingCallbackAction( 32 handleBlockingCallbackAction(
31 testCallbackHelperContainer.getOnPageFinishedHelper(), 33 testCallbackHelperContainer.getOnPageFinishedHelper(),
32 new Runnable() { 34 new Runnable() {
33 @Override 35 @Override
34 public void run() { 36 public void run() {
35 contentView.goBack(); 37 contentView.goBack();
36 } 38 }
37 }); 39 });
38 } 40 }
39 41
42 private void reload(final ContentView contentView,
43 TestCallbackHelperContainer testCallbackHelperContainer) throws Thro wable {
44 handleBlockingCallbackAction(
45 testCallbackHelperContainer.getOnPageFinishedHelper(),
46 new Runnable() {
47 @Override
48 public void run() {
49 contentView.reload();
50 }
51 });
52 }
53
40 @MediumTest 54 @MediumTest
41 @Feature({"Navigation"}) 55 @Feature({"Navigation"})
42 public void testDirectedNavigationHistory() throws Throwable { 56 public void testDirectedNavigationHistory() throws Throwable {
43 ContentShellActivity activity = launchContentShellWithUrl(URL_1); 57 ContentShellActivity activity = launchContentShellWithUrl(URL_1);
44 waitForActiveShellToBeDoneLoading(); 58 waitForActiveShellToBeDoneLoading();
45 ContentView contentView = activity.getActiveContentView(); 59 ContentView contentView = activity.getActiveContentView();
46 TestCallbackHelperContainer testCallbackHelperContainer = 60 TestCallbackHelperContainer testCallbackHelperContainer =
47 new TestCallbackHelperContainer(contentView); 61 new TestCallbackHelperContainer(contentView);
48 62
49 loadUrl(contentView, testCallbackHelperContainer, new LoadUrlParams(URL_ 2)); 63 loadUrl(contentView, testCallbackHelperContainer, new LoadUrlParams(URL_ 2));
(...skipping 25 matching lines...) Expand all
75 assertEquals(URL_2, history.getEntryAtIndex(1).getUrl()); 89 assertEquals(URL_2, history.getEntryAtIndex(1).getUrl());
76 assertEquals(URL_1, history.getEntryAtIndex(2).getUrl()); 90 assertEquals(URL_1, history.getEntryAtIndex(2).getUrl());
77 91
78 history = contentViewCore.getDirectedNavigationHistory(true, 4); 92 history = contentViewCore.getDirectedNavigationHistory(true, 4);
79 assertEquals(3, history.getEntryCount()); 93 assertEquals(3, history.getEntryCount());
80 assertEquals(URL_5, history.getEntryAtIndex(0).getUrl()); 94 assertEquals(URL_5, history.getEntryAtIndex(0).getUrl());
81 assertEquals(URL_6, history.getEntryAtIndex(1).getUrl()); 95 assertEquals(URL_6, history.getEntryAtIndex(1).getUrl());
82 assertEquals(URL_7, history.getEntryAtIndex(2).getUrl()); 96 assertEquals(URL_7, history.getEntryAtIndex(2).getUrl());
83 } 97 }
84 98
99 /**
100 * Tests whether a page was successfully reloaded.
101 * Checks to make sure that OnPageFinished events were fired and that the ti mestamps of when
102 * the page loaded are different after the reload.
103 */
104 @MediumTest
105 @Feature({"Navigation"})
106 public void testPageReload() throws Throwable {
107 final String HTML_LOADTIME = "<html><head>" +
108 "<script type=\"text/javascript\">var loadTimestamp = new Date() .getTime();" +
109 "function getLoadtime() { return loadTimestamp; }</script></head ></html>";
110 final String URL_LOADTIME = UrlUtils.encodeHtmlDataUri(HTML_LOADTIME);
111
112 ContentShellActivity activity = launchContentShellWithUrl(URL_LOADTIME);
113 waitForActiveShellToBeDoneLoading();
114 ContentView contentView = activity.getActiveContentView();
115 TestCallbackHelperContainer testCallbackHelperContainer =
116 new TestCallbackHelperContainer(contentView);
117 TestCallbackHelperContainer.OnEvaluateJavaScriptResultHelper javascriptH elper =
118 testCallbackHelperContainer.getOnEvaluateJavaScriptResultHelper( );
119
120 // Grab the first timestamp.
121 javascriptHelper.evaluateJavaScript(contentView.getContentViewCore(), "g etLoadtime();");
122 javascriptHelper.waitUntilHasValue();
123 String firstTimestamp = javascriptHelper.getJsonResultAndClear();
124 assertNotNull("Timestamp was null.", firstTimestamp);
125
126 // Grab the timestamp after a reload and make sure they don't match.
127 reload(contentView, testCallbackHelperContainer);
128 javascriptHelper.evaluateJavaScript(contentView.getContentViewCore(), "g etLoadtime();");
129 javascriptHelper.waitUntilHasValue();
130 String secondTimestamp = javascriptHelper.getJsonResultAndClear();
131 assertNotNull("Timestamp was null.", secondTimestamp);
132 assertFalse("Timestamps matched.", firstTimestamp.equals(secondTimestamp ));
133 }
85 } 134 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698