| 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 | // The purpose of the generator is to provide a sequence of distinct images |
| 8 | // to avoid caching side-effects. As we don't need too many images, I've |
| 9 | // found it easier to hardcode image samples. It is possible to generate |
| 10 | // images on the fly, but it will require hooking up additional packages. |
| 11 | public class ImagePageGenerator { |
| 12 | |
| 13 | public static final String IMAGE_LOADED_STRING = "1"; |
| 14 | public static final String IMAGE_NOT_LOADED_STRING = "0"; |
| 15 | |
| 16 | private final static String[] COLORS = { |
| 17 | "AAAAIAAc3j0Ss", "AQABIAEayS9b0", "AgACIAIQ8BmAc", "AwADIAMW5wvJE", |
| 18 | "BAAEIAQZNWRTI", "BQAFIAUfInYaQ", "BgAGIAYVG0DB4", "BwAHIAcTDFKIg", |
| 19 | "CAAIIAgXCI+Rk", "CQAJIAkRH53Y8", "CgAKIAobJqsDU", "CwALIAsdMblKM", |
| 20 | "DAAMIAwS49bQA", "DQANIA0U9MSZY", "DgAOIA4ezfJCw", "DwAPIA8Y2uALo", |
| 21 | "D+AQAA/9vaUwc", "D/AQEBANNhzkw" |
| 22 | }; |
| 23 | |
| 24 | private final static String IMAGE_PREFIX = "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA" + |
| 25 | "6fptVAAAAAXNSR0IArs4c6QAAAA1JREFUCB0BAgD9/w"; |
| 26 | |
| 27 | private final static String IMAGE_SUFFIX = "AAAAASUVORK5CYII="; |
| 28 | |
| 29 | private int mIndex; |
| 30 | private final boolean mAdvance; |
| 31 | |
| 32 | public ImagePageGenerator(int startIndex, boolean advance) { |
| 33 | mIndex = startIndex; |
| 34 | mAdvance = advance; |
| 35 | } |
| 36 | |
| 37 | public String getImageSourceNoAdvance() { |
| 38 | return IMAGE_PREFIX + COLORS[mIndex] + IMAGE_SUFFIX; |
| 39 | } |
| 40 | |
| 41 | public String getPageTemplateSource(String imageSrc) { |
| 42 | return CommonResources.getOnImageLoadedHtml(imageSrc); |
| 43 | } |
| 44 | |
| 45 | public String getPageSource() { |
| 46 | String result = |
| 47 | getPageTemplateSource("data:image/png;base64," + getImageSourceNoAdvance()); |
| 48 | if (mAdvance) mIndex += 2; |
| 49 | return result; |
| 50 | } |
| 51 | } |