AbstractResult.java revision 5f0ccd76a88586ce85c17cb4db058934e693a4fc
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;
18
19import android.os.Bundle;
20import android.os.Message;
21import android.webkit.WebView;
22
23/**
24 * A class that represent a result of the test. It is responsible for returning the result's
25 * raw data and generating its own diff in HTML format.
26 */
27public abstract class AbstractResult {
28
29    public enum TestType {
30        TEXT {
31            @Override
32            public AbstractResult createResult(Bundle bundle) {
33                return new TextResult(bundle);
34            }
35        },
36        RENDER_TREE {
37            @Override
38            public AbstractResult createResult(Bundle bundle) {
39                /** TODO: RenderTree tests are not yet supported */
40                return null;
41            }
42        };
43
44        public abstract AbstractResult createResult(Bundle bundle);
45    }
46
47    public enum ResultCode {
48        PASS("Passed"),
49        FAIL_RESULT_DIFFERS("Failed: different results"),
50        FAIL_NO_EXPECTED_RESULT("Failed: no expected result"),
51        FAIL_TIMED_OUT("Failed: timed out"),
52        FAIL_CRASHED("Failed: crashed");
53
54        private String mTitle;
55
56        private ResultCode(String title) {
57            mTitle = title;
58        }
59
60        @Override
61        public String toString() {
62            return mTitle;
63        }
64    }
65
66    /**
67     * Makes the result object obtain the results of the test from the webview
68     * and store them in the format that suits itself bests. This method is asynchronous.
69     * The message passed as a parameter is a message that should be sent to its target
70     * when the result finishes obtaining the result.
71     *
72     * @param webview
73     * @param resultObtainedMsg
74     */
75    public abstract void obtainActualResults(WebView webview, Message resultObtainedMsg);
76
77    public abstract void setExpectedImageResult(byte[] expectedResult);
78
79    public abstract void setExpectedTextResult(String expectedResult);
80
81    /**
82     * Returns result's image data that can be written to the disk. It can be null
83     * if there is an error of some sort or for example the test times out.
84     *
85     * <p> Some tests will not provide data (like text tests)
86     *
87     * @return
88     *      results image data
89     */
90    public abstract byte[] getActualImageResult();
91
92    /**
93     * Returns result's text data. It can be null
94     * if there is an error of some sort or for example the test times out.
95     *
96     * @return
97     *      results text data
98     */
99    public abstract String getActualTextResult();
100
101    /**
102     * Returns the code of this result.
103     *
104     * @return
105     *      the code of this result
106     */
107    public abstract ResultCode getResultCode();
108
109    /**
110     * Return the type of the result data.
111     *
112     * @return
113     *      the type of the result data.
114     */
115    public abstract TestType getType();
116
117    public abstract String getRelativePath();
118
119    /**
120     * Returns a piece of HTML code that presents a visual diff between a result and
121     * the expected result.
122     *
123     * @return
124     *      a piece of HTML code with a visual diff between the result and the expected result
125     */
126    public abstract String getDiffAsHtml();
127
128    public abstract Bundle getBundle();
129}