| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.test; | 5 package org.chromium.content.browser.test; |
| 6 | 6 |
| 7 import android.test.InstrumentationTestCase; | 7 import android.test.InstrumentationTestCase; |
| 8 | 8 |
| 9 import org.chromium.base.ContextUtils; |
| 9 import org.chromium.base.PathUtils; | 10 import org.chromium.base.PathUtils; |
| 10 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
| 11 import org.chromium.base.library_loader.LibraryLoader; | 12 import org.chromium.base.library_loader.LibraryLoader; |
| 12 import org.chromium.base.library_loader.LibraryProcessType; | 13 import org.chromium.base.library_loader.LibraryProcessType; |
| 13 import org.chromium.base.library_loader.ProcessInitException; | 14 import org.chromium.base.library_loader.ProcessInitException; |
| 14 import org.chromium.content.browser.BrowserStartupController; | 15 import org.chromium.content.browser.BrowserStartupController; |
| 15 import org.chromium.content.browser.test.util.ApplicationUtils; | 16 import org.chromium.content.browser.test.util.ApplicationUtils; |
| 16 | 17 |
| 17 /** | 18 /** |
| 18 * Test extension that adds support for loading and dealing with native librarie
s. | 19 * Test extension that adds support for loading and dealing with native librarie
s. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 32 * After loading the library, this will initialize the browser process. | 33 * After loading the library, this will initialize the browser process. |
| 33 */ | 34 */ |
| 34 public void loadNativeLibraryAndInitBrowserProcess() { | 35 public void loadNativeLibraryAndInitBrowserProcess() { |
| 35 handleNativeInitialization(true); | 36 handleNativeInitialization(true); |
| 36 } | 37 } |
| 37 | 38 |
| 38 private void handleNativeInitialization(final boolean initBrowserProcess) { | 39 private void handleNativeInitialization(final boolean initBrowserProcess) { |
| 39 assertFalse(ThreadUtils.runningOnUiThread()); | 40 assertFalse(ThreadUtils.runningOnUiThread()); |
| 40 | 41 |
| 41 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, | 42 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, |
| 42 getInstrumentation().getTargetContext()); | 43 ContextUtils.getApplicationContext()); |
| 43 | 44 |
| 44 try { | 45 try { |
| 45 ApplicationUtils.waitForLibraryDependencies(getInstrumentation()); | 46 ApplicationUtils.waitForLibraryDependencies(getInstrumentation()); |
| 46 } catch (InterruptedException e) { | 47 } catch (InterruptedException e) { |
| 47 fail("Library dependencies were never initialized."); | 48 fail("Library dependencies were never initialized."); |
| 48 } | 49 } |
| 49 | 50 |
| 50 // LibraryLoader is not in general multithreaded; as other Instrumentati
onTestCase code | 51 // LibraryLoader is not in general multithreaded; as other Instrumentati
onTestCase code |
| 51 // (specifically, ChromeBrowserProvider) uses it from the main thread we
must do | 52 // (specifically, ChromeBrowserProvider) uses it from the main thread we
must do |
| 52 // likewise. | 53 // likewise. |
| 53 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 54 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 54 @Override | 55 @Override |
| 55 public void run() { | 56 public void run() { |
| 56 nativeInitialization(initBrowserProcess); | 57 nativeInitialization(initBrowserProcess); |
| 57 } | 58 } |
| 58 }); | 59 }); |
| 59 } | 60 } |
| 60 | 61 |
| 61 private void nativeInitialization(boolean initBrowserProcess) { | 62 private void nativeInitialization(boolean initBrowserProcess) { |
| 62 if (initBrowserProcess) { | 63 if (initBrowserProcess) { |
| 63 try { | 64 try { |
| 64 BrowserStartupController.get(getInstrumentation().getTargetConte
xt(), | 65 BrowserStartupController.get(ContextUtils.getApplicationContext(
), |
| 65 LibraryProcessType.PROCESS_BROWSER).startBrowserProcesse
sSync(false); | 66 LibraryProcessType.PROCESS_BROWSER).startBrowserProcesse
sSync(false); |
| 66 } catch (ProcessInitException e) { | 67 } catch (ProcessInitException e) { |
| 67 throw new Error(e); | 68 throw new Error(e); |
| 68 } | 69 } |
| 69 } else { | 70 } else { |
| 70 try { | 71 try { |
| 71 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER) | 72 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInit
ialized(); |
| 72 .ensureInitialized(getInstrumentation().getTargetContext
()); | |
| 73 } catch (ProcessInitException e) { | 73 } catch (ProcessInitException e) { |
| 74 throw new Error(e); | 74 throw new Error(e); |
| 75 } | 75 } |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 } | 78 } |
| OLD | NEW |