• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.test.broker;
6 
7 import android.app.Activity;
8 import android.content.ComponentName;
9 import android.content.Intent;
10 import android.os.Bundle;
11 import android.util.Log;
12 
13 /**
14  * An Activity target for OnDeviceInstrumentationDriver that starts the specified
15  * Instrumentation test.
16  */
17 public class OnDeviceInstrumentationBroker extends Activity {
18 
19     public static final String EXTRA_INSTRUMENTATION_PACKAGE =
20             "org.chromium.test.broker.OnDeviceInstrumentationBroker." + "InstrumentationPackage";
21     public static final String EXTRA_INSTRUMENTATION_CLASS =
22             "org.chromium.test.broker.OnDeviceInstrumentationBroker." + "InstrumentationClass";
23     public static final String EXTRA_TARGET_ARGS =
24             "org.chromium.test.broker.OnDeviceInstrumentationBroker.TargetArgs";
25     public static final String EXTRA_TEST =
26             "org.chromium.test.broker.OnDeviceInstrumentationBroker.Test";
27 
28     private static final String TAG = "OnDeviceInstrumentationBroker";
29 
30     @Override
onCreate(Bundle savedInstanceState)31     public void onCreate(Bundle savedInstanceState) {
32         super.onCreate(savedInstanceState);
33         Log.d(TAG, "onCreate()");
34     }
35 
36     @Override
onStart()37     public void onStart() {
38         super.onStart();
39 
40         Intent i = getIntent();
41         String instrumentationPackage = i.getStringExtra(EXTRA_INSTRUMENTATION_PACKAGE);
42         String instrumentationClass = i.getStringExtra(EXTRA_INSTRUMENTATION_CLASS);
43         Bundle targetArgs = i.getBundleExtra(EXTRA_TARGET_ARGS);
44         String test = i.getStringExtra(EXTRA_TEST);
45 
46         if (instrumentationPackage == null || instrumentationClass == null) {
47             finish();
48             return;
49         }
50 
51         ComponentName instrumentationComponent =
52                 new ComponentName(instrumentationPackage, instrumentationClass);
53 
54         if (test != null) {
55             targetArgs.putString("class", test);
56         }
57 
58         startInstrumentation(instrumentationComponent, null, targetArgs);
59         finish();
60     }
61 }
62