OLD | NEW |
---|---|
1 // Copyright 2013 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.content.browser; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.support.test.filters.SmallTest; | 7 import android.support.test.filters.SmallTest; |
8 import android.test.InstrumentationTestCase; | |
9 | 8 |
10 import org.chromium.base.ThreadUtils; | 9 import org.chromium.base.ThreadUtils; |
11 import org.chromium.base.library_loader.LibraryProcessType; | 10 import org.chromium.base.library_loader.LibraryProcessType; |
12 import org.chromium.base.library_loader.LoaderErrors; | 11 import org.chromium.base.library_loader.LoaderErrors; |
13 import org.chromium.base.library_loader.ProcessInitException; | 12 import org.chromium.base.library_loader.ProcessInitException; |
13 import org.junit.Test; | |
jbudorick
2017/03/01 23:10:19
import order?
I'm surprised this wasn't flagged e
the real yoland
2017/03/08 23:35:31
Oops, my bad, I bypassed this one.
Fixed now
| |
14 import org.chromium.base.test.BaseJUnit4ClassRunner; | |
15 import org.junit.runner.RunWith; | |
16 import android.support.test.InstrumentationRegistry; | |
17 import org.junit.Assert; | |
18 import org.junit.Before; | |
14 | 19 |
15 /** | 20 /** |
16 * Test of BrowserStartupController | 21 * Test of BrowserStartupController |
17 */ | 22 */ |
18 public class BrowserStartupControllerTest extends InstrumentationTestCase { | 23 @RunWith(BaseJUnit4ClassRunner.class) |
24 public class BrowserStartupControllerTest { | |
19 | 25 |
20 private TestBrowserStartupController mController; | 26 private TestBrowserStartupController mController; |
21 | 27 |
22 private static class TestBrowserStartupController extends BrowserStartupCont roller { | 28 private static class TestBrowserStartupController extends BrowserStartupCont roller { |
23 | 29 |
24 private int mStartupResult; | 30 private int mStartupResult; |
25 private boolean mLibraryLoadSucceeds; | 31 private boolean mLibraryLoadSucceeds; |
26 private int mInitializedCounter = 0; | 32 private int mInitializedCounter = 0; |
27 | 33 |
28 @Override | 34 @Override |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 } | 83 } |
78 | 84 |
79 @Override | 85 @Override |
80 public void onFailure() { | 86 public void onFailure() { |
81 assert !mHasStartupResult; | 87 assert !mHasStartupResult; |
82 mWasFailure = true; | 88 mWasFailure = true; |
83 mHasStartupResult = true; | 89 mHasStartupResult = true; |
84 } | 90 } |
85 } | 91 } |
86 | 92 |
87 @Override | 93 @Before |
88 protected void setUp() throws Exception { | 94 |
jbudorick
2017/03/01 23:10:19
There shouldn't be a blank line here.
the real yoland
2017/03/08 23:35:31
Done, fixed for all tests
| |
89 super.setUp(); | 95 public void setUp() throws Exception { |
90 mController = new TestBrowserStartupController(); | 96 mController = new TestBrowserStartupController(); |
91 // Setting the static singleton instance field enables more correct test ing, since it is | 97 // Setting the static singleton instance field enables more correct test ing, since it is |
92 // is possible to call {@link BrowserStartupController#browserStartupCom plete(int)} instead | 98 // is possible to call {@link BrowserStartupController#browserStartupCom plete(int)} instead |
93 // of {@link BrowserStartupController#executeEnqueuedCallbacks(int, bool ean)} directly. | 99 // of {@link BrowserStartupController#executeEnqueuedCallbacks(int, bool ean)} directly. |
94 BrowserStartupController.overrideInstanceForTest(mController); | 100 BrowserStartupController.overrideInstanceForTest(mController); |
95 } | 101 } |
96 | 102 |
103 @Test | |
97 @SmallTest | 104 @SmallTest |
98 public void testSingleAsynchronousStartupRequest() { | 105 public void testSingleAsynchronousStartupRequest() { |
99 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; | 106 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; |
100 mController.mLibraryLoadSucceeds = true; | 107 mController.mLibraryLoadSucceeds = true; |
101 final TestStartupCallback callback = new TestStartupCallback(); | 108 final TestStartupCallback callback = new TestStartupCallback(); |
102 | 109 |
103 // Kick off the asynchronous startup request. | 110 // Kick off the asynchronous startup request. |
104 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 111 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
105 @Override | 112 @Override |
106 public void run() { | 113 public void run() { |
107 try { | 114 try { |
108 mController.startBrowserProcessesAsync(true, callback); | 115 mController.startBrowserProcessesAsync(true, callback); |
109 } catch (Exception e) { | 116 } catch (Exception e) { |
110 fail("Browser should have started successfully"); | 117 Assert.fail("Browser should have started successfully"); |
111 } | 118 } |
112 } | 119 } |
113 }); | 120 }); |
114 | 121 |
115 assertTrue("Asynchronous mode should have been set.", | 122 Assert.assertTrue("Asynchronous mode should have been set.", |
116 BrowserStartupController.browserMayStartAsynchonously()); | 123 BrowserStartupController.browserMayStartAsynchonously()); |
117 assertEquals("The browser process should have been initialized one time. ", 1, | 124 Assert.assertEquals("The browser process should have been initialized on e time.", 1, |
118 mController.initializedCounter()); | 125 mController.initializedCounter()); |
119 | 126 |
120 // Wait for callbacks to complete. | 127 // Wait for callbacks to complete. |
121 getInstrumentation().waitForIdleSync(); | 128 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
122 | 129 |
123 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); | 130 Assert.assertTrue("Callback should have been executed.", callback.mHasSt artupResult); |
124 assertTrue("Callback should have been a success.", callback.mWasSuccess) ; | 131 Assert.assertTrue("Callback should have been a success.", callback.mWasS uccess); |
125 assertFalse("Callback should be told that the browser process was not al ready started.", | 132 Assert.assertFalse("Callback should be told that the browser process was not already started.", |
126 callback.mAlreadyStarted); | 133 callback.mAlreadyStarted); |
127 } | 134 } |
128 | 135 |
136 @Test | |
129 @SmallTest | 137 @SmallTest |
130 public void testMultipleAsynchronousStartupRequests() { | 138 public void testMultipleAsynchronousStartupRequests() { |
131 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; | 139 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; |
132 mController.mLibraryLoadSucceeds = true; | 140 mController.mLibraryLoadSucceeds = true; |
133 final TestStartupCallback callback1 = new TestStartupCallback(); | 141 final TestStartupCallback callback1 = new TestStartupCallback(); |
134 final TestStartupCallback callback2 = new TestStartupCallback(); | 142 final TestStartupCallback callback2 = new TestStartupCallback(); |
135 final TestStartupCallback callback3 = new TestStartupCallback(); | 143 final TestStartupCallback callback3 = new TestStartupCallback(); |
136 | 144 |
137 // Kick off the asynchronous startup requests. | 145 // Kick off the asynchronous startup requests. |
138 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 146 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
139 @Override | 147 @Override |
140 public void run() { | 148 public void run() { |
141 try { | 149 try { |
142 mController.startBrowserProcessesAsync(true, callback1); | 150 mController.startBrowserProcessesAsync(true, callback1); |
143 } catch (Exception e) { | 151 } catch (Exception e) { |
144 fail("Browser should have started successfully"); | 152 Assert.fail("Browser should have started successfully"); |
145 } | 153 } |
146 } | 154 } |
147 }); | 155 }); |
148 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 156 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
149 @Override | 157 @Override |
150 public void run() { | 158 public void run() { |
151 try { | 159 try { |
152 mController.startBrowserProcessesAsync(true, callback2); | 160 mController.startBrowserProcessesAsync(true, callback2); |
153 } catch (Exception e) { | 161 } catch (Exception e) { |
154 fail("Browser should have started successfully"); | 162 Assert.fail("Browser should have started successfully"); |
155 } | 163 } |
156 } | 164 } |
157 }); | 165 }); |
158 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 166 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
159 @Override | 167 @Override |
160 public void run() { | 168 public void run() { |
161 mController.addStartupCompletedObserver(callback3); | 169 mController.addStartupCompletedObserver(callback3); |
162 } | 170 } |
163 }); | 171 }); |
164 | 172 |
165 assertTrue("Asynchronous mode should have been set.", | 173 Assert.assertTrue("Asynchronous mode should have been set.", |
166 BrowserStartupController.browserMayStartAsynchonously()); | 174 BrowserStartupController.browserMayStartAsynchonously()); |
167 assertEquals("The browser process should have been initialized one time. ", 1, | 175 Assert.assertEquals("The browser process should have been initialized on e time.", 1, |
168 mController.initializedCounter()); | 176 mController.initializedCounter()); |
169 | 177 |
170 // Wait for callbacks to complete. | 178 // Wait for callbacks to complete. |
171 getInstrumentation().waitForIdleSync(); | 179 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
172 | 180 |
173 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult); | 181 Assert.assertTrue("Callback 1 should have been executed.", callback1.mHa sStartupResult); |
174 assertTrue("Callback 1 should have been a success.", callback1.mWasSucce ss); | 182 Assert.assertTrue("Callback 1 should have been a success.", callback1.mW asSuccess); |
175 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult); | 183 Assert.assertTrue("Callback 2 should have been executed.", callback2.mHa sStartupResult); |
176 assertTrue("Callback 2 should have been a success.", callback2.mWasSucce ss); | 184 Assert.assertTrue("Callback 2 should have been a success.", callback2.mW asSuccess); |
177 assertTrue("Callback 3 should have been executed.", callback3.mHasStartu pResult); | 185 Assert.assertTrue("Callback 3 should have been executed.", callback3.mHa sStartupResult); |
178 assertTrue("Callback 3 should have been a success.", callback3.mWasSucce ss); | 186 Assert.assertTrue("Callback 3 should have been a success.", callback3.mW asSuccess); |
179 // Some startup tasks might have been enqueued after the browser process was started, but | 187 // Some startup tasks might have been enqueued after the browser process was started, but |
180 // not the first one which kicked of the startup. | 188 // not the first one which kicked of the startup. |
181 assertFalse("Callback 1 should be told that the browser process was not already started.", | 189 Assert.assertFalse("Callback 1 should be told that the browser process w as not already started.", |
182 callback1.mAlreadyStarted); | 190 callback1.mAlreadyStarted); |
183 } | 191 } |
184 | 192 |
193 @Test | |
185 @SmallTest | 194 @SmallTest |
186 public void testConsecutiveAsynchronousStartupRequests() { | 195 public void testConsecutiveAsynchronousStartupRequests() { |
187 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; | 196 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; |
188 mController.mLibraryLoadSucceeds = true; | 197 mController.mLibraryLoadSucceeds = true; |
189 final TestStartupCallback callback1 = new TestStartupCallback(); | 198 final TestStartupCallback callback1 = new TestStartupCallback(); |
190 final TestStartupCallback callback2 = new TestStartupCallback(); | 199 final TestStartupCallback callback2 = new TestStartupCallback(); |
191 | 200 |
192 // Kick off the asynchronous startup requests. | 201 // Kick off the asynchronous startup requests. |
193 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 202 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
194 @Override | 203 @Override |
195 public void run() { | 204 public void run() { |
196 try { | 205 try { |
197 mController.startBrowserProcessesAsync(true, callback1); | 206 mController.startBrowserProcessesAsync(true, callback1); |
198 } catch (Exception e) { | 207 } catch (Exception e) { |
199 fail("Browser should have started successfully"); | 208 Assert.fail("Browser should have started successfully"); |
200 } | 209 } |
201 } | 210 } |
202 }); | 211 }); |
203 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 212 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
204 @Override | 213 @Override |
205 public void run() { | 214 public void run() { |
206 mController.addStartupCompletedObserver(callback2); | 215 mController.addStartupCompletedObserver(callback2); |
207 } | 216 } |
208 }); | 217 }); |
209 | 218 |
210 assertTrue("Asynchronous mode should have been set.", | 219 Assert.assertTrue("Asynchronous mode should have been set.", |
211 BrowserStartupController.browserMayStartAsynchonously()); | 220 BrowserStartupController.browserMayStartAsynchonously()); |
212 assertEquals("The browser process should have been initialized one time. ", 1, | 221 Assert.assertEquals("The browser process should have been initialized on e time.", 1, |
213 mController.initializedCounter()); | 222 mController.initializedCounter()); |
214 | 223 |
215 // Wait for callbacks to complete. | 224 // Wait for callbacks to complete. |
216 getInstrumentation().waitForIdleSync(); | 225 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
217 | 226 |
218 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult); | 227 Assert.assertTrue("Callback 1 should have been executed.", callback1.mHa sStartupResult); |
219 assertTrue("Callback 1 should have been a success.", callback1.mWasSucce ss); | 228 Assert.assertTrue("Callback 1 should have been a success.", callback1.mW asSuccess); |
220 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult); | 229 Assert.assertTrue("Callback 2 should have been executed.", callback2.mHa sStartupResult); |
221 assertTrue("Callback 2 should have been a success.", callback2.mWasSucce ss); | 230 Assert.assertTrue("Callback 2 should have been a success.", callback2.mW asSuccess); |
222 | 231 |
223 final TestStartupCallback callback3 = new TestStartupCallback(); | 232 final TestStartupCallback callback3 = new TestStartupCallback(); |
224 final TestStartupCallback callback4 = new TestStartupCallback(); | 233 final TestStartupCallback callback4 = new TestStartupCallback(); |
225 | 234 |
226 // Kick off more asynchronous startup requests. | 235 // Kick off more asynchronous startup requests. |
227 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 236 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
228 @Override | 237 @Override |
229 public void run() { | 238 public void run() { |
230 try { | 239 try { |
231 mController.startBrowserProcessesAsync(true, callback3); | 240 mController.startBrowserProcessesAsync(true, callback3); |
232 } catch (Exception e) { | 241 } catch (Exception e) { |
233 fail("Browser should have started successfully"); | 242 Assert.fail("Browser should have started successfully"); |
234 } | 243 } |
235 } | 244 } |
236 }); | 245 }); |
237 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 246 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
238 @Override | 247 @Override |
239 public void run() { | 248 public void run() { |
240 mController.addStartupCompletedObserver(callback4); | 249 mController.addStartupCompletedObserver(callback4); |
241 } | 250 } |
242 }); | 251 }); |
243 | 252 |
244 // Wait for callbacks to complete. | 253 // Wait for callbacks to complete. |
245 getInstrumentation().waitForIdleSync(); | 254 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
246 | 255 |
247 assertTrue("Callback 3 should have been executed.", callback3.mHasStartu pResult); | 256 Assert.assertTrue("Callback 3 should have been executed.", callback3.mHa sStartupResult); |
248 assertTrue("Callback 3 should have been a success.", callback3.mWasSucce ss); | 257 Assert.assertTrue("Callback 3 should have been a success.", callback3.mW asSuccess); |
249 assertTrue("Callback 3 should be told that the browser process was alrea dy started.", | 258 Assert.assertTrue("Callback 3 should be told that the browser process wa s already started.", |
250 callback3.mAlreadyStarted); | 259 callback3.mAlreadyStarted); |
251 assertTrue("Callback 4 should have been executed.", callback4.mHasStartu pResult); | 260 Assert.assertTrue("Callback 4 should have been executed.", callback4.mHa sStartupResult); |
252 assertTrue("Callback 4 should have been a success.", callback4.mWasSucce ss); | 261 Assert.assertTrue("Callback 4 should have been a success.", callback4.mW asSuccess); |
253 assertTrue("Callback 4 should be told that the browser process was alrea dy started.", | 262 Assert.assertTrue("Callback 4 should be told that the browser process wa s already started.", |
254 callback4.mAlreadyStarted); | 263 callback4.mAlreadyStarted); |
255 } | 264 } |
256 | 265 |
266 @Test | |
257 @SmallTest | 267 @SmallTest |
258 public void testSingleFailedAsynchronousStartupRequest() { | 268 public void testSingleFailedAsynchronousStartupRequest() { |
259 mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE; | 269 mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE; |
260 mController.mLibraryLoadSucceeds = true; | 270 mController.mLibraryLoadSucceeds = true; |
261 final TestStartupCallback callback = new TestStartupCallback(); | 271 final TestStartupCallback callback = new TestStartupCallback(); |
262 | 272 |
263 // Kick off the asynchronous startup request. | 273 // Kick off the asynchronous startup request. |
264 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 274 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
265 @Override | 275 @Override |
266 public void run() { | 276 public void run() { |
267 try { | 277 try { |
268 mController.startBrowserProcessesAsync(true, callback); | 278 mController.startBrowserProcessesAsync(true, callback); |
269 } catch (Exception e) { | 279 } catch (Exception e) { |
270 fail("Browser should have started successfully"); | 280 Assert.fail("Browser should have started successfully"); |
271 } | 281 } |
272 } | 282 } |
273 }); | 283 }); |
274 | 284 |
275 assertTrue("Asynchronous mode should have been set.", | 285 Assert.assertTrue("Asynchronous mode should have been set.", |
276 BrowserStartupController.browserMayStartAsynchonously()); | 286 BrowserStartupController.browserMayStartAsynchonously()); |
277 assertEquals("The browser process should have been initialized one time. ", 1, | 287 Assert.assertEquals("The browser process should have been initialized on e time.", 1, |
278 mController.initializedCounter()); | 288 mController.initializedCounter()); |
279 | 289 |
280 // Wait for callbacks to complete. | 290 // Wait for callbacks to complete. |
281 getInstrumentation().waitForIdleSync(); | 291 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
282 | 292 |
283 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); | 293 Assert.assertTrue("Callback should have been executed.", callback.mHasSt artupResult); |
284 assertTrue("Callback should have been a failure.", callback.mWasFailure) ; | 294 Assert.assertTrue("Callback should have been a failure.", callback.mWasF ailure); |
285 } | 295 } |
286 | 296 |
297 @Test | |
287 @SmallTest | 298 @SmallTest |
288 public void testConsecutiveFailedAsynchronousStartupRequests() { | 299 public void testConsecutiveFailedAsynchronousStartupRequests() { |
289 mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE; | 300 mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE; |
290 mController.mLibraryLoadSucceeds = true; | 301 mController.mLibraryLoadSucceeds = true; |
291 final TestStartupCallback callback1 = new TestStartupCallback(); | 302 final TestStartupCallback callback1 = new TestStartupCallback(); |
292 final TestStartupCallback callback2 = new TestStartupCallback(); | 303 final TestStartupCallback callback2 = new TestStartupCallback(); |
293 | 304 |
294 // Kick off the asynchronous startup requests. | 305 // Kick off the asynchronous startup requests. |
295 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 306 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
296 @Override | 307 @Override |
297 public void run() { | 308 public void run() { |
298 try { | 309 try { |
299 mController.startBrowserProcessesAsync(true, callback1); | 310 mController.startBrowserProcessesAsync(true, callback1); |
300 } catch (Exception e) { | 311 } catch (Exception e) { |
301 fail("Browser should have started successfully"); | 312 Assert.fail("Browser should have started successfully"); |
302 } | 313 } |
303 } | 314 } |
304 }); | 315 }); |
305 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 316 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
306 @Override | 317 @Override |
307 public void run() { | 318 public void run() { |
308 mController.addStartupCompletedObserver(callback2); | 319 mController.addStartupCompletedObserver(callback2); |
309 } | 320 } |
310 }); | 321 }); |
311 | 322 |
312 assertTrue("Asynchronous mode should have been set.", | 323 Assert.assertTrue("Asynchronous mode should have been set.", |
313 BrowserStartupController.browserMayStartAsynchonously()); | 324 BrowserStartupController.browserMayStartAsynchonously()); |
314 assertEquals("The browser process should have been initialized one time. ", 1, | 325 Assert.assertEquals("The browser process should have been initialized on e time.", 1, |
315 mController.initializedCounter()); | 326 mController.initializedCounter()); |
316 | 327 |
317 // Wait for callbacks to complete. | 328 // Wait for callbacks to complete. |
318 getInstrumentation().waitForIdleSync(); | 329 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
319 | 330 |
320 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult); | 331 Assert.assertTrue("Callback 1 should have been executed.", callback1.mHa sStartupResult); |
321 assertTrue("Callback 1 should have been a failure.", callback1.mWasFailu re); | 332 Assert.assertTrue("Callback 1 should have been a failure.", callback1.mW asFailure); |
322 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult); | 333 Assert.assertTrue("Callback 2 should have been executed.", callback2.mHa sStartupResult); |
323 assertTrue("Callback 2 should have been a failure.", callback2.mWasFailu re); | 334 Assert.assertTrue("Callback 2 should have been a failure.", callback2.mW asFailure); |
324 | 335 |
325 final TestStartupCallback callback3 = new TestStartupCallback(); | 336 final TestStartupCallback callback3 = new TestStartupCallback(); |
326 final TestStartupCallback callback4 = new TestStartupCallback(); | 337 final TestStartupCallback callback4 = new TestStartupCallback(); |
327 | 338 |
328 // Kick off more asynchronous startup requests. | 339 // Kick off more asynchronous startup requests. |
329 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 340 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
330 @Override | 341 @Override |
331 public void run() { | 342 public void run() { |
332 try { | 343 try { |
333 mController.startBrowserProcessesAsync(true, callback3); | 344 mController.startBrowserProcessesAsync(true, callback3); |
334 } catch (Exception e) { | 345 } catch (Exception e) { |
335 fail("Browser should have started successfully"); | 346 Assert.fail("Browser should have started successfully"); |
336 } | 347 } |
337 } | 348 } |
338 }); | 349 }); |
339 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 350 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
340 @Override | 351 @Override |
341 public void run() { | 352 public void run() { |
342 mController.addStartupCompletedObserver(callback4); | 353 mController.addStartupCompletedObserver(callback4); |
343 } | 354 } |
344 }); | 355 }); |
345 | 356 |
346 // Wait for callbacks to complete. | 357 // Wait for callbacks to complete. |
347 getInstrumentation().waitForIdleSync(); | 358 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
348 | 359 |
349 assertTrue("Callback 3 should have been executed.", callback3.mHasStartu pResult); | 360 Assert.assertTrue("Callback 3 should have been executed.", callback3.mHa sStartupResult); |
350 assertTrue("Callback 3 should have been a failure.", callback3.mWasFailu re); | 361 Assert.assertTrue("Callback 3 should have been a failure.", callback3.mW asFailure); |
351 assertTrue("Callback 4 should have been executed.", callback4.mHasStartu pResult); | 362 Assert.assertTrue("Callback 4 should have been executed.", callback4.mHa sStartupResult); |
352 assertTrue("Callback 4 should have been a failure.", callback4.mWasFailu re); | 363 Assert.assertTrue("Callback 4 should have been a failure.", callback4.mW asFailure); |
353 } | 364 } |
354 | 365 |
366 @Test | |
355 @SmallTest | 367 @SmallTest |
356 public void testSingleSynchronousRequest() { | 368 public void testSingleSynchronousRequest() { |
357 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; | 369 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; |
358 mController.mLibraryLoadSucceeds = true; | 370 mController.mLibraryLoadSucceeds = true; |
359 // Kick off the synchronous startup. | 371 // Kick off the synchronous startup. |
360 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 372 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
361 @Override | 373 @Override |
362 public void run() { | 374 public void run() { |
363 try { | 375 try { |
364 mController.startBrowserProcessesSync(false); | 376 mController.startBrowserProcessesSync(false); |
365 } catch (Exception e) { | 377 } catch (Exception e) { |
366 fail("Browser should have started successfully"); | 378 Assert.fail("Browser should have started successfully"); |
367 } | 379 } |
368 } | 380 } |
369 }); | 381 }); |
370 assertFalse("Synchronous mode should have been set", | 382 Assert.assertFalse("Synchronous mode should have been set", |
371 BrowserStartupController.browserMayStartAsynchonously()); | 383 BrowserStartupController.browserMayStartAsynchonously()); |
372 | 384 |
373 assertEquals("The browser process should have been initialized one time. ", 1, | 385 Assert.assertEquals("The browser process should have been initialized on e time.", 1, |
374 mController.initializedCounter()); | 386 mController.initializedCounter()); |
375 } | 387 } |
376 | 388 |
389 @Test | |
377 @SmallTest | 390 @SmallTest |
378 public void testAsyncThenSyncRequests() { | 391 public void testAsyncThenSyncRequests() { |
379 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; | 392 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; |
380 mController.mLibraryLoadSucceeds = true; | 393 mController.mLibraryLoadSucceeds = true; |
381 final TestStartupCallback callback = new TestStartupCallback(); | 394 final TestStartupCallback callback = new TestStartupCallback(); |
382 | 395 |
383 // Kick off the startups. | 396 // Kick off the startups. |
384 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 397 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
385 @Override | 398 @Override |
386 public void run() { | 399 public void run() { |
387 try { | 400 try { |
388 mController.startBrowserProcessesAsync(true, callback); | 401 mController.startBrowserProcessesAsync(true, callback); |
389 } catch (Exception e) { | 402 } catch (Exception e) { |
390 fail("Browser should have started successfully"); | 403 Assert.fail("Browser should have started successfully"); |
391 } | 404 } |
392 // To ensure that the async startup doesn't complete too soon we have | 405 // To ensure that the async startup doesn't complete too soon we have |
393 // to do both these in a since Runnable instance. This avoids th e | 406 // to do both these in a since Runnable instance. This avoids th e |
394 // unpredictable race that happens in real situations. | 407 // unpredictable race that happens in real situations. |
395 try { | 408 try { |
396 mController.startBrowserProcessesSync(false); | 409 mController.startBrowserProcessesSync(false); |
397 } catch (Exception e) { | 410 } catch (Exception e) { |
398 fail("Browser should have started successfully"); | 411 Assert.fail("Browser should have started successfully"); |
399 } | 412 } |
400 } | 413 } |
401 }); | 414 }); |
402 assertFalse("Synchronous mode should have been set", | 415 Assert.assertFalse("Synchronous mode should have been set", |
403 BrowserStartupController.browserMayStartAsynchonously()); | 416 BrowserStartupController.browserMayStartAsynchonously()); |
404 | 417 |
405 assertEquals("The browser process should have been initialized twice.", 2, | 418 Assert.assertEquals("The browser process should have been initialized tw ice.", 2, |
406 mController.initializedCounter()); | 419 mController.initializedCounter()); |
407 | 420 |
408 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); | 421 Assert.assertTrue("Callback should have been executed.", callback.mHasSt artupResult); |
409 assertTrue("Callback should have been a success.", callback.mWasSuccess) ; | 422 Assert.assertTrue("Callback should have been a success.", callback.mWasS uccess); |
410 assertFalse("Callback should be told that the browser process was not al ready started.", | 423 Assert.assertFalse("Callback should be told that the browser process was not already started.", |
411 callback.mAlreadyStarted); | 424 callback.mAlreadyStarted); |
412 } | 425 } |
413 | 426 |
427 @Test | |
414 @SmallTest | 428 @SmallTest |
415 public void testSyncThenAsyncRequests() { | 429 public void testSyncThenAsyncRequests() { |
416 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; | 430 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; |
417 mController.mLibraryLoadSucceeds = true; | 431 mController.mLibraryLoadSucceeds = true; |
418 final TestStartupCallback callback = new TestStartupCallback(); | 432 final TestStartupCallback callback = new TestStartupCallback(); |
419 | 433 |
420 // Do a synchronous startup first. | 434 // Do a synchronous startup first. |
421 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 435 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
422 @Override | 436 @Override |
423 public void run() { | 437 public void run() { |
424 try { | 438 try { |
425 mController.startBrowserProcessesSync(false); | 439 mController.startBrowserProcessesSync(false); |
426 } catch (Exception e) { | 440 } catch (Exception e) { |
427 fail("Browser should have started successfully"); | 441 Assert.fail("Browser should have started successfully"); |
428 } | 442 } |
429 } | 443 } |
430 }); | 444 }); |
431 | 445 |
432 assertEquals("The browser process should have been initialized once.", 1 , | 446 Assert.assertEquals("The browser process should have been initialized on ce.", 1, |
433 mController.initializedCounter()); | 447 mController.initializedCounter()); |
434 | 448 |
435 assertFalse("Synchronous mode should have been set", | 449 Assert.assertFalse("Synchronous mode should have been set", |
436 BrowserStartupController.browserMayStartAsynchonously()); | 450 BrowserStartupController.browserMayStartAsynchonously()); |
437 | 451 |
438 // Kick off the asynchronous startup request. This should just queue the callback. | 452 // Kick off the asynchronous startup request. This should just queue the callback. |
439 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 453 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
440 @Override | 454 @Override |
441 public void run() { | 455 public void run() { |
442 try { | 456 try { |
443 mController.startBrowserProcessesAsync(true, callback); | 457 mController.startBrowserProcessesAsync(true, callback); |
444 } catch (Exception e) { | 458 } catch (Exception e) { |
445 fail("Browser should have started successfully"); | 459 Assert.fail("Browser should have started successfully"); |
446 } | 460 } |
447 } | 461 } |
448 }); | 462 }); |
449 | 463 |
450 assertEquals("The browser process should not have been initialized a sec ond time.", 1, | 464 Assert.assertEquals("The browser process should not have been initialize d a second time.", 1, |
451 mController.initializedCounter()); | 465 mController.initializedCounter()); |
452 | 466 |
453 // Wait for callbacks to complete. | 467 // Wait for callbacks to complete. |
454 getInstrumentation().waitForIdleSync(); | 468 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
455 | 469 |
456 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); | 470 Assert.assertTrue("Callback should have been executed.", callback.mHasSt artupResult); |
457 assertTrue("Callback should have been a success.", callback.mWasSuccess) ; | 471 Assert.assertTrue("Callback should have been a success.", callback.mWasS uccess); |
458 assertTrue("Callback should be told that the browser process was already started.", | 472 Assert.assertTrue("Callback should be told that the browser process was already started.", |
459 callback.mAlreadyStarted); | 473 callback.mAlreadyStarted); |
460 } | 474 } |
461 | 475 |
476 @Test | |
462 @SmallTest | 477 @SmallTest |
463 public void testLibraryLoadFails() { | 478 public void testLibraryLoadFails() { |
464 mController.mLibraryLoadSucceeds = false; | 479 mController.mLibraryLoadSucceeds = false; |
465 final TestStartupCallback callback = new TestStartupCallback(); | 480 final TestStartupCallback callback = new TestStartupCallback(); |
466 | 481 |
467 // Kick off the asynchronous startup request. | 482 // Kick off the asynchronous startup request. |
468 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 483 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
469 @Override | 484 @Override |
470 public void run() { | 485 public void run() { |
471 try { | 486 try { |
472 mController.startBrowserProcessesAsync(true, callback); | 487 mController.startBrowserProcessesAsync(true, callback); |
473 fail("Browser should not have started successfully"); | 488 Assert.fail("Browser should not have started successfully"); |
474 } catch (Exception e) { | 489 } catch (Exception e) { |
475 // Exception expected, ignore. | 490 // Exception expected, ignore. |
476 } | 491 } |
477 } | 492 } |
478 }); | 493 }); |
479 | 494 |
480 assertEquals("The browser process should not have been initialized.", 0, | 495 Assert.assertEquals("The browser process should not have been initialize d.", 0, |
481 mController.initializedCounter()); | 496 mController.initializedCounter()); |
482 | 497 |
483 // Wait for callbacks to complete. | 498 // Wait for callbacks to complete. |
484 getInstrumentation().waitForIdleSync(); | 499 InstrumentationRegistry.getInstrumentation().waitForIdleSync(); |
485 } | 500 } |
486 | 501 |
487 } | 502 } |
OLD | NEW |