1 // Copyright 2022 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.base.test; 6 7 import android.content.Context; 8 9 import org.junit.runners.model.FrameworkMethod; 10 11 import org.chromium.base.library_loader.LibraryLoader; 12 import org.chromium.base.test.BaseJUnit4ClassRunner.TestHook; 13 import org.chromium.base.test.util.Batch; 14 import org.chromium.base.test.util.RequiresRestart; 15 16 /** 17 * PreTestHook used to ensure we don't start the browser process in unit tests. 18 * */ 19 public final class UnitTestNoBrowserProcessHook implements TestHook { 20 @Override run(Context targetContext, FrameworkMethod testMethod)21 public void run(Context targetContext, FrameworkMethod testMethod) { 22 Batch annotation = testMethod.getDeclaringClass().getAnnotation(Batch.class); 23 if (annotation != null && annotation.value().equals(Batch.UNIT_TESTS)) { 24 if (testMethod.getAnnotation(RequiresRestart.class) != null) return; 25 LibraryLoader.setBrowserProcessStartupBlockedForTesting(); 26 } 27 } 28 } 29