Commit c95819c4 authored by Friedrich Horschig's avatar Friedrich Horschig Committed by Commit Bot

[Android] Re-enable and fix crashes in ManualFillingControllerTest

This CL reenables the ManualFillingControllerTest that was previously
disabled because the SetUp failed when initializing the initial
navigation for the RenderViewHostTestHarness.

This cannot happen anymore since the Test doesn't use any navigations
anymore but instead calls the controller interface directly. Therefore,
it also isn't a subclass of RenderViewHostTestHarness anymore but uses
TestProfile and TestWebContents directly.

Bug: 1004585
Change-Id: I6c48c651447645453fc080a35efa90c7d7b60c3e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807224
Commit-Queue: Friedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#697204}
parent b4fc7e93
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/mock_callback.h" #include "base/test/mock_callback.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
...@@ -22,16 +23,15 @@ ...@@ -22,16 +23,15 @@
#include "chrome/browser/autofill/mock_password_accessory_controller.h" #include "chrome/browser/autofill/mock_password_accessory_controller.h"
#include "chrome/browser/password_manager/password_accessory_controller.h" #include "chrome/browser/password_manager/password_accessory_controller.h"
#include "chrome/browser/password_manager/touch_to_fill_controller.h" #include "chrome/browser/password_manager/touch_to_fill_controller.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/testing_profile.h"
#include "components/autofill/core/common/autofill_features.h" #include "components/autofill/core/common/autofill_features.h"
#include "components/favicon/core/test/mock_favicon_service.h" #include "components/favicon/core/test/mock_favicon_service.h"
#include "components/password_manager/core/common/password_manager_features.h" #include "components/password_manager/core/common/password_manager_features.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_web_contents_factory.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
// TODO(crbug/1004585) Crashes on Android
#if !defined(OS_ANDROID)
namespace { namespace {
using autofill::AccessoryAction; using autofill::AccessoryAction;
using autofill::AccessorySheetData; using autofill::AccessorySheetData;
...@@ -62,20 +62,16 @@ AccessorySheetData populate_sheet(AccessoryTabType type) { ...@@ -62,20 +62,16 @@ AccessorySheetData populate_sheet(AccessoryTabType type) {
} // namespace } // namespace
class ManualFillingControllerTest : public ChromeRenderViewHostTestHarness { class ManualFillingControllerTest : public testing::Test {
public: public:
ManualFillingControllerTest() = default; ManualFillingControllerTest() = default;
void SetUp() override { void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp();
NavigateAndCommit(GURL(kExampleSite));
touch_to_fill_controller_.emplace(web_contents());
ManualFillingControllerImpl::CreateForWebContentsForTesting( ManualFillingControllerImpl::CreateForWebContentsForTesting(
web_contents(), favicon_service(), mock_pwd_controller_.AsWeakPtr(), web_contents(), favicon_service(), mock_pwd_controller_.AsWeakPtr(),
mock_address_controller_.AsWeakPtr(), mock_cc_controller_.AsWeakPtr(), mock_address_controller_.AsWeakPtr(), mock_cc_controller_.AsWeakPtr(),
touch_to_fill_controller_->AsWeakPtr(), touch_to_fill_controller_.AsWeakPtr(),
std::make_unique<NiceMock<MockManualFillingView>>()); std::make_unique<NiceMock<MockManualFillingView>>());
NavigateAndCommit(GURL(kExampleSite));
} }
void FocusFieldAndClearExpectations(FocusedFieldType fieldType) { void FocusFieldAndClearExpectations(FocusedFieldType fieldType) {
...@@ -100,17 +96,24 @@ class ManualFillingControllerTest : public ChromeRenderViewHostTestHarness { ...@@ -100,17 +96,24 @@ class ManualFillingControllerTest : public ChromeRenderViewHostTestHarness {
return mock_favicon_service_.get(); return mock_favicon_service_.get();
} }
content::WebContents* web_contents() { return web_contents_; }
MockManualFillingView* view() { MockManualFillingView* view() {
return static_cast<MockManualFillingView*>(controller()->view()); return static_cast<MockManualFillingView*>(controller()->view());
} }
protected: protected:
content::BrowserTaskEnvironment task_environment_;
TestingProfile profile_;
content::TestWebContentsFactory web_contents_factory_;
content::WebContents* web_contents_ =
web_contents_factory_.CreateWebContents(&profile_);
NiceMock<MockPasswordAccessoryController> mock_pwd_controller_; NiceMock<MockPasswordAccessoryController> mock_pwd_controller_;
NiceMock<MockAddressAccessoryController> mock_address_controller_; NiceMock<MockAddressAccessoryController> mock_address_controller_;
NiceMock<MockCreditCardAccessoryController> mock_cc_controller_; NiceMock<MockCreditCardAccessoryController> mock_cc_controller_;
// Constructing a TouchToFillController needs a valid WebContents. Use a TouchToFillController touch_to_fill_controller_{web_contents_};
// base::Optional to be able to delay the construction.
base::Optional<TouchToFillController> touch_to_fill_controller_;
std::unique_ptr<StrictMock<favicon::MockFaviconService>> std::unique_ptr<StrictMock<favicon::MockFaviconService>>
mock_favicon_service_ = mock_favicon_service_ =
std::make_unique<StrictMock<favicon::MockFaviconService>>(); std::make_unique<StrictMock<favicon::MockFaviconService>>();
...@@ -349,5 +352,3 @@ TEST_F(ManualFillingControllerTest, RequestsFaviconForOrigin) { ...@@ -349,5 +352,3 @@ TEST_F(ManualFillingControllerTest, RequestsFaviconForOrigin) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
#endif // !defined(OS_ANDROID)
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