| 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. |
| 4 | |
| 5 | package org.chromium.android_webview.test.util; |
| 6 | |
| 7 | import android.util.Pair; |
| 8 | import java.util.ArrayList; |
| 9 | import java.util.List; |
| 10 | |
| 11 | // Auxiliary class providing common HTML and base64 resources using for testing. |
| 12 | public class CommonResources { |
| 13 | |
| 14 | // Content-type headers used for HTML code. |
| 15 | public static List<Pair<String, String>> getTextHtmlHeaders(boolean disableCache) { |
| 16 | return getContentTypeAndCacheHeaders("text/html", disableCache); |
| 17 | } |
| 18 | |
| 19 | // Content-type headers used for javascript code. |
| 20 | public static List<Pair<String, String>> getTextJavascriptHeaders(boolean disableCache) { |
| 21 | return getContentTypeAndCacheHeaders("text/javascript", disableCache); |
| 22 | } |
| 23 | |
| 24 | // Content-type headers used for png images. |
| 25 | public static List<Pair<String, String>> getImagePngHeaders(boolean disableCache) { |
| 26 | return getContentTypeAndCacheHeaders("image/png", disableCache); |
| 27 | } |
| 28 | |
| 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")); |
| 34 | return headers; |
| 35 | } |
| 36 | |
| 37 | // Returns the HTML code used to verify if an image has been successfully loaded. |
| 38 | public static String getOnImageLoadedHtml(String imageSrc) { |
| 39 | return "<html>" + |
| 40 | " <head>" + |
| 41 | " <script>" + |
| 42 | " function updateTitle() {" + |
| 43 | " document.title=document.getElementById('img').naturalHeight" + |
| 44 | " }" + |
| 45 | " </script>" + |
| 46 | " </head>" + |
| 47 | " <body onload='updateTitle();'>" + |
| 48 | " <img id='img' onload='updateTitle();' src='" + imageSrc + "'>" + |
| 49 | " </body>" + |
| 50 | "</html>"; |
| 51 | } |
| 52 | |
| 53 | // Default name for the favicon image. |
| 54 | public static final String FAVICON_FILENAME = "favicon.png"; |
| 55 | |
| 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>"; |
| 60 | |
| 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"; |
| 70 | |
| 71 | // Default name for an example 'about' HTML page. |
| 72 | public static final String ABOUT_FILENAME = "about.html"; |
| 73 | |
| 74 | // Title used in the 'about' example. |
| 75 | public static final String ABOUT_TITLE = "About the Google"; |
| 76 | |
| 77 | // HTML code of an 'about' example. |
| 78 | public static final String ABOUT_HTML = |
| 79 | "<html>" + |
| 80 | " <head>" + |
| 81 | " <title>" + ABOUT_TITLE + "</title>" + |
| 82 | " </head>" + |
| 83 | " <body>" + |
| 84 | " This is the Google!" + |
| 85 | " </body>" + |
| 86 | "</html>"; |
| 87 | |
| 88 | public static String makeHtmlPageFrom(String headers, String body) { |
| 89 | return "<html>" + |
| 90 | "<head>" + |
| 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 |
| 94 | // to click it. |
| 95 | "img.big { width:100%; height:100%; background-color:blue; }" + |
| 96 | ".full_view { height:100%; width:100%; position:absolute; }" + |
| 97 | "</style>" + |
| 98 | headers + |
| 99 | "</head>" + |
| 100 | "<body>" + |
| 101 | body + |
| 102 | "</body>" + |
| 103 | "</html>"; |
| 104 | } |
| 105 | } |