| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.browserpowertest; |
| 18 |
|
| 19 |
import android.content.Intent; |
| 20 |
import android.app.Instrumentation; |
| 21 |
import android.os.Handler; |
| 22 |
import android.os.Message; |
| 23 |
import android.test.ActivityInstrumentationTestCase2; |
| 24 |
import android.util.Log; |
| 25 |
import junit.framework.*; |
| 26 |
|
| 27 |
public class PowerMeasurement extends ActivityInstrumentationTestCase2<PowerTestActivity> { |
| 28 |
|
| 29 |
private static final String LOGTAG = "PowerMeasurement"; |
| 30 |
private static final String PKG_NAME = "com.android.browserpowertest"; |
| 31 |
private static final String TESTING_URL = |
| 32 |
"http://75.17.48.204:10088/nyt/index.html"; |
| 33 |
private static final int TIME_OUT = 2 * 60 * 1000; |
| 34 |
private static final int DELAY = 0; |
| 35 |
|
| 36 |
public PowerMeasurement() { |
| 37 |
super(PKG_NAME, PowerTestActivity.class); |
| 38 |
} |
| 39 |
|
| 40 |
public void testPageLoadStaticNYTimes() throws Throwable { |
| 41 |
Instrumentation mInst = getInstrumentation(); |
| 42 |
PowerTestActivity act = getActivity(); |
| 43 |
|
| 44 |
Intent intent = new Intent(mInst.getContext(), PowerTestActivity.class); |
| 45 |
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 46 |
long start = System.currentTimeMillis(); |
| 47 |
PowerTestActivity activity = (PowerTestActivity)mInst.startActivitySync( |
| 48 |
intent); |
| 49 |
activity.reset(); |
| 50 |
|
| 51 |
Handler handler = activity.getHandler(); |
| 52 |
Message msg = handler.obtainMessage( |
| 53 |
PowerTestActivity.MSG_NAVIGATE, TIME_OUT, DELAY); |
| 54 |
msg.getData().putString(PowerTestActivity.MSG_NAV_URL, TESTING_URL); |
| 55 |
msg.getData().putBoolean(PowerTestActivity.MSG_NAV_LOGTIME, true); |
| 56 |
|
| 57 |
handler.sendMessage(msg); |
| 58 |
boolean timeoutFlag = activity.waitUntilDone(); |
| 59 |
long end = System.currentTimeMillis(); |
| 60 |
assertFalse(TESTING_URL + " failed to load", timeoutFlag); |
| 61 |
boolean pageErrorFlag = activity.getPageError(); |
| 62 |
assertFalse(TESTING_URL + " is not available, either network is down or the server is down", |
| 63 |
pageErrorFlag); |
| 64 |
Log.v(LOGTAG, "Page is loaded in " + activity.getPageLoadTime() + " ms."); |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
Runtime fileRemoval = Runtime.getRuntime(); |
| 69 |
String cmdBecomeSu = "su"; |
| 70 |
boolean clearCacheSuccess = false; |
| 71 |
try{ |
| 72 |
Process runsum = fileRemoval.exec(cmdBecomeSu); |
| 73 |
int exitVal = runsum.waitFor(); |
| 74 |
String rmfile = "rm -r /data/data/com.android.browserpowertest/cache"; |
| 75 |
Process removal = fileRemoval.exec(rmfile); |
| 76 |
exitVal = removal.waitFor(); |
| 77 |
if (exitVal == 0) { |
| 78 |
clearCacheSuccess = true; |
| 79 |
} |
| 80 |
} catch ( Exception e){ |
| 81 |
assertTrue("Fails to clear the cahche", false); |
| 82 |
} |
| 83 |
assertTrue("Fails to clear the cahche", clearCacheSuccess); |
| 84 |
activity.finish(); |
| 85 |
} |
| 86 |
} |