1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 package org.chromium.android_webview.test.util;
7 import android.util.Pair;
8 import java.util.ArrayList;
11 // Auxiliary class providing common HTML and base64 resources using for testing.
12 public class CommonResources {
14 // Content-type headers used for HTML code.
15 public static List<Pair<String, String>> getTextHtmlHeaders(boolean disableCache) {
16 return getContentTypeAndCacheHeaders("text/html", disableCache);
19 // Content-type headers used for javascript code.
20 public static List<Pair<String, String>> getTextJavascriptHeaders(boolean disableCache) {
21 return getContentTypeAndCacheHeaders("text/javascript", disableCache);
24 // Content-type headers used for png images.
25 public static List<Pair<String, String>> getImagePngHeaders(boolean disableCache) {
26 return getContentTypeAndCacheHeaders("image/png", disableCache);
29 public static List<Pair<String, String>> getContentTypeAndCacheHeaders(
30 String contentType, boolean disableCache) {
31 List<Pair<String, String>> headers = new ArrayList<Pair<String, String>>();
32 headers.add(Pair.create("Content-Type", contentType));
33 if (disableCache) headers.add(Pair.create("Cache-Control", "no-store"));
37 // Returns the HTML code used to verify if an image has been successfully loaded.
38 public static String getOnImageLoadedHtml(String imageSrc) {
42 " function updateTitle() {" +
43 " document.title=document.getElementById('img').naturalHeight" +
47 " <body onload='updateTitle();'>" +
48 " <img id='img' onload='updateTitle();' src='" + imageSrc + "'>" +
53 // Default name for the favicon image.
54 public static final String FAVICON_FILENAME = "favicon.png";
56 // HTML code of a static simple page with a favicon.
57 public static final String FAVICON_STATIC_HTML =
58 "<html><head><link rel=\"icon\" type=\"image/png\" href=\"" + FAVICON_FILENAME + "\">" +
59 "</head><body>Favicon example</body></html>";
61 // Base64 data of a favicon image resource.
62 public static final String FAVICON_DATA_BASE64 =
63 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAFCAYAAABM6GxJAAAABHNCSVQICAgIfAhkiAAAASJJREFU" +
64 "GJU9yDtLQnEYwOHfOZ40L3gZDJKgJCKaamvpGzS09wUaormh7xA0S5C0ZDTkZJsNUltkkpAUZkIX" +
65 "L3g9FzzH/9vm9vAgoqRUGUu20JHTXFfafUdERJSIKJnOPFUTERHpqIYclY5nb2QKFumky95OlO+W" +
66 "TSgATqOO5k3xr6ZxelXmDFDhdaqfLkPRWQglULaN/V5DPzl3iIb9xCI+Eskog/wdyhowLlb4vThE" +
67 "giF8zRsurx55beg8lMfMezZW9hqz20M/Owhwe2/yUrPI5Ds8//mRehN7JYWxvIX6eWJkbLK9laL8" +
68 "ZrKxFETzxTBNB5SOJjKV/mhCq+uSjGvE4hHc4QA9YGAEwnhWF1ePkCtOWFv0+PiasL8bR3QDr93h" +
69 "HyFup9LWUksHAAAAAElFTkSuQmCC";
71 // Default name for an example 'about' HTML page.
72 public static final String ABOUT_FILENAME = "about.html";
74 // Title used in the 'about' example.
75 public static final String ABOUT_TITLE = "About the Google";
77 // HTML code of an 'about' example.
78 public static final String ABOUT_HTML =
81 " <title>" + ABOUT_TITLE + "</title>" +
84 " This is the Google!" +
88 public static String makeHtmlPageFrom(String headers, String body) {
91 "<style type=\"text/css\">" +
92 // Make the image take up all of the page so that we don't have to do
93 // any fancy hit target calculations when synthesizing the touch event
95 "img.big { width:100%; height:100%; background-color:blue; }" +
96 ".full_view { height:100%; width:100%; position:absolute; }" +