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

Side by Side Diff: components/variations/android/junit/src/org/chromium/components/variations/firstrun/VariationsSeedFetcherTest.java

Issue 2970993002: Add AwVariationsSeedFetcher and refactory VariationsSeedFetcher (Closed)
Patch Set: Update unittest Created 3 years, 5 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 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
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.VARIATIONS_SERVER_URL
59 + VariationsSeedFetcher.VARIATIONS_PLATFORM,
Alexei Svitkine (slow) 2017/07/06 22:01:10 It's not great to leak the details of how to const
60 "");
57 mPrefs = ContextUtils.getAppSharedPreferences(); 61 mPrefs = ContextUtils.getAppSharedPreferences();
58 mPrefs.edit().clear().apply(); 62 mPrefs.edit().clear().apply();
59 } 63 }
60 64
61 @After 65 @After
62 public void tearDown() { 66 public void tearDown() {
63 ThreadUtils.setUiThread(null); 67 ThreadUtils.setUiThread(null);
64 } 68 }
65 69
66 /** 70 /**
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 @Test 129 @Test
126 public void testFetchSeed_IOException() throws IOException { 130 public void testFetchSeed_IOException() throws IOException {
127 doThrow(new IOException()).when(mConnection).connect(); 131 doThrow(new IOException()).when(mConnection).connect();
128 132
129 mFetcher.fetchSeed(""); 133 mFetcher.fetchSeed("");
130 134
131 assertTrue(mPrefs.getBoolean(VariationsSeedFetcher.VARIATIONS_INITIALIZE D_PREF, false)); 135 assertTrue(mPrefs.getBoolean(VariationsSeedFetcher.VARIATIONS_INITIALIZE D_PREF, false));
132 assertFalse(VariationsSeedBridge.hasJavaPref()); 136 assertFalse(VariationsSeedBridge.hasJavaPref());
133 } 137 }
134 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698