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