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

Side by Side Diff: chrome/android/shell/javatests/src/org/chromium/chrome/shell/ChromeShellTestBase.java

Issue 850813002: Upstream Site Settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@location_settings_singleton
Patch Set: use findbugs annotations; fix test Created 5 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.chrome.shell; 5 package org.chromium.chrome.shell;
6 6
7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout; 7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
8 8
9 import android.content.ComponentName; 9 import android.content.ComponentName;
10 import android.content.Context; 10 import android.content.Context;
11 import android.content.Intent; 11 import android.content.Intent;
12 import android.net.Uri; 12 import android.net.Uri;
13 import android.test.ActivityInstrumentationTestCase2; 13 import android.test.ActivityInstrumentationTestCase2;
14 import android.text.TextUtils; 14 import android.text.TextUtils;
15 import android.util.Log; 15 import android.util.Log;
16 16
17 import org.chromium.base.CommandLine; 17 import org.chromium.base.CommandLine;
18 import org.chromium.base.ThreadUtils; 18 import org.chromium.base.ThreadUtils;
19 import org.chromium.base.library_loader.ProcessInitException; 19 import org.chromium.base.library_loader.ProcessInitException;
20 import org.chromium.chrome.test.util.ApplicationData; 20 import org.chromium.chrome.test.util.ApplicationData;
21 import org.chromium.content.browser.BrowserStartupController; 21 import org.chromium.content.browser.BrowserStartupController;
22 import org.chromium.content.browser.test.util.Criteria; 22 import org.chromium.content.browser.test.util.Criteria;
23 import org.chromium.content.browser.test.util.CriteriaHelper; 23 import org.chromium.content.browser.test.util.CriteriaHelper;
24 import org.chromium.content_public.browser.LoadUrlParams;
24 25
25 import java.util.concurrent.atomic.AtomicBoolean; 26 import java.util.concurrent.atomic.AtomicBoolean;
26 27
27 /** 28 /**
28 * Base test class for all ChromeShell based tests. 29 * Base test class for all ChromeShell based tests.
29 */ 30 */
30 public class ChromeShellTestBase extends ActivityInstrumentationTestCase2<Chrome ShellActivity> { 31 public class ChromeShellTestBase extends ActivityInstrumentationTestCase2<Chrome ShellActivity> {
31 /** The maximum time the waitForActiveShellToBeDoneLoading method will wait. */ 32 /** The maximum time the waitForActiveShellToBeDoneLoading method will wait. */
32 private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeo ut(10000); 33 private static final long WAIT_FOR_ACTIVE_SHELL_LOADING_TIMEOUT = scaleTimeo ut(10000);
33 private static final String TAG = "ChromeShellTestBase"; 34 private static final String TAG = "ChromeShellTestBase";
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 * 117 *
117 * The 'cache' directory is recreated as an empty directory. 118 * The 'cache' directory is recreated as an empty directory.
118 * 119 *
119 * @return Whether clearing the application data was successful. 120 * @return Whether clearing the application data was successful.
120 */ 121 */
121 protected boolean clearAppData() throws InterruptedException { 122 protected boolean clearAppData() throws InterruptedException {
122 return ApplicationData.clearAppData(getInstrumentation().getTargetContex t()); 123 return ApplicationData.clearAppData(getInstrumentation().getTargetContex t());
123 } 124 }
124 125
125 /** 126 /**
127 * Navigates the currently active tab to {@code url} and waits for the page to finish loading.
128 */
129 public void loadUrl(final String url) throws InterruptedException {
130 getInstrumentation().runOnMainSync(new Runnable() {
131 @Override
132 public void run() {
133 getActivity().getActiveTab().loadUrl(new LoadUrlParams(url));
134 }
135 });
136 waitForActiveShellToBeDoneLoading();
137 }
138
139 /**
126 * Navigates the currently active tab to a sanitized version of {@code url}. 140 * Navigates the currently active tab to a sanitized version of {@code url}.
127 * @param url The potentially unsanitized URL to navigate to. 141 * @param url The potentially unsanitized URL to navigate to.
128 */ 142 */
129 public void loadUrlWithSanitization(final String url) throws InterruptedExce ption { 143 public void loadUrlWithSanitization(final String url) throws InterruptedExce ption {
130 getInstrumentation().runOnMainSync(new Runnable() { 144 getInstrumentation().runOnMainSync(new Runnable() {
131 @Override 145 @Override
132 public void run() { 146 public void run() {
133 getActivity().getActiveTab().loadUrlWithSanitization(url); 147 getActivity().getActiveTab().loadUrlWithSanitization(url);
134 } 148 }
135 }); 149 });
136 waitForActiveShellToBeDoneLoading(); 150 waitForActiveShellToBeDoneLoading();
137 } 151 }
138 152
139 // TODO(aelias): This method needs to be removed once http://crbug.com/17951 1 is fixed. 153 // TODO(aelias): This method needs to be removed once http://crbug.com/17951 1 is fixed.
140 // Meanwhile, we have to wait if the page has the <meta viewport> tag. 154 // Meanwhile, we have to wait if the page has the <meta viewport> tag.
141 /** 155 /**
142 * Waits till the ContentViewCore receives the expected page scale factor 156 * Waits till the ContentViewCore receives the expected page scale factor
143 * from the compositor and asserts that this happens. 157 * from the compositor and asserts that this happens.
144 */ 158 */
145 protected void assertWaitForPageScaleFactorMatch(final float expectedScale) 159 protected void assertWaitForPageScaleFactorMatch(final float expectedScale)
146 throws InterruptedException { 160 throws InterruptedException {
147 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { 161 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
148 @Override 162 @Override
149 public boolean isSatisfied() { 163 public boolean isSatisfied() {
150 return getActivity().getActiveTab().getContentViewCore().getScal e() == 164 return getActivity().getActiveTab().getContentViewCore().getScal e()
151 expectedScale; 165 == expectedScale;
152 } 166 }
153 })); 167 }));
154 } 168 }
155 } 169 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698