mobile/android/base/tests/testThumbnails.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 package org.mozilla.gecko.tests;
michael@0 2
michael@0 3 import org.mozilla.gecko.db.BrowserDB;
michael@0 4
michael@0 5 import android.content.ContentResolver;
michael@0 6 import android.graphics.Color;
michael@0 7
michael@0 8 /**
michael@0 9 * Test for thumbnail updates.
michael@0 10 * - loads 2 pages, each of which yield an HTTP 200
michael@0 11 * - verifies thumbnails are updated for both pages
michael@0 12 * - loads pages again; first page yields HTTP 200, second yields HTTP 404
michael@0 13 * - verifies thumbnail is updated for HTTP 200, but not HTTP 404
michael@0 14 * - finally, test that BrowserDB.removeThumbnails drops the thumbnails
michael@0 15 */
michael@0 16 public class testThumbnails extends BaseTest {
michael@0 17 public void testThumbnails() {
michael@0 18 final String site1Url = getAbsoluteUrl("/robocop/robocop_404.sjs?type=changeColor");
michael@0 19 final String site2Url = getAbsoluteUrl("/robocop/robocop_404.sjs?type=do404");
michael@0 20 final String site1Title = "changeColor";
michael@0 21 final String site2Title = "do404";
michael@0 22
michael@0 23 // the session snapshot runnable is run 500ms after document stop. a
michael@0 24 // 3000ms delay gives us 2.5 seconds to take the screenshot, which
michael@0 25 // should be plenty of time, even on slow devices
michael@0 26 final int thumbnailDelay = 3000;
michael@0 27
michael@0 28 blockForGeckoReady();
michael@0 29
michael@0 30 // load sites; both will return HTTP 200 with a green background
michael@0 31 inputAndLoadUrl(site1Url);
michael@0 32 mSolo.sleep(thumbnailDelay);
michael@0 33 inputAndLoadUrl(site2Url);
michael@0 34 mSolo.sleep(thumbnailDelay);
michael@0 35 inputAndLoadUrl("about:home");
michael@0 36 waitForTest(new ThumbnailTest(site1Title, Color.GREEN), 5000);
michael@0 37 mAsserter.is(getTopSiteThumbnailColor(site1Title), Color.GREEN, "Top site thumbnail updated for HTTP 200");
michael@0 38 waitForTest(new ThumbnailTest(site2Title, Color.GREEN), 5000);
michael@0 39 mAsserter.is(getTopSiteThumbnailColor(site2Title), Color.GREEN, "Top site thumbnail updated for HTTP 200");
michael@0 40
michael@0 41 // load sites again; both will have red background, and do404 will return HTTP 404
michael@0 42 inputAndLoadUrl(site1Url);
michael@0 43 mSolo.sleep(thumbnailDelay);
michael@0 44 inputAndLoadUrl(site2Url);
michael@0 45 mSolo.sleep(thumbnailDelay);
michael@0 46 inputAndLoadUrl("about:home");
michael@0 47 waitForTest(new ThumbnailTest(site1Title, Color.RED), 5000);
michael@0 48 mAsserter.is(getTopSiteThumbnailColor(site1Title), Color.RED, "Top site thumbnail updated for HTTP 200");
michael@0 49 waitForTest(new ThumbnailTest(site2Title, Color.GREEN), 5000);
michael@0 50 mAsserter.is(getTopSiteThumbnailColor(site2Title), Color.GREEN, "Top site thumbnail not updated for HTTP 404");
michael@0 51
michael@0 52 // test dropping thumbnails
michael@0 53 final ContentResolver resolver = getActivity().getContentResolver();
michael@0 54 // check that the thumbnail is non-null
michael@0 55 byte[] thumbnailData = BrowserDB.getThumbnailForUrl(resolver, site1Url);
michael@0 56 mAsserter.ok(thumbnailData != null && thumbnailData.length > 0, "Checking for thumbnail data", "No thumbnail data found");
michael@0 57 // drop thumbnails
michael@0 58 BrowserDB.removeThumbnails(resolver);
michael@0 59 // check that the thumbnail is now null
michael@0 60 thumbnailData = BrowserDB.getThumbnailForUrl(resolver, site1Url);
michael@0 61 mAsserter.ok(thumbnailData == null || thumbnailData.length == 0, "Checking for thumbnail data", "Thumbnail data found");
michael@0 62 }
michael@0 63
michael@0 64 private class ThumbnailTest implements BooleanTest {
michael@0 65 private String mTitle;
michael@0 66 private int mColor;
michael@0 67
michael@0 68 public ThumbnailTest(String title, int color) {
michael@0 69 mTitle = title;
michael@0 70 mColor = color;
michael@0 71 }
michael@0 72
michael@0 73 @Override
michael@0 74 public boolean test() {
michael@0 75 return getTopSiteThumbnailColor(mTitle) == mColor;
michael@0 76 }
michael@0 77 }
michael@0 78
michael@0 79 private int getTopSiteThumbnailColor(String title) {
michael@0 80 // This test is not currently run, so this just needs to compile.
michael@0 81 return -1;
michael@0 82 // ViewGroup topSites = (ViewGroup) getActivity().findViewById(mTopSitesId);
michael@0 83 // if (topSites != null) {
michael@0 84 // final int childCount = topSites.getChildCount();
michael@0 85 // for (int i = 0; i < childCount; i++) {
michael@0 86 // View child = topSites.getChildAt(i);
michael@0 87 // if (child != null) {
michael@0 88 // TextView titleView = (TextView) child.findViewById(R.id.title);
michael@0 89 // if (titleView != null) {
michael@0 90 // if (titleView.getText().equals(title)) {
michael@0 91 // ImageView thumbnailView = (ImageView) child.findViewById(R.id.thumbnail);
michael@0 92 // if (thumbnailView != null) {
michael@0 93 // Bitmap thumbnail = ((BitmapDrawable) thumbnailView.getDrawable()).getBitmap();
michael@0 94 // return thumbnail.getPixel(0, 0);
michael@0 95 // } else {
michael@0 96 // mAsserter.dumpLog("getTopSiteThumbnailColor: unable to find mThumbnailId: "+R.id.thumbnail);
michael@0 97 // }
michael@0 98 // }
michael@0 99 // } else {
michael@0 100 // mAsserter.dumpLog("getTopSiteThumbnailColor: unable to find R.id.title: "+R.id.title);
michael@0 101 // }
michael@0 102 // } else {
michael@0 103 // mAsserter.dumpLog("getTopSiteThumbnailColor: skipped null child at index "+i);
michael@0 104 // }
michael@0 105 // }
michael@0 106 // } else {
michael@0 107 // mAsserter.dumpLog("getTopSiteThumbnailColor: unable to find mTopSitesId: " + mTopSitesId);
michael@0 108 // }
michael@0 109 // return -1;
michael@0 110 }
michael@0 111 }

mercurial