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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappActivityTestBase.java

Issue 2863583002: Convert WebappActivityTestBase and direct children to JUnit4. (Closed)
Patch Set: Merge Created 3 years, 7 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
(Empty)
1 // Copyright 2015 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.chrome.browser.webapps;
6
7 import static org.chromium.base.test.util.ScalableTimeout.scaleTimeout;
8
9 import android.content.Intent;
10 import android.net.Uri;
11 import android.view.ViewGroup;
12
13 import org.chromium.chrome.browser.ShortcutHelper;
14 import org.chromium.chrome.test.ChromeActivityTestCaseBase;
15 import org.chromium.content.browser.test.util.Criteria;
16 import org.chromium.content.browser.test.util.CriteriaHelper;
17
18 /**
19 * The base class of the WebappActivity tests. It provides the common methods to access the activity
20 * UI. This particular test base only instantiates WebappActivity0.
21 */
22 public abstract class WebappActivityTestBase extends ChromeActivityTestCaseBase< WebappActivity0> {
23 static final String WEBAPP_ID = "webapp_id";
24 static final String WEBAPP_NAME = "webapp name";
25 static final String WEBAPP_SHORT_NAME = "webapp short name";
26
27 private static final long STARTUP_TIMEOUT = scaleTimeout(10000);
28
29 // Empty 192x192 image generated with:
30 // ShortcutHelper.encodeBitmapAsString(Bitmap.createBitmap(192, 192, Bitmap. Config.ARGB_4444));
31 protected static final String TEST_ICON =
32 "iVBORw0KGgoAAAANSUhEUgAAAMAAAADACAYAAABS3GwHAAAABHNCSVQICAgIfAhkiAA AAKZJREFU"
33 + "eJztwTEBAAAAwqD1T20JT6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
34 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
35 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4GQ N4AAe3mX6IA"
36 + "AAAASUVORK5CYII=";
37
38 // Empty 512x512 image generated with:
39 // ShortcutHelper.encodeBitmapAsString(Bitmap.createBitmap(512, 512, Bitmap. Config.ARGB_4444));
40 protected static final String TEST_SPLASH_ICON =
41 "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABHNCSVQICAgIfAhkiAA ABA9JREFU"
42 + "eJztwTEBAAAAwqD1T20Hb6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
43 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
44 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
45 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
46 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
47 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
48 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
49 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
50 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
51 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
52 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
53 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
54 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
55 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
56 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
57 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
58 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
59 + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAA"
60 + "AAAAAAAAAOA3AvAAAdln8YgAAAAASUVORK5CYII=";
61
62 public WebappActivityTestBase() {
63 super(WebappActivity0.class);
64 }
65
66 /**
67 * Creates the Intent that starts the WebAppActivity. This is meant to be ov erriden by other
68 * tests in order for them to pass some specific values, but it defaults to a web app that just
69 * loads about:blank to avoid a network load. This results in the URL bar s howing because
70 * {@link UrlUtils} cannot parse this type of URL.
71 */
72 protected Intent createIntent() {
73 Intent intent = new Intent(getInstrumentation().getTargetContext(), Weba ppActivity0.class);
74 intent.setData(Uri.parse(WebappActivity.WEBAPP_SCHEME + "://" + WEBAPP_I D));
75 intent.putExtra(ShortcutHelper.EXTRA_ID, WEBAPP_ID);
76 intent.putExtra(ShortcutHelper.EXTRA_URL, "about:blank");
77 intent.putExtra(ShortcutHelper.EXTRA_NAME, WEBAPP_NAME);
78 intent.putExtra(ShortcutHelper.EXTRA_SHORT_NAME, WEBAPP_SHORT_NAME);
79 return intent;
80 }
81
82 @Override
83 protected void setUp() throws Exception {
84 super.setUp();
85
86 // Register the webapp so when the data storage is opened, the test does n't crash.
87 WebappRegistry.refreshSharedPrefsForTesting();
88 TestFetchStorageCallback callback = new TestFetchStorageCallback();
89 WebappRegistry.getInstance().register(WEBAPP_ID, callback);
90 callback.waitForCallback(0);
91 callback.getStorage().updateFromShortcutIntent(createIntent());
92 }
93
94 /**
95 * Starts up the WebappActivity and sets up the test observer.
96 */
97 protected final void startWebappActivity() throws Exception {
98 startWebappActivity(createIntent());
99 }
100
101 /**
102 * Starts up the WebappActivity with a specific Intent and sets up the test observer.
103 */
104 protected final void startWebappActivity(Intent intent) throws Exception {
105 setActivityIntent(intent);
106 waitUntilIdle();
107 }
108
109 /**
110 * Waits until any loads in progress have completed.
111 */
112 protected void waitUntilIdle() {
113 getInstrumentation().waitForIdleSync();
114 CriteriaHelper.pollInstrumentationThread(new Criteria() {
115 @Override
116 public boolean isSatisfied() {
117 return getActivity().getActivityTab() != null
118 && !getActivity().getActivityTab().isLoading();
119 }
120 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
121
122 getInstrumentation().waitForIdleSync();
123 }
124
125 @Override
126 public final void startMainActivity() throws InterruptedException {
127 // Do nothing; the WebappActivity may not have been completely set up, y et.
128 }
129
130 /**
131 * Waits for the splash screen to be hidden.
132 */
133 protected void waitUntilSplashscreenHides() {
134 CriteriaHelper.pollInstrumentationThread(new Criteria() {
135 @Override
136 public boolean isSatisfied() {
137 return !getActivity().isSplashScreenVisibleForTests();
138 }
139 });
140 }
141
142 protected ViewGroup waitUntilSplashScreenAppears() {
143 CriteriaHelper.pollInstrumentationThread(new Criteria() {
144 @Override
145 public boolean isSatisfied() {
146 return getActivity().getSplashScreenForTests() != null;
147 }
148 });
149
150 ViewGroup splashScreen = getActivity().getSplashScreenForTests();
151 if (splashScreen == null) {
152 fail("No splash screen available.");
153 }
154 return splashScreen;
155 }
156 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698