Commit 14e69de1 authored by Yue Zhang's avatar Yue Zhang Committed by Commit Bot

Fix testSetIphDialogVisibility on O devices

Bug: 983170
Change-Id: I830632b436bfd4f9b159b3a183f524e4d432ad79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1900362Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Commit-Queue: Yue Zhang <yuezhanggg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713046}
parent d822cd29
...@@ -14,14 +14,13 @@ import static org.junit.Assert.assertNotEquals; ...@@ -14,14 +14,13 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.chromium.base.test.util.CallbackHelper.WAIT_TIMEOUT_SECONDS; import static org.chromium.base.test.util.CallbackHelper.WAIT_TIMEOUT_SECONDS;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.areAnimatorsEnabled;
import static org.chromium.chrome.browser.util.UrlConstants.NTP_URL; import static org.chromium.chrome.browser.util.UrlConstants.NTP_URL;
import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL; import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_MAX_TIME_TO_POLL;
import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_POLLING_INTERVAL; import static org.chromium.content_public.browser.test.util.CriteriaHelper.DEFAULT_POLLING_INTERVAL;
import android.animation.ValueAnimator;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Build; import android.os.Build;
import android.provider.Settings;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.NoMatchingViewException; import android.support.test.espresso.NoMatchingViewException;
...@@ -40,7 +39,6 @@ import org.junit.rules.TestRule; ...@@ -40,7 +39,6 @@ import org.junit.rules.TestRule;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.GarbageCollectionTestUtils; import org.chromium.base.GarbageCollectionTestUtils;
import org.chromium.base.metrics.RecordHistogram; import org.chromium.base.metrics.RecordHistogram;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
...@@ -815,19 +813,4 @@ public class StartSurfaceLayoutTest { ...@@ -815,19 +813,4 @@ public class StartSurfaceLayoutTest {
} }
return true; return true;
} }
/**
* Should be the same as {@link ValueAnimator#areAnimatorsEnabled}, which requires API level 26.
* TODO(crbug.com/982018): put this interface in a place to share with
* TabListContainerViewBinderTest.areAnimatorsEnabled.
*/
private static boolean areAnimatorsEnabled() {
// We default to assuming that animations are enabled in case ANIMATOR_DURATION_SCALE is not
// defined.
final float defaultScale = 1f;
float durationScale =
Settings.Global.getFloat(ContextUtils.getApplicationContext().getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, defaultScale);
return !(durationScale == 0.0);
}
} }
...@@ -4,10 +4,11 @@ ...@@ -4,10 +4,11 @@
package org.chromium.chrome.browser.tasks.tab_management; package org.chromium.chrome.browser.tasks.tab_management;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.areAnimatorsEnabled;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Rect; import android.graphics.Rect;
import android.provider.Settings;
import android.support.test.annotation.UiThreadTest; import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
...@@ -23,7 +24,6 @@ import org.junit.Assert; ...@@ -23,7 +24,6 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.tab.TabFeatureUtilities; import org.chromium.chrome.browser.tab.TabFeatureUtilities;
import org.chromium.chrome.tab_ui.R; import org.chromium.chrome.tab_ui.R;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -421,18 +421,4 @@ public class TabGridDialogParentTest extends DummyUiActivityTestCase { ...@@ -421,18 +421,4 @@ public class TabGridDialogParentTest extends DummyUiActivityTestCase {
mTabGridDialogParent.destroy(); mTabGridDialogParent.destroy();
super.tearDownTest(); super.tearDownTest();
} }
}
/**
* TODO(crbug.com/982018): put this interface in a place to share with
* TabListContainerViewBinderTest.areAnimatorsEnabled.
*/
private static boolean areAnimatorsEnabled() {
// We default to assuming that animations are enabled in case ANIMATOR_DURATION_SCALE is not
// defined.
final float defaultScale = 1f;
float durationScale =
Settings.Global.getFloat(ContextUtils.getApplicationContext().getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, defaultScale);
return !(durationScale == 0.0);
}
}
\ No newline at end of file
...@@ -14,6 +14,7 @@ import static org.junit.Assert.assertNotNull; ...@@ -14,6 +14,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.areAnimatorsEnabled;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.isKitKatAndBelow; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.isKitKatAndBelow;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
...@@ -150,12 +151,16 @@ public class TabGridIphItemViewBinderTest extends DummyUiActivityTestCase { ...@@ -150,12 +151,16 @@ public class TabGridIphItemViewBinderTest extends DummyUiActivityTestCase {
mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, true); mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, true);
assertTrue(mIphWindow.isShowing()); assertTrue(mIphWindow.isShowing());
assertTrue(mIphAnimation.isRunning()); if (areAnimatorsEnabled()) {
assertTrue(mIphAnimation.isRunning());
}
mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, false); mModel.set(TabGridIphItemProperties.IS_IPH_DIALOG_VISIBLE, false);
assertFalse(mIphWindow.isShowing()); assertFalse(mIphWindow.isShowing());
assertFalse(mIphAnimation.isRunning()); if (areAnimatorsEnabled()) {
assertFalse(mIphAnimation.isRunning());
}
} }
@Test @Test
......
...@@ -4,12 +4,13 @@ ...@@ -4,12 +4,13 @@
package org.chromium.chrome.browser.tasks.tab_management; package org.chromium.chrome.browser.tasks.tab_management;
import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.areAnimatorsEnabled;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.os.Build; import android.os.Build;
import android.os.SystemClock; import android.os.SystemClock;
import android.provider.Settings;
import android.support.test.annotation.UiThreadTest; import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
...@@ -29,7 +30,6 @@ import org.junit.Assert; ...@@ -29,7 +30,6 @@ import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.toolbar.ToolbarColors; import org.chromium.chrome.browser.toolbar.ToolbarColors;
import org.chromium.chrome.browser.widget.ScrimView; import org.chromium.chrome.browser.widget.ScrimView;
import org.chromium.chrome.tab_ui.R; import org.chromium.chrome.tab_ui.R;
...@@ -481,14 +481,4 @@ public class TabGridPanelViewBinderTest extends DummyUiActivityTestCase { ...@@ -481,14 +481,4 @@ public class TabGridPanelViewBinderTest extends DummyUiActivityTestCase {
mTabGridDialogParent.destroy(); mTabGridDialogParent.destroy();
super.tearDownTest(); super.tearDownTest();
} }
private static boolean areAnimatorsEnabled() {
// We default to assuming that animations are enabled in case ANIMATOR_DURATION_SCALE is not
// defined.
final float defaultScale = 1f;
float durationScale =
Settings.Global.getFloat(ContextUtils.getApplicationContext().getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, defaultScale);
return !(durationScale == 0.0);
}
} }
...@@ -8,9 +8,9 @@ import static org.hamcrest.CoreMatchers.equalTo; ...@@ -8,9 +8,9 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import android.animation.ValueAnimator; import static org.chromium.chrome.browser.tasks.tab_management.TabUiTestHelper.areAnimatorsEnabled;
import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.ColorDrawable;
import android.provider.Settings;
import android.support.test.annotation.UiThreadTest; import android.support.test.annotation.UiThreadTest;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.view.View; import android.view.View;
...@@ -24,7 +24,6 @@ import org.junit.runner.RunWith; ...@@ -24,7 +24,6 @@ import org.junit.runner.RunWith;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.CommandLine; import org.chromium.base.CommandLine;
import org.chromium.base.ContextUtils;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.DisabledTest; import org.chromium.base.test.util.DisabledTest;
import org.chromium.chrome.browser.ChromeFeatureList; import org.chromium.chrome.browser.ChromeFeatureList;
...@@ -267,17 +266,4 @@ public class TabListContainerViewBinderTest extends DummyUiActivityTestCase { ...@@ -267,17 +266,4 @@ public class TabListContainerViewBinderTest extends DummyUiActivityTestCase {
mMCP.destroy(); mMCP.destroy();
super.tearDownTest(); super.tearDownTest();
} }
/**
* Should be the same as {@link ValueAnimator#areAnimatorsEnabled}, which requires API level 26.
*/
private static boolean areAnimatorsEnabled() {
// We default to assuming that animations are enabled in case ANIMATOR_DURATION_SCALE is not
// defined.
final float defaultScale = 1f;
float durationScale =
Settings.Global.getFloat(ContextUtils.getApplicationContext().getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, defaultScale);
return !(durationScale == 0.0);
}
} }
...@@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue; ...@@ -17,6 +17,7 @@ import static org.junit.Assert.assertTrue;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.provider.Settings;
import android.support.test.InstrumentationRegistry; import android.support.test.InstrumentationRegistry;
import android.support.test.espresso.NoMatchingViewException; import android.support.test.espresso.NoMatchingViewException;
import android.support.test.espresso.ViewAssertion; import android.support.test.espresso.ViewAssertion;
...@@ -24,6 +25,7 @@ import android.support.test.espresso.contrib.RecyclerViewActions; ...@@ -24,6 +25,7 @@ import android.support.test.espresso.contrib.RecyclerViewActions;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.View; import android.view.View;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.browser.ChromeTabbedActivity; import org.chromium.chrome.browser.ChromeTabbedActivity;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tasks.tab_groups.TabGroupModelFilter; import org.chromium.chrome.browser.tasks.tab_groups.TabGroupModelFilter;
...@@ -167,6 +169,20 @@ public class TabUiTestHelper { ...@@ -167,6 +169,20 @@ public class TabUiTestHelper {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP; return Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;
} }
/**
* @return whether animators are enabled on device by checking whether the animation duration
* scale is set to 0.0.
*/
public static boolean areAnimatorsEnabled() {
// We default to assuming that animations are enabled in case ANIMATOR_DURATION_SCALE is not
// defined.
final float defaultScale = 1f;
float durationScale =
Settings.Global.getFloat(ContextUtils.getApplicationContext().getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, defaultScale);
return !(durationScale == 0.0);
}
/** /**
* Implementation of {@link ViewAssertion} to verify the {@link RecyclerView} has correct number * Implementation of {@link ViewAssertion} to verify the {@link RecyclerView} has correct number
* of children, and children are showing correctly. * of children, and children are showing correctly.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment