2 * Copyright (C) 2011 0xlab - http://0xlab.org/
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * Authored by Julian Chu <walkingice@0xlab.org>
19 package org.zeroxlab.benchmark;
21 import android.app.Activity;
22 import android.os.Bundle;
23 import android.os.Message;
24 import android.content.Intent;
25 import android.webkit.WebView;
26 import android.webkit.WebSettings;
27 import android.util.Log;
29 public class TesterJavascript extends Tester {
31 protected WebView mWebView;
32 protected WebSettings mSettings;
34 private double mTotalTime = 0.0;
35 private String mResult = "";
36 private String mFormattedResult = "";
39 public void onCreate(Bundle savedInstanceState) {
40 super.onCreate(savedInstanceState);
41 setContentView(R.layout.javascript);
42 mWebView = (WebView) findViewById(R.id.web);
44 mSettings = mWebView.getSettings();
45 mSettings.setJavaScriptEnabled(true);
46 mWebView.addJavascriptInterface(new MsgCallback(), "ANDROID_OBJ");
52 public void onResume() {
57 protected String getTag() {
62 protected int sleepBeforeStart() {
67 protected int sleepBetweenRound() {
72 protected void oneRound() {
73 mWebView.loadUrl("file:///android_asset/driver.html");
77 protected boolean saveResult(Intent intent) {
78 intent.putExtra(CaseJavascript.SUNSPIDER_RESULT, mResult);
79 intent.putExtra(CaseJavascript.SUNSPIDER_FORMATTED_RESULT, mFormattedResult);
80 intent.putExtra(CaseJavascript.SUNSPIDER_TOTAL, mTotalTime);
85 public void finish(String result, String formatted_result) {
86 Log.i("Benchmark", "JS result got");
88 mFormattedResult = formatted_result;