Index: chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java |
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java |
index 1d2271e8ecf5ba03fb46c440cdb51815c68b381c..8e30c9069ab6ee4104b9b4b1e58848f0c23520ac 100644 |
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java |
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webapps/WebappSplashScreenTest.java |
@@ -28,11 +28,31 @@ import org.chromium.chrome.browser.ShortcutHelper; |
import org.chromium.chrome.browser.metrics.WebappUma; |
import org.chromium.chrome.browser.tab.Tab; |
import org.chromium.chrome.browser.tab.TabTestUtils; |
+import org.chromium.content.browser.test.util.Criteria; |
+import org.chromium.content.browser.test.util.CriteriaHelper; |
/** |
* Tests for splash screens. |
*/ |
public class WebappSplashScreenTest extends WebappActivityTestBase { |
+ |
+ private boolean mCallbackCalled; |
+ |
+ private class CallbackCriteria extends Criteria { |
+ public CallbackCriteria() { |
+ mCallbackCalled = false; |
+ } |
+ |
+ @Override |
+ public boolean isSatisfied() { |
+ if (mCallbackCalled) { |
+ mCallbackCalled = false; |
+ return true; |
+ } |
+ return false; |
+ } |
+ } |
+ |
private int getHistogramTotalCountFor(String histogram, int buckets) { |
int count = 0; |
@@ -235,9 +255,18 @@ public class WebappSplashScreenTest extends WebappActivityTestBase { |
Context context = getInstrumentation().getTargetContext(); |
int thresholdSize = context.getResources().getDimensionPixelSize( |
R.dimen.webapp_splash_image_size_threshold); |
- int bitmapSize = thresholdSize + 1; |
- Bitmap splashBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888); |
- WebappDataStorage.open(WEBAPP_ID).updateSplashScreenImage(splashBitmap); |
+ int size = thresholdSize + 1; |
+ final Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
+ |
+ WebappRegistry.getInstance().register( |
+ WEBAPP_ID, new WebappRegistry.FetchWebappDataStorageCallback() { |
+ @Override |
+ public void onWebappDataStorageRetrieved(WebappDataStorage storage) { |
+ mCallbackCalled = true; |
+ storage.updateSplashScreenImage(splashBitmap); |
+ } |
+ }); |
+ CriteriaHelper.pollUiThread(new CallbackCriteria()); |
startWebappActivity(createIntent()); |
ViewGroup splashScreen = waitUntilSplashScreenAppears(); |
@@ -245,8 +274,8 @@ public class WebappSplashScreenTest extends WebappActivityTestBase { |
ImageView splashImage = |
(ImageView) splashScreen.findViewById(R.id.webapp_splash_screen_icon); |
- assertEquals(bitmapSize, splashImage.getMeasuredWidth()); |
- assertEquals(bitmapSize, splashImage.getMeasuredHeight()); |
+ assertEquals(size, splashImage.getMeasuredWidth()); |
+ assertEquals(size, splashImage.getMeasuredHeight()); |
TextView splashText = (TextView) splashScreen.findViewById(R.id.webapp_splash_screen_name); |
int[] rules = ((RelativeLayout.LayoutParams) splashText.getLayoutParams()).getRules(); |
@@ -262,10 +291,19 @@ public class WebappSplashScreenTest extends WebappActivityTestBase { |
Context context = getInstrumentation().getTargetContext(); |
int thresholdSize = context.getResources().getDimensionPixelSize( |
R.dimen.webapp_splash_image_size_threshold); |
- int bitmapSize = context.getResources().getDimensionPixelSize( |
+ int size = context.getResources().getDimensionPixelSize( |
R.dimen.webapp_splash_image_size_minimum); |
- Bitmap splashBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888); |
- WebappDataStorage.open(WEBAPP_ID).updateSplashScreenImage(splashBitmap); |
+ final Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
+ |
+ WebappRegistry.getInstance().register( |
+ WEBAPP_ID, new WebappRegistry.FetchWebappDataStorageCallback() { |
+ @Override |
+ public void onWebappDataStorageRetrieved(WebappDataStorage storage) { |
+ mCallbackCalled = true; |
+ storage.updateSplashScreenImage(splashBitmap); |
+ } |
+ }); |
+ CriteriaHelper.pollUiThread(new CallbackCriteria()); |
startWebappActivity(createIntent()); |
ViewGroup splashScreen = waitUntilSplashScreenAppears(); |
@@ -289,10 +327,19 @@ public class WebappSplashScreenTest extends WebappActivityTestBase { |
public void testSplashScreenWithoutImageAppears() throws Exception { |
// Register an image that's too small for the splash screen. |
Context context = getInstrumentation().getTargetContext(); |
- int bitmapSize = context.getResources().getDimensionPixelSize( |
+ int size = context.getResources().getDimensionPixelSize( |
R.dimen.webapp_splash_image_size_minimum) - 1; |
- Bitmap splashBitmap = Bitmap.createBitmap(bitmapSize, bitmapSize, Bitmap.Config.ARGB_8888); |
- WebappDataStorage.open(WEBAPP_ID).updateSplashScreenImage(splashBitmap); |
+ final Bitmap splashBitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
+ |
+ WebappRegistry.getInstance().register( |
+ WEBAPP_ID, new WebappRegistry.FetchWebappDataStorageCallback() { |
+ @Override |
+ public void onWebappDataStorageRetrieved(WebappDataStorage storage) { |
+ mCallbackCalled = true; |
+ storage.updateSplashScreenImage(splashBitmap); |
+ } |
+ }); |
+ CriteriaHelper.pollUiThread(new CallbackCriteria()); |
Intent intent = createIntent(); |
intent.putExtra(ShortcutHelper.EXTRA_IS_ICON_GENERATED, true); |