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