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

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

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

Powered by Google App Engine
This is Rietveld 408576698