Bug 789923 - Test that BrowserDB.removeThumbnails clears thumbnail data. r=mfinkle, lucasr
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 16 Oct 2012 10:07:09 -0400
changeset 110542 47ee1a38fe31ebfffd5aea68095b15ccc2446e83
parent 110541 386b12107730c76308b3f9f444df69538c41d0b8
child 110543 8bef5de35c7444f1f25762630b6b0803f70a060f
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmfinkle, lucasr
bugs789923
milestone19.0a1
Bug 789923 - Test that BrowserDB.removeThumbnails clears thumbnail data. r=mfinkle, lucasr
mobile/android/base/tests/testThumbnails.java.in
--- a/mobile/android/base/tests/testThumbnails.java.in
+++ b/mobile/android/base/tests/testThumbnails.java.in
@@ -1,27 +1,29 @@
 #filter substitution
 package @ANDROID_PACKAGE_NAME@.tests;
 
 import @ANDROID_PACKAGE_NAME@.*;
 import android.app.Activity;
+import android.content.ContentResolver;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.graphics.drawable.BitmapDrawable;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
 
 /**
  * Test for thumbnail updates.
  * - loads 2 pages, each of which yield an HTTP 200
  * - verifies thumbnails are updated for both pages
  * - loads pages again; first page yields HTTP 200, second yields HTTP 404
  * - verifies thumbnail is updated for HTTP 200, but not HTTP 404
+ * - finally, test that BrowserDB.removeThumbnails drops the thumbnails
  */
 public class testThumbnails extends BaseTest {
     private int mTopSitesId;
     private int mThumbnailId;
     private int mTitleId;
 
     @Override
     protected int getTestType() {
@@ -61,16 +63,38 @@ public class testThumbnails extends Base
         mSolo.sleep(thumbnailDelay);
         loadUrl(site2Url);
         mSolo.sleep(thumbnailDelay);
         loadUrl("about:home");
         waitForTest(new ThumbnailTest(site1Title, Color.RED), 5000);
         mAsserter.is(getTopSiteThumbnailColor(site1Title), Color.RED, "Top site thumbnail updated for HTTP 200");
         waitForTest(new ThumbnailTest(site2Title, Color.GREEN), 5000);
         mAsserter.is(getTopSiteThumbnailColor(site2Title), Color.GREEN, "Top site thumbnail not updated for HTTP 404");
+
+        // test dropping thumbnails
+        try {
+            ClassLoader cl = getActivity().getApplicationContext().getClassLoader();
+            Class browserDB = cl.loadClass("org.mozilla.gecko.db.BrowserDB");
+            // check that the thumbnail is non-null
+            byte[] thumbnailData = (byte[])browserDB
+                .getMethod("getThumbnailForUrl", ContentResolver.class, String.class)
+                .invoke(null, getActivity().getContentResolver(), site1Url);
+            mAsserter.ok(thumbnailData != null && thumbnailData.length > 0, "Checking for thumbnail data", "No thumbnail data found");
+            // drop thumbnails
+            browserDB.getMethod("removeThumbnails", ContentResolver.class)
+                .invoke(null, getActivity().getContentResolver());
+            // check that the thumbnail is now null
+            thumbnailData = (byte[])browserDB
+                .getMethod("getThumbnailForUrl", ContentResolver.class, String.class)
+                .invoke(null, getActivity().getContentResolver(), site1Url);
+            mAsserter.ok(thumbnailData == null || thumbnailData.length == 0, "Checking for thumbnail data", "Thumbnail data found");
+        } catch (Exception e) {
+            mAsserter.ok(false, "Testing removing thumbnails", e.toString());
+            mAsserter.dumpLog(e.toString(), e);
+        }
     }
 
     private class ThumbnailTest implements BooleanTest {
         private String mTitle;
         private int mColor;
 
         public ThumbnailTest(String title, int color) {
             mTitle = title;