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

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

Issue 2854943005: Converts WebApkIntegrationTest to JUnit4. (Closed)
Patch Set: Uses InstrumentationRegistry now 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
« 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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.browser.webapps; 5 package org.chromium.chrome.browser.webapps;
6 6
7 import android.content.Intent; 7 import android.content.Intent;
8 import android.support.test.InstrumentationRegistry;
8 import android.support.test.filters.LargeTest; 9 import android.support.test.filters.LargeTest;
9 10
11 import org.junit.After;
12 import org.junit.Before;
13 import org.junit.Rule;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16
17 import org.chromium.base.test.util.CommandLineFlags;
10 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
11 import org.chromium.base.test.util.RetryOnFailure; 19 import org.chromium.base.test.util.RetryOnFailure;
12 import org.chromium.base.test.util.ScalableTimeout; 20 import org.chromium.base.test.util.ScalableTimeout;
21 import org.chromium.chrome.browser.ChromeSwitches;
13 import org.chromium.chrome.browser.ShortcutHelper; 22 import org.chromium.chrome.browser.ShortcutHelper;
14 import org.chromium.chrome.test.ChromeActivityTestCaseBase; 23 import org.chromium.chrome.test.ChromeActivityTestRule;
24 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
15 import org.chromium.chrome.test.util.ChromeTabUtils; 25 import org.chromium.chrome.test.util.ChromeTabUtils;
16 import org.chromium.content.browser.test.util.Criteria; 26 import org.chromium.content.browser.test.util.Criteria;
17 import org.chromium.content.browser.test.util.CriteriaHelper; 27 import org.chromium.content.browser.test.util.CriteriaHelper;
18 import org.chromium.net.test.EmbeddedTestServer; 28 import org.chromium.net.test.EmbeddedTestServer;
19 import org.chromium.webapk.lib.common.WebApkConstants; 29 import org.chromium.webapk.lib.common.WebApkConstants;
20 30
21 /** Integration tests for WebAPK feature. */ 31 /** Integration tests for WebAPK feature. */
22 public class WebApkIntegrationTest extends ChromeActivityTestCaseBase<WebApkActi vity> { 32 @RunWith(ChromeJUnit4ClassRunner.class)
33 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
34 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
35 public class WebApkIntegrationTest {
36 @Rule
37 public final ChromeActivityTestRule<WebApkActivity> mActivityTestRule =
38 new ChromeActivityTestRule<>(WebApkActivity.class);
39
23 private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(100 00); 40 private static final long STARTUP_TIMEOUT = ScalableTimeout.scaleTimeout(100 00);
24 41
25 private EmbeddedTestServer mTestServer; 42 private EmbeddedTestServer mTestServer;
26 43
27 public WebApkIntegrationTest() {
28 super(WebApkActivity.class);
29 }
30
31 public void startWebApkActivity(String webApkPackageName, final String start Url) 44 public void startWebApkActivity(String webApkPackageName, final String start Url)
32 throws InterruptedException { 45 throws InterruptedException {
33 Intent intent = new Intent(getInstrumentation().getTargetContext(), WebA pkActivity.class); 46 Intent intent =
47 new Intent(InstrumentationRegistry.getTargetContext(), WebApkAct ivity.class);
34 intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage Name); 48 intent.putExtra(WebApkConstants.EXTRA_WEBAPK_PACKAGE_NAME, webApkPackage Name);
35 intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl); 49 intent.putExtra(ShortcutHelper.EXTRA_URL, startUrl);
36 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 50 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
37 setActivity(getInstrumentation().startActivitySync(intent)); 51 mActivityTestRule.setActivity(
38 getInstrumentation().waitForIdleSync(); 52 (WebApkActivity) InstrumentationRegistry.getInstrumentation().st artActivitySync(
53 intent));
54 InstrumentationRegistry.getInstrumentation().waitForIdleSync();
39 55
40 CriteriaHelper.pollInstrumentationThread(new Criteria() { 56 CriteriaHelper.pollInstrumentationThread(new Criteria() {
41 @Override 57 @Override
42 public boolean isSatisfied() { 58 public boolean isSatisfied() {
43 return getActivity().getActivityTab() != null; 59 return mActivityTestRule.getActivity().getActivityTab() != null;
44 } 60 }
45 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL); 61 }, STARTUP_TIMEOUT, CriteriaHelper.DEFAULT_POLLING_INTERVAL);
46 62
47 ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), star tUrl); 63 ChromeTabUtils.waitForTabPageLoaded(
64 mActivityTestRule.getActivity().getActivityTab(), startUrl);
48 } 65 }
49 66
50 /** Waits for the splash screen to be hidden. */ 67 /** Waits for the splash screen to be hidden. */
51 public void waitUntilSplashscreenHides() { 68 public void waitUntilSplashscreenHides() {
52 CriteriaHelper.pollInstrumentationThread(new Criteria() { 69 CriteriaHelper.pollInstrumentationThread(new Criteria() {
53 @Override 70 @Override
54 public boolean isSatisfied() { 71 public boolean isSatisfied() {
55 return !getActivity().isSplashScreenVisibleForTests(); 72 return !mActivityTestRule.getActivity().isSplashScreenVisibleFor Tests();
56 } 73 }
57 }); 74 });
58 } 75 }
59 76
60 @Override 77 @Before
61 public final void startMainActivity() throws InterruptedException { 78 public void setUp() throws Exception {
62 // Do nothing 79 mTestServer = EmbeddedTestServer.createAndStartServer(
63 } 80 InstrumentationRegistry.getInstrumentation().getContext());
64
65 @Override
66 protected void setUp() throws Exception {
67 super.setUp();
68 mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation ().getContext());
69 WebApkUpdateManager.setUpdatesEnabledForTesting(false); 81 WebApkUpdateManager.setUpdatesEnabledForTesting(false);
70 } 82 }
71 83
72 @Override 84 @After
73 protected void tearDown() throws Exception { 85 public void tearDown() throws Exception {
74 mTestServer.stopAndDestroyServer(); 86 mTestServer.stopAndDestroyServer();
75 super.tearDown();
76 } 87 }
77 88
78 /** 89 /**
79 * Test launching a WebAPK. Test that loading the start page works and that the splashscreen 90 * Test launching a WebAPK. Test that loading the start page works and that the splashscreen
80 * eventually hides. 91 * eventually hides.
81 */ 92 */
93 @Test
82 @LargeTest 94 @LargeTest
83 @Feature({"WebApk"}) 95 @Feature({"WebApk"})
84 @RetryOnFailure 96 @RetryOnFailure
85 public void testLaunch() throws InterruptedException { 97 public void testLaunch() throws InterruptedException {
86 startWebApkActivity("org.chromium.webapk.test", 98 startWebApkActivity("org.chromium.webapk.test",
87 mTestServer.getURL("/chrome/test/data/android/test.html")); 99 mTestServer.getURL("/chrome/test/data/android/test.html"));
88 waitUntilSplashscreenHides(); 100 waitUntilSplashscreenHides();
89 } 101 }
90 } 102 }
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