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.browser.policy; | 5 package org.chromium.chrome.browser.policy; |
6 | 6 |
7 import android.support.test.filters.SmallTest; | 7 import android.support.test.filters.SmallTest; |
8 | 8 |
| 9 import org.junit.Assert; |
| 10 import org.junit.Before; |
| 11 import org.junit.Rule; |
| 12 import org.junit.Test; |
| 13 import org.junit.runner.RunWith; |
| 14 |
9 import org.chromium.base.ThreadUtils; | 15 import org.chromium.base.ThreadUtils; |
| 16 import org.chromium.base.test.util.CommandLineFlags; |
10 import org.chromium.base.test.util.Feature; | 17 import org.chromium.base.test.util.Feature; |
11 import org.chromium.base.test.util.RetryOnFailure; | 18 import org.chromium.base.test.util.RetryOnFailure; |
12 import org.chromium.chrome.browser.ChromeActivity; | 19 import org.chromium.chrome.browser.ChromeActivity; |
| 20 import org.chromium.chrome.browser.ChromeSwitches; |
13 import org.chromium.chrome.browser.tabmodel.TabModel; | 21 import org.chromium.chrome.browser.tabmodel.TabModel; |
14 import org.chromium.chrome.test.ChromeActivityTestCaseBase; | 22 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 23 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
15 import org.chromium.policy.CombinedPolicyProvider; | 24 import org.chromium.policy.CombinedPolicyProvider; |
16 import org.chromium.policy.PolicyProvider; | 25 import org.chromium.policy.PolicyProvider; |
17 | 26 |
18 /** Instrumentation tests for {@link CombinedPolicyProvider} */ | 27 /** Instrumentation tests for {@link CombinedPolicyProvider} */ |
19 public class CombinedPolicyProviderTest extends ChromeActivityTestCaseBase<Chrom
eActivity> { | 28 @RunWith(ChromeJUnit4ClassRunner.class) |
| 29 @CommandLineFlags.Add({ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE, |
| 30 ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG}) |
| 31 public class CombinedPolicyProviderTest { |
| 32 @Rule |
| 33 public ChromeActivityTestRule<ChromeActivity> mActivityTestRule = |
| 34 new ChromeActivityTestRule<>(ChromeActivity.class); |
| 35 |
20 private static final String DATA_URI = "data:text/plain;charset=utf-8;base64
,dGVzdA=="; | 36 private static final String DATA_URI = "data:text/plain;charset=utf-8;base64
,dGVzdA=="; |
21 | 37 |
22 public CombinedPolicyProviderTest() { | 38 @Before |
23 super(ChromeActivity.class); | 39 public void setUp() throws InterruptedException { |
24 } | 40 mActivityTestRule.startMainActivityOnBlankPage(); |
25 | |
26 @Override | |
27 public void startMainActivity() throws InterruptedException { | |
28 startMainActivityOnBlankPage(); | |
29 } | 41 } |
30 | 42 |
31 /** | 43 /** |
32 * Checks that the {@link CombinedPolicyProvider} properly notifies tabs whe
n incognito mode is | 44 * Checks that the {@link CombinedPolicyProvider} properly notifies tabs whe
n incognito mode is |
33 * disabled. | 45 * disabled. |
34 */ | 46 */ |
35 @Feature({"Policy" }) | 47 @Test |
| 48 @Feature({"Policy"}) |
36 @SmallTest | 49 @SmallTest |
37 @RetryOnFailure | 50 @RetryOnFailure |
38 public void testTerminateIncognitoSon() throws InterruptedException { | 51 public void testTerminateIncognitoSon() throws InterruptedException { |
39 final boolean incognitoMode = true; | 52 final boolean incognitoMode = true; |
40 | 53 |
41 TabModel incognitoTabModel = getActivity().getTabModelSelector().getMode
l(incognitoMode); | 54 TabModel incognitoTabModel = |
42 loadUrlInNewTab(DATA_URI, incognitoMode); | 55 mActivityTestRule.getActivity().getTabModelSelector().getModel(i
ncognitoMode); |
43 loadUrlInNewTab(DATA_URI, incognitoMode); | 56 mActivityTestRule.loadUrlInNewTab(DATA_URI, incognitoMode); |
44 assertEquals(2, incognitoTabModel.getCount()); | 57 mActivityTestRule.loadUrlInNewTab(DATA_URI, incognitoMode); |
| 58 Assert.assertEquals(2, incognitoTabModel.getCount()); |
45 | 59 |
46 final CombinedPolicyProvider provider = CombinedPolicyProvider.get(); | 60 final CombinedPolicyProvider provider = CombinedPolicyProvider.get(); |
47 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 61 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
48 @Override | 62 @Override |
49 public void run() { | 63 public void run() { |
50 provider.registerProvider(new PolicyProvider() { | 64 provider.registerProvider(new PolicyProvider() { |
51 @Override | 65 @Override |
52 public void refresh() { | 66 public void refresh() { |
53 terminateIncognitoSession(); | 67 terminateIncognitoSession(); |
54 } | 68 } |
55 }); | 69 }); |
56 } | 70 } |
57 }); | 71 }); |
58 | 72 |
59 assertEquals(0, incognitoTabModel.getCount()); | 73 Assert.assertEquals(0, incognitoTabModel.getCount()); |
60 } | 74 } |
61 } | 75 } |
OLD | NEW |