Commit 693be9e7 authored by Michael Bai's avatar Michael Bai Committed by Chromium LUCI CQ

Fix AwAutofill test failure on x86 emulator

It seems the x86 emulator is a little bit slow or it connects to
cloud, the query response come back during the test.

This patch disable the download server in tests.

Bug: 1161326

Change-Id: I19171957ca266f8827eb14a55e017b901ea60201
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2633203Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Reviewed-by: default avatarShimi Zhang <ctzsm@chromium.org>
Commit-Queue: Michael Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846208}
parent 11af90c0
......@@ -320,7 +320,9 @@ void AwContents::InitAutofillIfNecessary(bool autocomplete_enabled) {
web_contents, AwAutofillClient::FromWebContents(web_contents),
base::android::GetDefaultLocaleString(),
base::FeatureList::IsEnabled(
autofill::features::kAndroidAutofillQueryServerFieldTypes)
autofill::features::kAndroidAutofillQueryServerFieldTypes) &&
(!autofill::AutofillProvider::
is_download_manager_disabled_for_testing())
? autofill::AutofillHandler::ENABLE_AUTOFILL_DOWNLOAD_MANAGER
: autofill::AutofillHandler::DISABLE_AUTOFILL_DOWNLOAD_MANAGER,
autofill_provider_.get());
......
......@@ -886,6 +886,8 @@ public class AwAutofillTest {
mWebServer = TestWebServer.start();
mUMATestHelper = new AwAutofillSessionUMATestHelper(this, mWebServer);
mContentsClient = new AwAutofillTestClient();
TestThreadUtils.runOnUiThreadBlocking(
() -> AutofillProviderTestHelper.disableDownloadServerForTesting());
mTestContainerView = mRule.createAwTestContainerViewOnMainSync(
mContentsClient, false, new TestDependencyFactory() {
@Override
......
......@@ -8,6 +8,8 @@
#include "base/base64.h"
#include "base/strings/string16.h"
#include "components/autofill/content/browser/content_autofill_driver.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/autofill/core/browser/autofill_provider.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/field_types.h"
#include "content/public/browser/web_contents.h"
......@@ -15,22 +17,38 @@
namespace autofill {
namespace {
AutofillHandler* GetAutofillHandler(content::WebContents* web_contents,
content::RenderFrameHost* rfh) {
// Avoid using ContentAutofillDriver::GetForRenderFrameHost(), it will create
// a new ContentAutofillDriver.
if (ContentAutofillDriverFactory* factory =
ContentAutofillDriverFactory::FromWebContents(web_contents)) {
if (ContentAutofillDriver* driver =
static_cast<ContentAutofillDriver*>(factory->DriverForKey(rfh))) {
return driver->autofill_handler();
}
}
return nullptr;
}
AutofillHandler* ToMainFrameAutofillHandler(
const base::android::JavaParamRef<jobject>& jweb_contents) {
content::WebContents* web_contents =
content::WebContents::FromJavaWebContents(jweb_contents);
CHECK(web_contents);
ContentAutofillDriver* driver = ContentAutofillDriver::GetForRenderFrameHost(
web_contents->GetMainFrame());
CHECK(driver);
AutofillHandler* autofill_handler = driver->autofill_handler();
AutofillHandler* autofill_handler =
GetAutofillHandler(web_contents, web_contents->GetMainFrame());
CHECK(autofill_handler);
return autofill_handler;
}
} // namespace
static void JNI_AutofillProviderTestHelper_DisableDownloadServerForTesting(
JNIEnv* env_md_ctx_st) {
AutofillProvider::set_is_download_manager_disabled_for_testing();
}
static jboolean
JNI_AutofillProviderTestHelper_SimulateMainFrameAutofillServerResponseForTesting(
JNIEnv* env,
......
......@@ -19,6 +19,14 @@ import org.chromium.content_public.browser.WebContents;
@TargetApi(Build.VERSION_CODES.O)
@JNINamespace("autofill")
public class AutofillProviderTestHelper {
/**
* Disable the download server for testing to avoid the server response affect the integration
* tests. Must be called before WebContents is created.
*/
public static void disableDownloadServerForTesting() {
AutofillProviderTestHelperJni.get().disableDownloadServerForTesting();
}
/**
* Simulate the primary server type only.
*/
......@@ -46,6 +54,7 @@ public class AutofillProviderTestHelper {
@NativeMethods
interface Natives {
void disableDownloadServerForTesting();
boolean simulateMainFrameAutofillServerResponseForTesting(
WebContents webContents, String[] fieldIds, int[] fieldTypes);
boolean simulateMainFramePredictionsAutofillServerResponseForTesting(
......
......@@ -7,6 +7,18 @@
#include "components/autofill/core/browser/autofill_handler_proxy.h"
namespace autofill {
namespace {
bool g_is_download_manager_disabled_for_testing = false;
}
// static
bool AutofillProvider::is_download_manager_disabled_for_testing() {
return g_is_download_manager_disabled_for_testing;
}
void AutofillProvider::set_is_download_manager_disabled_for_testing() {
g_is_download_manager_disabled_for_testing = true;
}
AutofillProvider::AutofillProvider() {}
......
......@@ -25,6 +25,9 @@ class AutofillProvider {
AutofillProvider();
virtual ~AutofillProvider();
static bool is_download_manager_disabled_for_testing();
static void set_is_download_manager_disabled_for_testing();
virtual void OnQueryFormFieldAutofill(AutofillHandlerProxy* handler,
int32_t id,
const FormData& form,
......
# crbug.com/1161326
-org.chromium.android_webview.test.AwAutofillTest.*
......@@ -1347,7 +1347,9 @@ void TabImpl::InitializeAutofill() {
autofill::AutofillHandler::DISABLE_AUTOFILL_DOWNLOAD_MANAGER;
#if defined(OS_ANDROID)
if (base::FeatureList::IsEnabled(
autofill::features::kAndroidAutofillQueryServerFieldTypes)) {
autofill::features::kAndroidAutofillQueryServerFieldTypes) &&
(!autofill::AutofillProvider::
is_download_manager_disabled_for_testing())) {
enable_autofill_download_manager =
autofill::AutofillHandler::ENABLE_AUTOFILL_DOWNLOAD_MANAGER;
}
......
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