• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
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.net;
6 
7 import static org.junit.Assert.assertEquals;
8 import static org.junit.Assert.assertFalse;
9 import static org.junit.Assert.assertTrue;
10 import static org.junit.Assert.fail;
11 
12 import androidx.test.ext.junit.runners.AndroidJUnit4;
13 import androidx.test.filters.SmallTest;
14 
15 import org.junit.After;
16 import org.junit.Before;
17 import org.junit.Rule;
18 import org.junit.Test;
19 import org.junit.rules.TestName;
20 import org.junit.runner.RunWith;
21 
22 import org.chromium.net.CronetTestRule.CronetTestFramework;
23 import org.chromium.net.CronetTestRule.OnlyRunNativeCronet;
24 import org.chromium.net.CronetTestRule.RequiresMinApi;
25 import org.chromium.net.impl.CronetUrlRequestContext;
26 
27 /**
28  * Tests features of CronetTestRule.
29  */
30 @RunWith(AndroidJUnit4.class)
31 public class CronetTestRuleTest {
32     @Rule
33     public final CronetTestRule mTestRule = new CronetTestRule();
34     @Rule
35     public final TestName mTestName = new TestName();
36 
37     private CronetTestFramework mTestFramework;
38     /**
39      * For any test whose name contains "MustRun", it's enforced that the test must run and set
40      * {@code mTestWasRun} to {@code true}.
41      */
42     private boolean mTestWasRun;
43 
44     @Before
setUp()45     public void setUp() throws Exception {
46         mTestWasRun = false;
47         mTestFramework = mTestRule.startCronetTestFramework();
48     }
49 
50     @After
tearDown()51     public void tearDown() throws Exception {
52         if (mTestName.getMethodName().contains("MustRun") && !mTestWasRun) {
53             fail(mTestName.getMethodName() + " should have run but didn't.");
54         }
55     }
56 
57     @Test
58     @SmallTest
59     @RequiresMinApi(999999999)
testRequiresMinApiDisable()60     public void testRequiresMinApiDisable() {
61         fail("RequiresMinApi failed to disable.");
62     }
63 
64     @Test
65     @SmallTest
66     @RequiresMinApi(-999999999)
testRequiresMinApiMustRun()67     public void testRequiresMinApiMustRun() {
68         mTestWasRun = true;
69     }
70 
71     @Test
72     @SmallTest
73     @OnlyRunNativeCronet
testRunOnlyNativeMustRun()74     public void testRunOnlyNativeMustRun() {
75         assertFalse(mTestRule.testingJavaImpl());
76         assertFalse(mTestWasRun);
77         mTestWasRun = true;
78         assertEquals(mTestFramework.mCronetEngine.getClass(), CronetUrlRequestContext.class);
79     }
80 
81 }
82