• 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."
21                     + "InstrumentationPackage";
22     public static final String EXTRA_INSTRUMENTATION_CLASS =
23             "org.chromium.test.broker.OnDeviceInstrumentationBroker."
24                     + "InstrumentationClass";
25     public static final String EXTRA_TARGET_ARGS =
26             "org.chromium.test.broker.OnDeviceInstrumentationBroker.TargetArgs";
27     public static final String EXTRA_TEST =
28             "org.chromium.test.broker.OnDeviceInstrumentationBroker.Test";
29 
30     private static final String TAG = "OnDeviceInstrumentationBroker";
31 
32     @Override
onCreate(Bundle savedInstanceState)33     public void onCreate(Bundle savedInstanceState) {
34         super.onCreate(savedInstanceState);
35         Log.d(TAG, "onCreate()");
36     }
37 
38     @Override
onStart()39     public void onStart() {
40         super.onStart();
41 
42         Intent i = getIntent();
43         String instrumentationPackage = i.getStringExtra(EXTRA_INSTRUMENTATION_PACKAGE);
44         String instrumentationClass = i.getStringExtra(EXTRA_INSTRUMENTATION_CLASS);
45         Bundle targetArgs = i.getBundleExtra(EXTRA_TARGET_ARGS);
46         String test = i.getStringExtra(EXTRA_TEST);
47 
48         if (instrumentationPackage == null || instrumentationClass == null) {
49             finish();
50             return;
51         }
52 
53         ComponentName instrumentationComponent =
54                 new ComponentName(instrumentationPackage, instrumentationClass);
55 
56         if (test != null) {
57             targetArgs.putString("class", test);
58         }
59 
60         startInstrumentation(instrumentationComponent, null, targetArgs);
61         finish();
62     }
63 }
64 
65