Starter.java revision 2e5982a55ac031110ed39515a76f7a5ec9ff2c14
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.dumprendertree2.scriptsupport; 18 19import android.content.Intent; 20import android.test.ActivityInstrumentationTestCase2; 21import android.util.Log; 22 23import com.android.dumprendertree2.TestsListActivity; 24 25/** 26 * A class which provides methods that can be invoked by a script running on the host machine to 27 * run the tests. 28 * 29 * It starts a TestsListActivity and does not return until all the tests finish executing. 30 */ 31public class Starter extends ActivityInstrumentationTestCase2<TestsListActivity> { 32 private static final String LOG_TAG = "Starter"; 33 private boolean mEverythingFinished; 34 35 public Starter() { 36 super(TestsListActivity.class); 37 } 38 39 /** 40 * This method is called from adb to start executing the tests. It doesn't return 41 * until everything is finished so that the script can wait for the end if it needs 42 * to. 43 */ 44 public void startLayoutTests() { 45 ScriptTestRunner runner = (ScriptTestRunner)getInstrumentation(); 46 String relativePath = runner.getTestsRelativePath(); 47 48 Intent intent = new Intent(); 49 intent.setClassName("com.android.dumprendertree2", "TestsListActivity"); 50 intent.setAction(Intent.ACTION_RUN); 51 intent.putExtra(TestsListActivity.EXTRA_TEST_PATH, relativePath); 52 setActivityIntent(intent); 53 getActivity().registerOnEverythingFinishedCallback(new OnEverythingFinishedCallback() { 54 /** This method is safe to call on any thread */ 55 @Override 56 public void onFinished() { 57 synchronized (Starter.this) { 58 mEverythingFinished = true; 59 Starter.this.notifyAll(); 60 } 61 } 62 }); 63 64 synchronized (this) { 65 while (!mEverythingFinished) { 66 try { 67 this.wait(); 68 } catch (InterruptedException e) { 69 Log.e(LOG_TAG, "startLayoutTests()", e); 70 } 71 } 72 } 73 } 74}