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 82c9732ee028a59c3a4cf6ef3618316a0b785863..99db40daf48a13cac6da23fe56aaeb7efc146eb5 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 |
@@ -14,10 +14,15 @@ import android.test.suitebuilder.annotation.SmallTest; |
import android.view.ViewGroup; |
import android.widget.ImageView; |
+import org.chromium.base.ObserverList.RewindableIterator; |
+import org.chromium.base.ThreadUtils; |
import org.chromium.base.test.util.Feature; |
import org.chromium.chrome.R; |
import org.chromium.chrome.browser.ShortcutHelper; |
import org.chromium.chrome.browser.ShortcutSource; |
+import org.chromium.chrome.browser.tab.TabObserver; |
+import org.chromium.content.browser.test.util.Criteria; |
+import org.chromium.content.browser.test.util.CriteriaHelper; |
import org.chromium.content_public.common.ScreenOrientationValues; |
/** |
@@ -27,7 +32,7 @@ public class WebappSplashScreenTest extends WebappActivityTestBase { |
@UiThreadTest |
@SmallTest |
@Feature({"Webapps"}) |
- public void testSplashScreenDoesntUseSmallWebappInfoIcons() { |
+ public void testDoesntUseSmallWebappInfoIcons() { |
int smallSize = getActivity().getResources().getDimensionPixelSize( |
R.dimen.webapp_splash_image_min_size) - 1; |
Bitmap image = Bitmap.createBitmap(smallSize, smallSize, Bitmap.Config.ARGB_8888); |
@@ -44,7 +49,7 @@ public class WebappSplashScreenTest extends WebappActivityTestBase { |
@UiThreadTest |
@SmallTest |
@Feature({"Webapps"}) |
- public void testSplashScreenUsesMinWebappInfoIcons() { |
+ public void testUsesMinWebappInfoIcons() { |
int minSizePx = getActivity().getResources().getDimensionPixelSize( |
R.dimen.webapp_splash_image_min_size); |
Bitmap image = Bitmap.createBitmap(minSizePx, minSizePx, Bitmap.Config.ARGB_8888); |
@@ -63,12 +68,147 @@ public class WebappSplashScreenTest extends WebappActivityTestBase { |
@SmallTest |
@Feature({"Webapps"}) |
@TargetApi(Build.VERSION_CODES.LOLLIPOP) |
- public void testSplashscreenThemeColorWhenNotSpecified() { |
+ public void testThemeColorWhenNotSpecified() { |
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; |
assertEquals(Color.BLACK, getActivity().getWindow().getStatusBarColor()); |
} |
+ @SmallTest |
+ @Feature({"Webapps"}) |
+ public void testHidesAfterFirstPaint() throws InterruptedException { |
+ assertTrue(getActivity().isSplashScreenVisibleForTest()); |
+ |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ RewindableIterator<TabObserver> observers = |
+ getActivity().getActivityTab().getTabObservers(); |
+ while (observers.hasNext()) { |
+ observers.next().didFirstVisuallyNonEmptyPaint(getActivity().getActivityTab()); |
+ } |
+ } |
+ }); |
+ |
+ // Waits for the splashscreen animation to finish. |
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return !getActivity().isSplashScreenVisibleForTest(); |
+ } |
+ })); |
+ } |
+ |
+ @SmallTest |
+ @Feature({"Webapps"}) |
+ public void testHidesAfterCrash() throws InterruptedException { |
+ assertTrue(getActivity().isSplashScreenVisibleForTest()); |
+ |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ RewindableIterator<TabObserver> observers = |
+ getActivity().getActivityTab().getTabObservers(); |
+ while (observers.hasNext()) { |
+ observers.next().onCrash(getActivity().getActivityTab(), true); |
+ } |
+ } |
+ }); |
+ |
+ // Waits for the splashscreen animation to finish. |
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return !getActivity().isSplashScreenVisibleForTest(); |
+ } |
+ })); |
+ } |
+ |
+ @SmallTest |
+ @Feature({"Webapps"}) |
+ public void testHidesAfterLoadCompletes() throws InterruptedException { |
+ assertTrue(getActivity().isSplashScreenVisibleForTest()); |
+ |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ RewindableIterator<TabObserver> observers = |
+ getActivity().getActivityTab().getTabObservers(); |
+ while (observers.hasNext()) { |
+ observers.next().onPageLoadFinished(getActivity().getActivityTab()); |
+ } |
+ } |
+ }); |
+ |
+ // Waits for the splashscreen animation to finish. |
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return !getActivity().isSplashScreenVisibleForTest(); |
+ } |
+ })); |
+ } |
+ |
+ @SmallTest |
+ @Feature({"Webapps"}) |
+ public void testHidesAfterLoadFails() throws InterruptedException { |
+ assertTrue(getActivity().isSplashScreenVisibleForTest()); |
+ |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ RewindableIterator<TabObserver> observers = |
+ getActivity().getActivityTab().getTabObservers(); |
+ while (observers.hasNext()) { |
+ observers.next().onPageLoadFailed(getActivity().getActivityTab(), 0); |
+ } |
+ } |
+ }); |
+ |
+ // Waits for the splashscreen animation to finish. |
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return !getActivity().isSplashScreenVisibleForTest(); |
+ } |
+ })); |
+ } |
+ |
+ @SmallTest |
+ @Feature({"Webapps"}) |
+ public void testHidesAfterMultipleEvents() throws InterruptedException { |
+ assertTrue(getActivity().isSplashScreenVisibleForTest()); |
+ |
+ ThreadUtils.runOnUiThread(new Runnable() { |
+ @Override |
+ public void run() { |
+ RewindableIterator<TabObserver> observers = |
+ getActivity().getActivityTab().getTabObservers(); |
+ while (observers.hasNext()) { |
+ observers.next().onPageLoadFinished(getActivity().getActivityTab()); |
+ } |
+ |
+ observers.rewind(); |
+ while (observers.hasNext()) { |
+ observers.next().onPageLoadFailed(getActivity().getActivityTab(), 0); |
+ } |
+ |
+ observers.rewind(); |
+ while (observers.hasNext()) { |
+ observers.next().didFirstVisuallyNonEmptyPaint(getActivity().getActivityTab()); |
+ } |
+ } |
+ }); |
+ |
+ // Waits for the splashscreen animation to finish. |
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
+ @Override |
+ public boolean isSatisfied() { |
+ return !getActivity().isSplashScreenVisibleForTest(); |
+ } |
+ })); |
+ } |
+ |
private void setActivityWebappInfoFromBitmap(Bitmap image) { |
WebappInfo mockInfo = WebappInfo.create(WEBAPP_ID, "about:blank", |
ShortcutHelper.encodeBitmapAsString(image), null, null, |