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

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/BrowserStartupControllerTest.java

Issue 59533009: Check library version and handle library load errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to second round of review comments. Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.content.Context; 7 import android.content.Context;
8 import android.test.InstrumentationTestCase; 8 import android.test.InstrumentationTestCase;
9 import android.test.suitebuilder.annotation.SmallTest; 9 import android.test.suitebuilder.annotation.SmallTest;
10 10
(...skipping 19 matching lines...) Expand all
30 } 30 }
31 } 31 }
32 32
33 private TestBrowserStartupController(Context context) { 33 private TestBrowserStartupController(Context context) {
34 super(context); 34 super(context);
35 } 35 }
36 36
37 @Override 37 @Override
38 int contentStart() { 38 int contentStart() {
39 mInitializedCounter++; 39 mInitializedCounter++;
40 if(BrowserStartupController.browserMayStartAsynchonously()) { 40 if (BrowserStartupController.browserMayStartAsynchonously()) {
41 // Post to the UI thread to emulate what would happen in a real scenario. 41 // Post to the UI thread to emulate what would happen in a real scenario.
42 ThreadUtils.postOnUiThread(new Runnable() { 42 ThreadUtils.postOnUiThread(new Runnable() {
43 @Override 43 @Override
44 public void run() { 44 public void run() {
45 BrowserStartupController.browserStartupComplete(mStartup Result); 45 BrowserStartupController.browserStartupComplete(mStartup Result);
46 } 46 }
47 }); 47 });
48 } else { 48 } else {
49 BrowserStartupController.browserStartupComplete(mStartupResult); 49 BrowserStartupController.browserStartupComplete(mStartupResult);
50 } 50 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 @SmallTest 92 @SmallTest
93 public void testSingleAsynchronousStartupRequest() { 93 public void testSingleAsynchronousStartupRequest() {
94 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; 94 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
95 mController.mLibraryLoadSucceeds = true; 95 mController.mLibraryLoadSucceeds = true;
96 final TestStartupCallback callback = new TestStartupCallback(); 96 final TestStartupCallback callback = new TestStartupCallback();
97 97
98 // Kick off the asynchronous startup request. 98 // Kick off the asynchronous startup request.
99 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 99 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
100 @Override 100 @Override
101 public void run() { 101 public void run() {
102 mController.startBrowserProcessesAsync(callback); 102 try {
103 mController.startBrowserProcessesAsync(callback);
104 } catch (Exception e) {
105 fail("Browser should have started successfully");
106 }
103 } 107 }
104 }); 108 });
105 109
106 assertTrue("Asynchronous mode should have been set.", 110 assertTrue("Asynchronous mode should have been set.",
107 BrowserStartupController.browserMayStartAsynchonously()); 111 BrowserStartupController.browserMayStartAsynchonously());
108 assertEquals("The browser process should have been initialized one time. ", 112 assertEquals("The browser process should have been initialized one time. ", 1,
109 1, mController.initializedCounter()); 113 mController.initializedCounter());
110 114
111 // Wait for callbacks to complete. 115 // Wait for callbacks to complete.
112 getInstrumentation().waitForIdleSync(); 116 getInstrumentation().waitForIdleSync();
113 117
114 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); 118 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult);
115 assertTrue("Callback should have been a success.", callback.mWasSuccess) ; 119 assertTrue("Callback should have been a success.", callback.mWasSuccess) ;
116 assertFalse("Callback should be told that the browser process was not al ready started.", 120 assertFalse("Callback should be told that the browser process was not al ready started.",
117 callback.mAlreadyStarted); 121 callback.mAlreadyStarted);
118 } 122 }
119 123
120 @SmallTest 124 @SmallTest
121 public void testMultipleAsynchronousStartupRequests() { 125 public void testMultipleAsynchronousStartupRequests() {
122 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; 126 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
123 mController.mLibraryLoadSucceeds = true; 127 mController.mLibraryLoadSucceeds = true;
124 final TestStartupCallback callback1 = new TestStartupCallback(); 128 final TestStartupCallback callback1 = new TestStartupCallback();
125 final TestStartupCallback callback2 = new TestStartupCallback(); 129 final TestStartupCallback callback2 = new TestStartupCallback();
126 final TestStartupCallback callback3 = new TestStartupCallback(); 130 final TestStartupCallback callback3 = new TestStartupCallback();
127 131
128 // Kick off the asynchronous startup requests. 132 // Kick off the asynchronous startup requests.
129 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 133 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
130 @Override 134 @Override
131 public void run() { 135 public void run() {
132 mController.startBrowserProcessesAsync(callback1); 136 try {
137 mController.startBrowserProcessesAsync(callback1);
138 } catch (Exception e) {
139 fail("Browser should have started successfully");
140 }
133 } 141 }
134 }); 142 });
135 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 143 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
136 @Override 144 @Override
137 public void run() { 145 public void run() {
138 mController.startBrowserProcessesAsync(callback2); 146 try {
147 mController.startBrowserProcessesAsync(callback2);
148 } catch (Exception e) {
149 fail("Browser should have started successfully");
150 }
139 } 151 }
140 }); 152 });
141 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 153 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
142 @Override 154 @Override
143 public void run() { 155 public void run() {
144 mController.addStartupCompletedObserver(callback3); 156 mController.addStartupCompletedObserver(callback3);
145 } 157 }
146 }); 158 });
147 159
148 assertTrue("Asynchronous mode should have been set.", 160 assertTrue("Asynchronous mode should have been set.",
149 BrowserStartupController.browserMayStartAsynchonously()); 161 BrowserStartupController.browserMayStartAsynchonously());
150 assertEquals("The browser process should have been initialized one time. ", 162 assertEquals("The browser process should have been initialized one time. ", 1,
151 1, mController.initializedCounter()); 163 mController.initializedCounter());
152 164
153 // Wait for callbacks to complete. 165 // Wait for callbacks to complete.
154 getInstrumentation().waitForIdleSync(); 166 getInstrumentation().waitForIdleSync();
155 167
156 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult); 168 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult);
157 assertTrue("Callback 1 should have been a success.", callback1.mWasSucce ss); 169 assertTrue("Callback 1 should have been a success.", callback1.mWasSucce ss);
158 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult); 170 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult);
159 assertTrue("Callback 2 should have been a success.", callback2.mWasSucce ss); 171 assertTrue("Callback 2 should have been a success.", callback2.mWasSucce ss);
160 assertTrue("Callback 3 should have been executed.", callback3.mHasStartu pResult); 172 assertTrue("Callback 3 should have been executed.", callback3.mHasStartu pResult);
161 assertTrue("Callback 3 should have been a success.", callback3.mWasSucce ss); 173 assertTrue("Callback 3 should have been a success.", callback3.mWasSucce ss);
162 // Some startup tasks might have been enqueued after the browser process was started, but 174 // Some startup tasks might have been enqueued after the browser process was started, but
163 // not the first one which kicked of the startup. 175 // not the first one which kicked of the startup.
164 assertFalse("Callback 1 should be told that the browser process was not already started.", 176 assertFalse("Callback 1 should be told that the browser process was not already started.",
165 callback1.mAlreadyStarted); 177 callback1.mAlreadyStarted);
166 } 178 }
167 179
168 @SmallTest 180 @SmallTest
169 public void testConsecutiveAsynchronousStartupRequests() { 181 public void testConsecutiveAsynchronousStartupRequests() {
170 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; 182 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
171 mController.mLibraryLoadSucceeds = true; 183 mController.mLibraryLoadSucceeds = true;
172 final TestStartupCallback callback1 = new TestStartupCallback(); 184 final TestStartupCallback callback1 = new TestStartupCallback();
173 final TestStartupCallback callback2 = new TestStartupCallback(); 185 final TestStartupCallback callback2 = new TestStartupCallback();
174 186
175 // Kick off the asynchronous startup requests. 187 // Kick off the asynchronous startup requests.
176 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 188 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
177 @Override 189 @Override
178 public void run() { 190 public void run() {
179 mController.startBrowserProcessesAsync(callback1); 191 try {
192 mController.startBrowserProcessesAsync(callback1);
193 } catch (Exception e) {
194 fail("Browser should have started successfully");
195 }
180 } 196 }
181 }); 197 });
182 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 198 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
183 @Override 199 @Override
184 public void run() { 200 public void run() {
185 mController.addStartupCompletedObserver(callback2); 201 mController.addStartupCompletedObserver(callback2);
186 } 202 }
187 }); 203 });
188 204
189 assertTrue("Asynchronous mode should have been set.", 205 assertTrue("Asynchronous mode should have been set.",
190 BrowserStartupController.browserMayStartAsynchonously()); 206 BrowserStartupController.browserMayStartAsynchonously());
191 assertEquals("The browser process should have been initialized one time. ", 207 assertEquals("The browser process should have been initialized one time. ", 1,
192 1, mController.initializedCounter()); 208 mController.initializedCounter());
193 209
194 // Wait for callbacks to complete. 210 // Wait for callbacks to complete.
195 getInstrumentation().waitForIdleSync(); 211 getInstrumentation().waitForIdleSync();
196 212
197 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult); 213 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult);
198 assertTrue("Callback 1 should have been a success.", callback1.mWasSucce ss); 214 assertTrue("Callback 1 should have been a success.", callback1.mWasSucce ss);
199 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult); 215 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult);
200 assertTrue("Callback 2 should have been a success.", callback2.mWasSucce ss); 216 assertTrue("Callback 2 should have been a success.", callback2.mWasSucce ss);
201 217
202 final TestStartupCallback callback3 = new TestStartupCallback(); 218 final TestStartupCallback callback3 = new TestStartupCallback();
203 final TestStartupCallback callback4 = new TestStartupCallback(); 219 final TestStartupCallback callback4 = new TestStartupCallback();
204 220
205 // Kick off more asynchronous startup requests. 221 // Kick off more asynchronous startup requests.
206 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 222 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
207 @Override 223 @Override
208 public void run() { 224 public void run() {
209 mController.startBrowserProcessesAsync(callback3); 225 try {
226 mController.startBrowserProcessesAsync(callback3);
227 } catch (Exception e) {
228 fail("Browser should have started successfully");
229 }
210 } 230 }
211 }); 231 });
212 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 232 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
213 @Override 233 @Override
214 public void run() { 234 public void run() {
215 mController.addStartupCompletedObserver(callback4); 235 mController.addStartupCompletedObserver(callback4);
216 } 236 }
217 }); 237 });
218 238
219 // Wait for callbacks to complete. 239 // Wait for callbacks to complete.
(...skipping 12 matching lines...) Expand all
232 @SmallTest 252 @SmallTest
233 public void testSingleFailedAsynchronousStartupRequest() { 253 public void testSingleFailedAsynchronousStartupRequest() {
234 mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE; 254 mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE;
235 mController.mLibraryLoadSucceeds = true; 255 mController.mLibraryLoadSucceeds = true;
236 final TestStartupCallback callback = new TestStartupCallback(); 256 final TestStartupCallback callback = new TestStartupCallback();
237 257
238 // Kick off the asynchronous startup request. 258 // Kick off the asynchronous startup request.
239 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 259 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
240 @Override 260 @Override
241 public void run() { 261 public void run() {
242 mController.startBrowserProcessesAsync(callback); 262 try {
263 mController.startBrowserProcessesAsync(callback);
264 } catch (Exception e) {
265 fail("Browser should have started successfully");
266 }
243 } 267 }
244 }); 268 });
245 269
246 assertTrue("Asynchronous mode should have been set.", 270 assertTrue("Asynchronous mode should have been set.",
247 BrowserStartupController.browserMayStartAsynchonously()); 271 BrowserStartupController.browserMayStartAsynchonously());
248 assertEquals("The browser process should have been initialized one time. ", 272 assertEquals("The browser process should have been initialized one time. ", 1,
249 1, mController.initializedCounter()); 273 mController.initializedCounter());
250 274
251 // Wait for callbacks to complete. 275 // Wait for callbacks to complete.
252 getInstrumentation().waitForIdleSync(); 276 getInstrumentation().waitForIdleSync();
253 277
254 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); 278 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult);
255 assertTrue("Callback should have been a failure.", callback.mWasFailure) ; 279 assertTrue("Callback should have been a failure.", callback.mWasFailure) ;
256 } 280 }
257 281
258 @SmallTest 282 @SmallTest
259 public void testConsecutiveFailedAsynchronousStartupRequests() { 283 public void testConsecutiveFailedAsynchronousStartupRequests() {
260 mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE; 284 mController.mStartupResult = BrowserStartupController.STARTUP_FAILURE;
261 mController.mLibraryLoadSucceeds = true; 285 mController.mLibraryLoadSucceeds = true;
262 final TestStartupCallback callback1 = new TestStartupCallback(); 286 final TestStartupCallback callback1 = new TestStartupCallback();
263 final TestStartupCallback callback2 = new TestStartupCallback(); 287 final TestStartupCallback callback2 = new TestStartupCallback();
264 288
265 // Kick off the asynchronous startup requests. 289 // Kick off the asynchronous startup requests.
266 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 290 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
267 @Override 291 @Override
268 public void run() { 292 public void run() {
269 mController.startBrowserProcessesAsync(callback1); 293 try {
294 mController.startBrowserProcessesAsync(callback1);
295 } catch (Exception e) {
296 fail("Browser should have started successfully");
297 }
270 } 298 }
271 }); 299 });
272 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 300 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
273 @Override 301 @Override
274 public void run() { 302 public void run() {
275 mController.addStartupCompletedObserver(callback2); 303 mController.addStartupCompletedObserver(callback2);
276 } 304 }
277 }); 305 });
278 306
279 assertTrue("Asynchronous mode should have been set.", 307 assertTrue("Asynchronous mode should have been set.",
280 BrowserStartupController.browserMayStartAsynchonously()); 308 BrowserStartupController.browserMayStartAsynchonously());
281 assertEquals("The browser process should have been initialized one time. ", 309 assertEquals("The browser process should have been initialized one time. ", 1,
282 1, mController.initializedCounter()); 310 mController.initializedCounter());
283 311
284 // Wait for callbacks to complete. 312 // Wait for callbacks to complete.
285 getInstrumentation().waitForIdleSync(); 313 getInstrumentation().waitForIdleSync();
286 314
287 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult); 315 assertTrue("Callback 1 should have been executed.", callback1.mHasStartu pResult);
288 assertTrue("Callback 1 should have been a failure.", callback1.mWasFailu re); 316 assertTrue("Callback 1 should have been a failure.", callback1.mWasFailu re);
289 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult); 317 assertTrue("Callback 2 should have been executed.", callback2.mHasStartu pResult);
290 assertTrue("Callback 2 should have been a failure.", callback2.mWasFailu re); 318 assertTrue("Callback 2 should have been a failure.", callback2.mWasFailu re);
291 319
292 final TestStartupCallback callback3 = new TestStartupCallback(); 320 final TestStartupCallback callback3 = new TestStartupCallback();
293 final TestStartupCallback callback4 = new TestStartupCallback(); 321 final TestStartupCallback callback4 = new TestStartupCallback();
294 322
295 // Kick off more asynchronous startup requests. 323 // Kick off more asynchronous startup requests.
296 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 324 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
297 @Override 325 @Override
298 public void run() { 326 public void run() {
299 mController.startBrowserProcessesAsync(callback3); 327 try {
328 mController.startBrowserProcessesAsync(callback3);
329 } catch (Exception e) {
330 fail("Browser should have started successfully");
331 }
300 } 332 }
301 }); 333 });
302 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 334 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
303 @Override 335 @Override
304 public void run() { 336 public void run() {
305 mController.addStartupCompletedObserver(callback4); 337 mController.addStartupCompletedObserver(callback4);
306 } 338 }
307 }); 339 });
308 340
309 // Wait for callbacks to complete. 341 // Wait for callbacks to complete.
310 getInstrumentation().waitForIdleSync(); 342 getInstrumentation().waitForIdleSync();
311 343
312 assertTrue("Callback 3 should have been executed.", callback3.mHasStartu pResult); 344 assertTrue("Callback 3 should have been executed.", callback3.mHasStartu pResult);
313 assertTrue("Callback 3 should have been a failure.", callback3.mWasFailu re); 345 assertTrue("Callback 3 should have been a failure.", callback3.mWasFailu re);
314 assertTrue("Callback 4 should have been executed.", callback4.mHasStartu pResult); 346 assertTrue("Callback 4 should have been executed.", callback4.mHasStartu pResult);
315 assertTrue("Callback 4 should have been a failure.", callback4.mWasFailu re); 347 assertTrue("Callback 4 should have been a failure.", callback4.mWasFailu re);
316 } 348 }
317 349
318 @SmallTest 350 @SmallTest
319 public void testSingleSynchronousRequest() { 351 public void testSingleSynchronousRequest() {
320 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; 352 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
321 mController.mLibraryLoadSucceeds = true; 353 mController.mLibraryLoadSucceeds = true;
322 // Kick off the synchronous startup. 354 // Kick off the synchronous startup.
323 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 355 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
324 @Override 356 @Override
325 public void run() { 357 public void run() {
326 assertTrue("Browser should have started successfully", 358 try {
327 mController.startBrowserProcessesSync(1)); 359 mController.startBrowserProcessesSync(1);
360 } catch (Exception e) {
361 fail("Browser should have started successfully");
362 }
328 } 363 }
329 }); 364 });
330 assertFalse("Synchronous mode should have been set", 365 assertFalse("Synchronous mode should have been set",
331 BrowserStartupController.browserMayStartAsynchonously()); 366 BrowserStartupController.browserMayStartAsynchonously());
332 367
333 assertEquals("The browser process should have been initialized one time. ", 368 assertEquals("The browser process should have been initialized one time. ", 1,
334 1, mController.initializedCounter()); 369 mController.initializedCounter());
335 } 370 }
336 371
337 @SmallTest 372 @SmallTest
338 public void testAsyncThenSyncRequests() { 373 public void testAsyncThenSyncRequests() {
339 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; 374 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
340 mController.mLibraryLoadSucceeds = true; 375 mController.mLibraryLoadSucceeds = true;
341 final TestStartupCallback callback = new TestStartupCallback(); 376 final TestStartupCallback callback = new TestStartupCallback();
342 377
343 // Kick off the startups. 378 // Kick off the startups.
344 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 379 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
345 @Override 380 @Override
346 public void run() { 381 public void run() {
347 mController.startBrowserProcessesAsync(callback); 382 try {
383 mController.startBrowserProcessesAsync(callback);
384 } catch (Exception e) {
385 fail("Browser should have started successfully");
386 }
348 // To ensure that the async startup doesn't complete too soon we have 387 // To ensure that the async startup doesn't complete too soon we have
349 // to do both these in a since Runnable instance. This avoids th e 388 // to do both these in a since Runnable instance. This avoids th e
350 // unpredictable race that happens in real situations. 389 // unpredictable race that happens in real situations.
351 assertTrue("Browser should have started successfully", 390 try {
352 mController.startBrowserProcessesSync(1)); 391 mController.startBrowserProcessesSync(1);
392 } catch (Exception e) {
393 fail("Browser should have started successfully");
394 }
353 } 395 }
354 }); 396 });
355 assertFalse("Synchronous mode should have been set", 397 assertFalse("Synchronous mode should have been set",
356 BrowserStartupController.browserMayStartAsynchonously()); 398 BrowserStartupController.browserMayStartAsynchonously());
357 399
358 assertEquals("The browser process should have been initialized twice.", 400 assertEquals("The browser process should have been initialized twice.", 2,
359 2, mController.initializedCounter()); 401 mController.initializedCounter());
360 402
361 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); 403 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult);
362 assertTrue("Callback should have been a success.", callback.mWasSuccess) ; 404 assertTrue("Callback should have been a success.", callback.mWasSuccess) ;
363 assertFalse("Callback should be told that the browser process was not al ready started.", 405 assertFalse("Callback should be told that the browser process was not al ready started.",
364 callback.mAlreadyStarted); 406 callback.mAlreadyStarted);
365 } 407 }
366 408
367 @SmallTest 409 @SmallTest
368 public void testSyncThenAsyncRequests() { 410 public void testSyncThenAsyncRequests() {
369 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS; 411 mController.mStartupResult = BrowserStartupController.STARTUP_SUCCESS;
370 mController.mLibraryLoadSucceeds = true; 412 mController.mLibraryLoadSucceeds = true;
371 final TestStartupCallback callback = new TestStartupCallback(); 413 final TestStartupCallback callback = new TestStartupCallback();
372 414
373 // Do a synchronous startup first. 415 // Do a synchronous startup first.
374 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 416 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
375 @Override 417 @Override
376 public void run() { 418 public void run() {
377 assertTrue("Browser should have started successfully", 419 try {
378 mController.startBrowserProcessesSync(1)); 420 mController.startBrowserProcessesSync(1);
421 } catch (Exception e) {
422 fail("Browser should have started successfully");
423 }
379 } 424 }
380 }); 425 });
381 426
382 assertEquals("The browser process should have been initialized once.", 427 assertEquals("The browser process should have been initialized once.", 1 ,
383 1, mController.initializedCounter()); 428 mController.initializedCounter());
384 429
385 assertFalse("Synchronous mode should have been set", 430 assertFalse("Synchronous mode should have been set",
386 BrowserStartupController.browserMayStartAsynchonously()); 431 BrowserStartupController.browserMayStartAsynchonously());
387 432
388 // Kick off the asynchronous startup request. This should just queue the callback. 433 // Kick off the asynchronous startup request. This should just queue the callback.
389 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 434 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
390 @Override 435 @Override
391 public void run() { 436 public void run() {
392 mController.startBrowserProcessesAsync(callback); 437 try {
438 mController.startBrowserProcessesAsync(callback);
439 } catch (Exception e) {
440 fail("Browser should have started successfully");
441 }
393 } 442 }
394 }); 443 });
395 444
396 assertEquals("The browser process should not have been initialized a sec ond time.", 445 assertEquals("The browser process should not have been initialized a sec ond time.", 1,
397 1, mController.initializedCounter()); 446 mController.initializedCounter());
398 447
399 // Wait for callbacks to complete. 448 // Wait for callbacks to complete.
400 getInstrumentation().waitForIdleSync(); 449 getInstrumentation().waitForIdleSync();
401 450
402 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); 451 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult);
403 assertTrue("Callback should have been a success.", callback.mWasSuccess) ; 452 assertTrue("Callback should have been a success.", callback.mWasSuccess) ;
404 assertTrue("Callback should be told that the browser process was already started.", 453 assertTrue("Callback should be told that the browser process was already started.",
405 callback.mAlreadyStarted); 454 callback.mAlreadyStarted);
406 } 455 }
407 456
408 @SmallTest 457 @SmallTest
409 public void testLibraryLoadFails() { 458 public void testLibraryLoadFails() {
410 mController.mLibraryLoadSucceeds = false; 459 mController.mLibraryLoadSucceeds = false;
411 final TestStartupCallback callback = new TestStartupCallback(); 460 final TestStartupCallback callback = new TestStartupCallback();
412 461
413 // Kick off the asynchronous startup request. 462 // Kick off the asynchronous startup request.
414 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 463 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
415 @Override 464 @Override
416 public void run() { 465 public void run() {
417 mController.startBrowserProcessesAsync(callback); 466 try {
467 mController.startBrowserProcessesAsync(callback);
468 } catch (Exception e) {
469 fail("Browser should have started successfully");
470 }
418 } 471 }
419 }); 472 });
420 473
421 assertEquals("The browser process should not have been initialized.", 474 assertEquals("The browser process should not have been initialized.", 0,
422 0, mController.initializedCounter()); 475 mController.initializedCounter());
423 476
424 // Wait for callbacks to complete. 477 // Wait for callbacks to complete.
425 getInstrumentation().waitForIdleSync(); 478 getInstrumentation().waitForIdleSync();
426 479
427 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult); 480 assertTrue("Callback should have been executed.", callback.mHasStartupRe sult);
428 assertFalse("Callback should have been a failure.", callback.mWasSuccess ); 481 assertFalse("Callback should have been a failure.", callback.mWasSuccess );
429 assertFalse("Callback should be told that the browser process was not al ready started.", 482 assertFalse("Callback should be told that the browser process was not al ready started.",
430 callback.mAlreadyStarted); 483 callback.mAlreadyStarted);
431 } 484 }
432 485
433 } 486 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698