OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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.test; | 5 package org.chromium.chrome.test; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.test.InstrumentationTestCase; | 8 import android.test.InstrumentationTestCase; |
9 import android.text.TextUtils; | |
10 | 9 |
11 import org.chromium.base.metrics.RecordHistogram; | |
12 import org.chromium.base.test.util.CommandLineFlags; | 10 import org.chromium.base.test.util.CommandLineFlags; |
13 import org.chromium.base.test.util.parameter.BaseParameter; | 11 import org.chromium.base.test.util.parameter.BaseParameter; |
14 import org.chromium.base.test.util.parameter.Parameter; | 12 import org.chromium.base.test.util.parameter.Parameter; |
15 import org.chromium.base.test.util.parameter.Parameterizable; | 13 import org.chromium.base.test.util.parameter.Parameterizable; |
16 import org.chromium.base.test.util.parameter.parameters.MethodParameter; | 14 import org.chromium.base.test.util.parameter.parameters.MethodParameter; |
17 import org.chromium.chrome.browser.ChromeActivity; | 15 import org.chromium.chrome.browser.ChromeActivity; |
18 import org.chromium.chrome.browser.ChromeSwitches; | 16 import org.chromium.chrome.browser.ChromeSwitches; |
19 import org.chromium.chrome.browser.tab.Tab; | |
20 import org.chromium.chrome.browser.tabmodel.document.DocumentTabModelSelector; | |
21 import org.chromium.chrome.test.util.ApplicationTestUtils; | |
22 import org.chromium.chrome.test.util.browser.tabmodel.document.MockStorageDelega
te; | 17 import org.chromium.chrome.test.util.browser.tabmodel.document.MockStorageDelega
te; |
23 import org.chromium.chrome.test.util.parameters.AddFakeAccountToAppParameter; | 18 import org.chromium.chrome.test.util.parameters.AddFakeAccountToAppParameter; |
24 import org.chromium.chrome.test.util.parameters.AddFakeAccountToOsParameter; | 19 import org.chromium.chrome.test.util.parameters.AddFakeAccountToOsParameter; |
25 import org.chromium.chrome.test.util.parameters.AddGoogleAccountToOsParameter; | 20 import org.chromium.chrome.test.util.parameters.AddGoogleAccountToOsParameter; |
26 import org.chromium.content.browser.test.util.Criteria; | |
27 import org.chromium.content.browser.test.util.CriteriaHelper; | |
28 | 21 |
29 import java.util.HashMap; | 22 import java.util.HashMap; |
30 import java.util.Map; | 23 import java.util.Map; |
31 | 24 |
32 /** | 25 /** |
33 * Base for testing and interacting with multiple Activities (e.g. Document or W
ebapp Activities). | 26 * Base for testing and interacting with multiple Activities (e.g. Document or W
ebapp Activities). |
34 */ | 27 */ |
35 @CommandLineFlags.Add({ | 28 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE}) |
36 ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE | |
37 }) | |
38 public abstract class MultiActivityTestBase extends InstrumentationTestCase | 29 public abstract class MultiActivityTestBase extends InstrumentationTestCase |
39 implements Parameterizable { | 30 implements Parameterizable, MultiActivityTestCommon.MultiActivityTestCom
monCallback { |
| 31 private final MultiActivityTestCommon mTestCommon; |
| 32 |
40 private Parameter.Reader mParameterReader; | 33 private Parameter.Reader mParameterReader; |
| 34 |
41 private Map<String, BaseParameter> mAvailableParameters; | 35 private Map<String, BaseParameter> mAvailableParameters; |
42 protected MockStorageDelegate mStorageDelegate; | 36 |
43 protected Context mContext; | 37 public MultiActivityTestBase() { |
| 38 mTestCommon = new MultiActivityTestCommon(this); |
| 39 } |
44 | 40 |
45 @Override | 41 @Override |
46 public void setUp() throws Exception { | 42 public void setUp() throws Exception { |
47 super.setUp(); | 43 super.setUp(); |
48 RecordHistogram.setDisabledForTests(true); | 44 mTestCommon.setUp(); |
49 mContext = getInstrumentation().getTargetContext(); | |
50 CommandLineFlags.setUp(mContext, getClass().getMethod(getName())); | |
51 ApplicationTestUtils.setUp(mContext, true); | |
52 | |
53 // Make the DocumentTabModelSelector use a mocked out directory so that
test runs don't | |
54 // interfere with each other. | |
55 mStorageDelegate = new MockStorageDelegate(mContext.getCacheDir()); | |
56 DocumentTabModelSelector.setStorageDelegateForTests(mStorageDelegate); | |
57 } | 45 } |
58 | 46 |
59 @Override | 47 @Override |
60 public void tearDown() throws Exception { | 48 public void tearDown() throws Exception { |
61 super.tearDown(); | 49 super.tearDown(); |
62 mStorageDelegate.ensureDirectoryDestroyed(); | 50 mTestCommon.tearDown(); |
63 ApplicationTestUtils.tearDown(mContext); | 51 } |
64 RecordHistogram.setDisabledForTests(false); | 52 |
| 53 public Context getContext() { |
| 54 return mTestCommon.mContext; |
| 55 } |
| 56 |
| 57 public MockStorageDelegate getStorageDelegate() { |
| 58 return mTestCommon.mStorageDelegate; |
65 } | 59 } |
66 | 60 |
67 /** | 61 /** |
68 * See {@link #waitForFullLoad(ChromeActivity,String,boolean)}. | 62 * See {@link #waitForFullLoad(ChromeActivity,String,boolean)}. |
69 */ | 63 */ |
70 protected void waitForFullLoad(final ChromeActivity activity, final String e
xpectedTitle) { | 64 protected void waitForFullLoad(final ChromeActivity activity, final String e
xpectedTitle) { |
71 waitForFullLoad(activity, expectedTitle, false); | 65 mTestCommon.waitForFullLoad(activity, expectedTitle); |
72 } | 66 } |
73 | 67 |
74 /** | 68 /** |
75 * Approximates when a ChromeActivity is fully ready and loaded, which is ha
rd to gauge | 69 * Approximates when a ChromeActivity is fully ready and loaded, which is ha
rd to gauge |
76 * because Android's Activity transition animations are not monitorable. | 70 * because Android's Activity transition animations are not monitorable. |
77 */ | 71 */ |
78 protected void waitForFullLoad(final ChromeActivity activity, final String e
xpectedTitle, | 72 protected void waitForFullLoad(final ChromeActivity activity, final String e
xpectedTitle, |
79 boolean waitLongerForLoad) { | 73 boolean waitLongerForLoad) { |
80 ApplicationTestUtils.assertWaitForPageScaleFactorMatch(activity, 0.5f, w
aitLongerForLoad); | 74 mTestCommon.waitForFullLoad(activity, expectedTitle, waitLongerForLoad); |
81 final Tab tab = activity.getActivityTab(); | |
82 assert tab != null; | |
83 | |
84 CriteriaHelper.pollUiThread(new Criteria() { | |
85 @Override | |
86 public boolean isSatisfied() { | |
87 if (!tab.isLoadingAndRenderingDone()) return false; | |
88 if (!TextUtils.equals(expectedTitle, tab.getTitle())) return fal
se; | |
89 return true; | |
90 } | |
91 }); | |
92 } | 75 } |
93 | 76 |
94 /** | 77 /** |
95 * Creates the {@link Map} of available parameters for the test to use. | 78 * Creates the {@link Map} of available parameters for the test to use. |
96 * | 79 * |
97 * @return a {@link Map} of {@link BaseParameter} objects. | 80 * @return a {@link Map} of {@link BaseParameter} objects. |
98 */ | 81 */ |
99 protected Map<String, BaseParameter> createAvailableParameters() { | 82 protected Map<String, BaseParameter> createAvailableParameters() { |
100 Map<String, BaseParameter> availableParameters = new HashMap<>(); | 83 Map<String, BaseParameter> availableParameters = new HashMap<>(); |
101 availableParameters | 84 availableParameters |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 * Getter method for {@link Parameter.Reader} object to be used by test case
s reading the | 129 * Getter method for {@link Parameter.Reader} object to be used by test case
s reading the |
147 * parameter. | 130 * parameter. |
148 * | 131 * |
149 * @return the {@link Parameter.Reader} for the current {@link | 132 * @return the {@link Parameter.Reader} for the current {@link |
150 * org.chromium.base.test.util.parameter.ParameterizedTest} being run. | 133 * org.chromium.base.test.util.parameter.ParameterizedTest} being run. |
151 */ | 134 */ |
152 protected Parameter.Reader getParameterReader() { | 135 protected Parameter.Reader getParameterReader() { |
153 return mParameterReader; | 136 return mParameterReader; |
154 } | 137 } |
155 } | 138 } |
OLD | NEW |