1 // Copyright 2015 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package org.chromium.native_test; 6 7 import android.app.Application; 8 import android.content.Context; 9 10 import org.chromium.base.ApplicationStatus; 11 import org.chromium.base.CommandLine; 12 import org.chromium.base.ContextUtils; 13 import org.chromium.base.library_loader.LibraryLoader; 14 import org.chromium.base.library_loader.LibraryProcessType; 15 16 /** An {@link android.app.Application} for running native browser tests. */ 17 public abstract class NativeBrowserTestApplication extends Application { 18 @Override attachBaseContext(Context base)19 protected void attachBaseContext(Context base) { 20 super.attachBaseContext(base); 21 initApplicationContext(); 22 23 setLibraryProcessType(); 24 if (isBrowserProcess()) { 25 CommandLine.init(new String[] {}); 26 ApplicationStatus.initialize(this); 27 } 28 } 29 setLibraryProcessType()30 protected void setLibraryProcessType() { 31 LibraryLoader.getInstance() 32 .setLibraryProcessType( 33 isBrowserProcess() 34 ? LibraryProcessType.PROCESS_BROWSER 35 : LibraryProcessType.PROCESS_CHILD); 36 } 37 38 /** 39 * Initializes the application context. Subclasses may want to override this if the 40 * application context is initialized elsewhere. 41 */ initApplicationContext()42 protected void initApplicationContext() { 43 ContextUtils.initApplicationContext(this); 44 } 45 isMainProcess()46 protected static boolean isMainProcess() { 47 // The test harness runs in the main process, and browser in :test_process. 48 return !ContextUtils.getProcessName().contains(":"); 49 } 50 isBrowserProcess()51 protected static boolean isBrowserProcess() { 52 // The test harness runs in the main process, and browser in :test_process. 53 return ContextUtils.getProcessName().contains(":test"); 54 } 55 } 56