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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/tab/TabIdManagerTest.java

Issue 2766373004: Convert the rest of chrome_public_test_apk InstrumentationTestCases to JUnit4 (Closed)
Patch Set: nits and rebase Created 3 years, 8 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
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.tab; 5 package org.chromium.chrome.browser.tab;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.content.SharedPreferences; 8 import android.content.SharedPreferences;
9 import android.support.test.InstrumentationRegistry;
10 import android.support.test.annotation.UiThreadTest;
9 import android.support.test.filters.SmallTest; 11 import android.support.test.filters.SmallTest;
10 import android.test.InstrumentationTestCase; 12 import android.support.test.rule.UiThreadTestRule;
11 import android.test.UiThreadTest; 13
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Rule;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
12 19
13 import org.chromium.base.ContextUtils; 20 import org.chromium.base.ContextUtils;
14 import org.chromium.base.test.util.AdvancedMockContext; 21 import org.chromium.base.test.util.AdvancedMockContext;
22 import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
15 23
16 /** Tests for the TabIdManager. */ 24 /** Tests for the TabIdManager. */
17 public class TabIdManagerTest extends InstrumentationTestCase { 25 @RunWith(ChromeJUnit4ClassRunner.class)
26 public class TabIdManagerTest {
18 Context mContext; 27 Context mContext;
19 28
20 @Override 29 @Rule
30 public UiThreadTestRule mRule = new UiThreadTestRule();
31
32 @Before
21 public void setUp() throws Exception { 33 public void setUp() throws Exception {
22 super.setUp(); 34 mContext = new AdvancedMockContext(
23 mContext = new AdvancedMockContext(getInstrumentation().getTargetContext ()); 35 InstrumentationRegistry.getInstrumentation().getTargetContext()) ;
24 } 36 }
25 37
26 /** Tests that IDs are stored and generated properly. */ 38 /** Tests that IDs are stored and generated properly. */
39 @Test
27 @UiThreadTest 40 @UiThreadTest
28 @SmallTest 41 @SmallTest
29 public void testBasic() { 42 public void testBasic() {
30 SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); 43 SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
31 SharedPreferences.Editor editor = prefs.edit(); 44 SharedPreferences.Editor editor = prefs.edit();
32 editor.putInt(TabIdManager.PREF_NEXT_ID, 11684); 45 editor.putInt(TabIdManager.PREF_NEXT_ID, 11684);
33 editor.apply(); 46 editor.apply();
34 47
35 TabIdManager manager = TabIdManager.getInstance(mContext); 48 TabIdManager manager = TabIdManager.getInstance(mContext);
36 assertEquals("Wrong Tab ID was generated", 49 Assert.assertEquals(
37 11684, manager.generateValidId(Tab.INVALID_TAB_ID)); 50 "Wrong Tab ID was generated", 11684, manager.generateValidId(Tab .INVALID_TAB_ID));
38 51
39 assertEquals("Wrong next Tab ID", 11685, prefs.getInt(TabIdManager.PREF_ NEXT_ID, -1)); 52 Assert.assertEquals(
53 "Wrong next Tab ID", 11685, prefs.getInt(TabIdManager.PREF_NEXT_ ID, -1));
40 } 54 }
41 55
42 /** Tests that the max ID is updated properly. */ 56 /** Tests that the max ID is updated properly. */
57 @Test
43 @UiThreadTest 58 @UiThreadTest
44 @SmallTest 59 @SmallTest
45 public void testIncrementIdCounterTo() { 60 public void testIncrementIdCounterTo() {
46 SharedPreferences prefs = ContextUtils.getAppSharedPreferences(); 61 SharedPreferences prefs = ContextUtils.getAppSharedPreferences();
47 SharedPreferences.Editor editor = prefs.edit(); 62 SharedPreferences.Editor editor = prefs.edit();
48 editor.putInt(TabIdManager.PREF_NEXT_ID, 11684); 63 editor.putInt(TabIdManager.PREF_NEXT_ID, 11684);
49 editor.apply(); 64 editor.apply();
50 65
51 TabIdManager manager = TabIdManager.getInstance(mContext); 66 TabIdManager manager = TabIdManager.getInstance(mContext);
52 assertEquals("Wrong Tab ID was generated", 67 Assert.assertEquals(
53 11684, manager.generateValidId(Tab.INVALID_TAB_ID)); 68 "Wrong Tab ID was generated", 11684, manager.generateValidId(Tab .INVALID_TAB_ID));
54 69
55 assertEquals("Wrong next Tab ID", 11685, prefs.getInt(TabIdManager.PREF_ NEXT_ID, -1)); 70 Assert.assertEquals(
71 "Wrong next Tab ID", 11685, prefs.getInt(TabIdManager.PREF_NEXT_ ID, -1));
56 72
57 manager.incrementIdCounterTo(100); 73 manager.incrementIdCounterTo(100);
58 assertEquals("Didn't stay the same", 11685, prefs.getInt(TabIdManager.PR EF_NEXT_ID, -1)); 74 Assert.assertEquals(
75 "Didn't stay the same", 11685, prefs.getInt(TabIdManager.PREF_NE XT_ID, -1));
59 76
60 manager.incrementIdCounterTo(1000000); 77 manager.incrementIdCounterTo(1000000);
61 assertEquals("Didn't increase", 1000000, prefs.getInt(TabIdManager.PREF_ NEXT_ID, -1)); 78 Assert.assertEquals(
79 "Didn't increase", 1000000, prefs.getInt(TabIdManager.PREF_NEXT_ ID, -1));
62 } 80 }
63 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698