Commit 58e83b12 authored by Carlos IL's avatar Carlos IL Committed by Commit Bot

Fix flakiness in webview safe browsing tests with CI

Safe browsing webview tests were flaky with committed interstitials
enabled caused by a lack of a reliable way to wait for an interstitial
to show. This CL exposes IsShowingInterstitial from security_
interstitial_tab_helper.h and changes the tests to poll it before
waiting for the visual state callback.

Bug: 1046832
Change-Id: If82f7fbbd9896e4cc3611e48fe945c8581cd847a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2027902
Commit-Queue: Carlos IL <carlosil@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#736528}
parent 7a21d87d
...@@ -970,6 +970,16 @@ bool AwContents::IsVisible(JNIEnv* env, const JavaParamRef<jobject>& obj) { ...@@ -970,6 +970,16 @@ bool AwContents::IsVisible(JNIEnv* env, const JavaParamRef<jobject>& obj) {
return browser_view_renderer_.IsClientVisible(); return browser_view_renderer_.IsClientVisible();
} }
bool AwContents::IsDisplayingInterstitialForTesting(
JNIEnv* env,
const JavaParamRef<jobject>& obj) {
security_interstitials::SecurityInterstitialTabHelper*
security_interstitial_tab_helper = security_interstitials::
SecurityInterstitialTabHelper::FromWebContents(web_contents_.get());
return security_interstitial_tab_helper &&
security_interstitial_tab_helper->IsDisplayingInterstitial();
}
base::android::ScopedJavaLocalRef<jbyteArray> AwContents::GetOpaqueState( base::android::ScopedJavaLocalRef<jbyteArray> AwContents::GetOpaqueState(
JNIEnv* env, JNIEnv* env,
const JavaParamRef<jobject>& obj) { const JavaParamRef<jobject>& obj) {
......
...@@ -157,6 +157,9 @@ class AwContents : public FindHelper::Listener, ...@@ -157,6 +157,9 @@ class AwContents : public FindHelper::Listener,
void OnDetachedFromWindow(JNIEnv* env, void OnDetachedFromWindow(JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
bool IsVisible(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj); bool IsVisible(JNIEnv* env, const base::android::JavaParamRef<jobject>& obj);
bool IsDisplayingInterstitialForTesting(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj);
base::android::ScopedJavaLocalRef<jbyteArray> GetOpaqueState( base::android::ScopedJavaLocalRef<jbyteArray> GetOpaqueState(
JNIEnv* env, JNIEnv* env,
const base::android::JavaParamRef<jobject>& obj); const base::android::JavaParamRef<jobject>& obj);
......
...@@ -2930,6 +2930,16 @@ public class AwContents implements SmartClipProvider { ...@@ -2930,6 +2930,16 @@ public class AwContents implements SmartClipProvider {
return AwContentsJni.get().isVisible(mNativeAwContents, AwContents.this); return AwContentsJni.get().isVisible(mNativeAwContents, AwContents.this);
} }
/**
* Returns true if the web contents has an associated interstitial.
* This method is only called by tests.
*/
@VisibleForTesting
public boolean isDisplayingInterstitialForTesting() {
return AwContentsJni.get().isDisplayingInterstitialForTesting(
mNativeAwContents, AwContents.this);
}
/** /**
* Key for opaque state in bundle. Note this is only public for tests. * Key for opaque state in bundle. Note this is only public for tests.
*/ */
...@@ -3983,6 +3993,7 @@ public class AwContents implements SmartClipProvider { ...@@ -3983,6 +3993,7 @@ public class AwContents implements SmartClipProvider {
void onAttachedToWindow(long nativeAwContents, AwContents caller, int w, int h); void onAttachedToWindow(long nativeAwContents, AwContents caller, int w, int h);
void onDetachedFromWindow(long nativeAwContents, AwContents caller); void onDetachedFromWindow(long nativeAwContents, AwContents caller);
boolean isVisible(long nativeAwContents, AwContents caller); boolean isVisible(long nativeAwContents, AwContents caller);
boolean isDisplayingInterstitialForTesting(long nativeAwContents, AwContents caller);
void setDipScale(long nativeAwContents, AwContents caller, float dipScale); void setDipScale(long nativeAwContents, AwContents caller, float dipScale);
void onInputEvent(long nativeAwContents, AwContents caller); void onInputEvent(long nativeAwContents, AwContents caller);
// Returns null if save state fails. // Returns null if save state fails.
......
...@@ -440,6 +440,20 @@ public class SafeBrowsingTest { ...@@ -440,6 +440,20 @@ public class SafeBrowsingTest {
final String responseUrl = mTestServer.getURL(path); final String responseUrl = mTestServer.getURL(path);
mActivityTestRule.loadUrlAsync(mAwContents, responseUrl); mActivityTestRule.loadUrlAsync(mAwContents, responseUrl);
if (AwFeatureList.isEnabled(AwFeatures.SAFE_BROWSING_COMMITTED_INTERSTITIALS)) { if (AwFeatureList.isEnabled(AwFeatures.SAFE_BROWSING_COMMITTED_INTERSTITIALS)) {
// Subresource triggered interstitials will trigger after the page containing the
// subresource has loaded (and displayed), so we first wait for the interstitial to be
// attached to the web contents, then for a visual state callback to allow the
// interstitial to render.
CriteriaHelper.pollUiThread(new Criteria() {
@Override
public boolean isSatisfied() {
try {
return mAwContents.isDisplayingInterstitialForTesting();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
// Wait for the interstitial to actually render. // Wait for the interstitial to actually render.
mActivityTestRule.waitForVisualStateCallback(mAwContents); mActivityTestRule.waitForVisualStateCallback(mAwContents);
} else { } else {
......
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