01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.user.client;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19: import com.google.gwt.user.client.ui.Label;
20: import com.google.gwt.user.client.ui.RootPanel;
21:
22: /**
23: * TODO: document me.
24: */
25: public abstract class Profile extends GWTTestCase {
26:
27: public static String REPORT_TO_BROWSER = "Report to Browser";
28: public static String REPORT_TO_EXCEL = "Report to Excel";
29: public static String REPORT_TO_WIKI = "Report to Wiki";
30: private static String browser;
31: private static String reportType = REPORT_TO_WIKI;
32: private static long time;
33:
34: public static void setReportType(String s) {
35: reportType = s;
36: }
37:
38: private void browserTiming(String s) {
39: long elapsed = System.currentTimeMillis() - time;
40: RootPanel.get().add(
41: new Label("|" + browser + "|" + s + "|" + elapsed
42: + " milliseconds|"));
43: }
44:
45: protected void resetTimer() {
46: time = System.currentTimeMillis();
47: if (browser == null) {
48: browser = getBrowser();
49: }
50: }
51:
52: protected void timing(String s) {
53: long elapsed = System.currentTimeMillis() - time;
54: if (reportType == REPORT_TO_BROWSER) {
55: browserTiming(s);
56: } else if (reportType == REPORT_TO_WIKI) {
57: this .addCheckpoint("|" + browser + "|" + s + "|" + elapsed
58: + " milliseconds|");
59: } else if (reportType == REPORT_TO_EXCEL) {
60: s = s.replace('|', '\t');
61: this .addCheckpoint(browser + "\t" + s + "\t" + elapsed);
62: } else {
63: throw new IllegalStateException("Should not ever get here");
64: }
65: }
66:
67: public native String getBrowser() /*-{
68: var ua = navigator.userAgent.toLowerCase();
69: if (ua.indexOf("opera") != -1) {
70: return "opera";
71: }
72: else if (ua.indexOf("safari") != -1) {
73: return "safari";
74: }
75: else if ((ua.indexOf("msie 6.0") != -1) ||
76: (ua.indexOf("msie 7.0") != -1)) {
77: return "ie6";
78: }
79: else if (ua.indexOf("gecko") != -1) {
80: var result = /rv:([0-9]+)\.([0-9]+)/.exec(ua);
81: if (result && result.length == 3) {
82: var version = (parseInt(result[1]) * 10) + parseInt(result[2]);
83: if (version >= 18)
84: return "gecko1_8";
85: }
86: return "gecko";
87: }
88: return "unknown";
89: }-*/;
90: }
|