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

Side by Side Diff: content/shell/android/javatests/src/org/chromium/content_shell/ContentDetectionTestBase.java

Issue 11085008: [Android] Upstream content detection and ChromeBrowserProvider tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clean-up for review. Created 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.content_shell;
6
7 import android.content.Context;
8 import android.net.Uri;
9
10 import java.util.concurrent.TimeUnit;
11
12 import org.chromium.base.test.util.UrlUtils;
13
14 import org.chromium.content.browser.ContentView;
15 import org.chromium.content.browser.test.util.DOMUtils;
16 import org.chromium.content.browser.test.util.JavaScriptUtils;
17 import org.chromium.content.browser.test.util.TestContentViewClient;
18 import org.chromium.content.browser.test.util.TestCallbackHelperContainer;
19 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage FinishedHelper;
20 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnStar tContentIntentHelper;
21
22 /**
23 * Base class for content detection test suites.
24 */
25 public class ContentDetectionTestBase extends ContentShellTestBase {
26
27 private static final int WAIT_TIMEOUT_SECONDS = 10;
28
29 private ContentView mContentView;
30 private TestCallbackHelperContainer mCallbackHelper;
31
32 /**
33 * Starts the content shell activity with the provided test url.
34 * The url is synchronously loaded.
35 * @param testUrl Test url to load.
36 */
37 protected void startActivityWithTestUrl(String testUrl) throws Throwable {
38 ContentShellActivity activity = launchContentShellWithUrl(UrlUtils.getTe stFileUrl(testUrl));
39 assertNotNull(activity);
40 assertTrue(waitForActiveShellToBeDoneLoading());
41 mContentView = activity.getActiveShell().getContentView();
42 assertEquals(UrlUtils.getTestFileUrl(testUrl), mContentView.getUrl());
43 }
44
45 /**
46 * Starts the content shell activity with the provided etst url and optional command line
47 * arguments to append.
48 * The url is synchronously loaded.
49 * @param testUrl Test url to load.
50 * @param commandLineArgs Optional command line args to append when launchin g the activity.
51 */
52 protected void startActivityWithTestUrlAndCommandLineArgs(
53 String testUrl, String[] commandLineArgs) throws Throwable {
54 ContentShellActivity activity = launchContentShellWithUrlAndCommandLineA rgs(
55 UrlUtils.getTestFileUrl(testUrl), commandLineArgs);
56 assertNotNull(activity);
57 assertTrue(waitForActiveShellToBeDoneLoading());
58 mContentView = activity.getActiveShell().getContentView();
59 }
60
61 /**
62 * Returns the current ContentView.
63 */
64 protected ContentView getContentView() {
65 return mContentView;
66 }
67
68 /**
69 * Returns the TestCallbackHelperContainer associated with this ContentView,
70 * or creates it lazily.
71 */
72 protected TestCallbackHelperContainer getTestCallbackHelperContainer() {
73 if (mCallbackHelper == null) {
74 mCallbackHelper = new TestCallbackHelperContainer(getContentView());
75 }
76 return mCallbackHelper;
77 }
78
79 /**
80 * Encodes the provided content string into an escaped url as intents do.
81 * @param content Content to escape into a url.
82 * @return Escaped url.
83 */
84 protected String urlForContent(String content) {
85 return Uri.encode(content).replaceAll("%20", "+");
86 }
87
88 /**
89 * Checks if the provided test url is the current url in the content view.
90 * @param testUrl Test url to check.
91 * @return true if the test url is the current one, false otherwise.
92 */
93 protected boolean isCurrentTestUrl(String testUrl) {
94 return UrlUtils.getTestFileUrl(testUrl).equals(getContentView().getUrl() );
95 }
96
97 /**
98 * Scrolls to the node with the provided id, taps on it and waits for an int ent to come.
99 * @param id Id of the node to scroll and tap.
100 * @return The content url of the received intent or null if none.
101 */
102 protected String scrollAndTapExpectingIntent(String id) throws Throwable {
103 TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHel perContainer();
104 OnStartContentIntentHelper onStartContentIntentHelper =
105 callbackHelperContainer.getOnStartContentIntentHelper();
106 int currentCallCount = onStartContentIntentHelper.getCallCount();
107
108 DOMUtils.scrollNodeIntoView(this, getContentView(), callbackHelperContai ner, id);
109 DOMUtils.clickNode(this, getContentView(), callbackHelperContainer, id);
110
111 onStartContentIntentHelper.waitForCallback(currentCallCount, 1, WAIT_TIM EOUT_SECONDS,
112 TimeUnit.SECONDS);
113 getInstrumentation().waitForIdleSync();
114 return onStartContentIntentHelper.getIntentUrl();
115 }
116
117 /**
118 * Scrolls to the node with the provided id, taps on it and waits for a new page load to finish.
119 * Useful when tapping on links that take to other pages.
120 * @param id Id of the node to scroll and tap.
121 * @return The content url of the received intent or null if none.
122 */
123 protected void scrollAndTapNavigatingOut(String id) throws Throwable {
124 TestCallbackHelperContainer callbackHelperContainer = getTestCallbackHel perContainer();
125 OnPageFinishedHelper onPageFinishedHelper =
126 callbackHelperContainer.getOnPageFinishedHelper();
127 int currentCallCount = onPageFinishedHelper.getCallCount();
128
129 DOMUtils.scrollNodeIntoView(this, getContentView(), callbackHelperContai ner, id);
130 DOMUtils.clickNode(this, getContentView(), callbackHelperContainer, id);
131
132 onPageFinishedHelper.waitForCallback(currentCallCount, 1, WAIT_TIMEOUT_S ECONDS,
133 TimeUnit.SECONDS);
134 getInstrumentation().waitForIdleSync();
135 }
136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698