OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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.components.variations.firstrun; | 5 package org.chromium.components.variations.firstrun; |
6 | 6 |
7 import static org.hamcrest.CoreMatchers.equalTo; | 7 import static org.hamcrest.CoreMatchers.equalTo; |
8 import static org.junit.Assert.assertFalse; | 8 import static org.junit.Assert.assertFalse; |
9 import static org.junit.Assert.assertThat; | 9 import static org.junit.Assert.assertThat; |
10 import static org.junit.Assert.assertTrue; | 10 import static org.junit.Assert.assertTrue; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 private SharedPreferences mPrefs; | 46 private SharedPreferences mPrefs; |
47 | 47 |
48 @Before | 48 @Before |
49 public void setUp() throws IOException { | 49 public void setUp() throws IOException { |
50 ContextUtils.initApplicationContextForTests(RuntimeEnvironment.applicati
on); | 50 ContextUtils.initApplicationContextForTests(RuntimeEnvironment.applicati
on); |
51 // Pretend we are not on the UI thread, since the class we are testing i
s supposed to run | 51 // Pretend we are not on the UI thread, since the class we are testing i
s supposed to run |
52 // only on a background thread. | 52 // only on a background thread. |
53 ThreadUtils.setUiThread(mock(Looper.class)); | 53 ThreadUtils.setUiThread(mock(Looper.class)); |
54 mFetcher = spy(VariationsSeedFetcher.get()); | 54 mFetcher = spy(VariationsSeedFetcher.get()); |
55 mConnection = mock(HttpURLConnection.class); | 55 mConnection = mock(HttpURLConnection.class); |
56 doReturn(mConnection).when(mFetcher).getServerConnection(""); | 56 doReturn(mConnection) |
| 57 .when(mFetcher) |
| 58 .getServerConnection(VariationsSeedFetcher.VariationsPlatform.AN
DROID, ""); |
57 mPrefs = ContextUtils.getAppSharedPreferences(); | 59 mPrefs = ContextUtils.getAppSharedPreferences(); |
58 mPrefs.edit().clear().apply(); | 60 mPrefs.edit().clear().apply(); |
59 } | 61 } |
60 | 62 |
61 @After | 63 @After |
62 public void tearDown() { | 64 public void tearDown() { |
63 ThreadUtils.setUiThread(null); | 65 ThreadUtils.setUiThread(null); |
64 } | 66 } |
65 | 67 |
66 /** | 68 /** |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 @Test | 127 @Test |
126 public void testFetchSeed_IOException() throws IOException { | 128 public void testFetchSeed_IOException() throws IOException { |
127 doThrow(new IOException()).when(mConnection).connect(); | 129 doThrow(new IOException()).when(mConnection).connect(); |
128 | 130 |
129 mFetcher.fetchSeed(""); | 131 mFetcher.fetchSeed(""); |
130 | 132 |
131 assertTrue(mPrefs.getBoolean(VariationsSeedFetcher.VARIATIONS_INITIALIZE
D_PREF, false)); | 133 assertTrue(mPrefs.getBoolean(VariationsSeedFetcher.VARIATIONS_INITIALIZE
D_PREF, false)); |
132 assertFalse(VariationsSeedBridge.hasJavaPref()); | 134 assertFalse(VariationsSeedBridge.hasJavaPref()); |
133 } | 135 } |
134 } | 136 } |
OLD | NEW |