From ec51a9823ff3d8c7966a7b64abf77d27ca8cc179 Mon Sep 17 00:00:00 2001
From: David Bienvenu <davidbienvenu@chromium.org>
Date: Fri, 11 Jun 2021 19:52:41 +0000
Subject: [PATCH] unit_tests: fix mock warnings in AutoFillPopup tests

Use NiceMock to silence warnings about uninteresting mock function calls.
Also fix some DISALLOW_COPY_AND_ASSIGNS

Bug: 1010217
Change-Id: I622f27120e0e111f3daa1573b17ceded4ca57910
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2955891
Reviewed-by: Evan Stade <estade@chromium.org>
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#891765}
---
 .../autofill_popup_controller_unittest.cc     | 51 +++++++++----------
 ...tofill_popup_view_native_views_unittest.cc | 10 ++--
 .../core/browser/test_autofill_client.h       |  6 ++-
 3 files changed, 34 insertions(+), 33 deletions(-)

diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
index 8c71662a0a06a..ab21e2d39b1c5 100644
--- a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
@@ -6,7 +6,6 @@
 
 #include <memory>
 
-#include "base/macros.h"
 #include "base/memory/weak_ptr.h"
 #include "base/strings/utf_string_conversions.h"
 #include "build/build_config.h"
@@ -61,6 +60,8 @@ const BrowserAutofillManager::AutofillDownloadManagerState kDownloadState =
 class MockAutofillClient : public autofill::TestAutofillClient {
  public:
   MockAutofillClient() : prefs_(autofill::test::PrefServiceForTesting()) {}
+  MockAutofillClient(MockAutofillClient&) = delete;
+  MockAutofillClient& operator=(MockAutofillClient&) = delete;
   ~MockAutofillClient() override = default;
 
   PrefService* GetPrefs() override {
@@ -70,8 +71,6 @@ class MockAutofillClient : public autofill::TestAutofillClient {
 
  private:
   std::unique_ptr<PrefService> prefs_;
-
-  DISALLOW_COPY_AND_ASSIGN(MockAutofillClient);
 };
 
 class MockAutofillDriver : public ContentAutofillDriver {
@@ -84,11 +83,11 @@ class MockAutofillDriver : public ContentAutofillDriver {
             kDownloadState,
             AutofillManager::AutofillManagerFactoryCallback()) {}
 
+  MockAutofillDriver(MockAutofillDriver&) = delete;
+  MockAutofillDriver& operator=(MockAutofillDriver&) = delete;
+
   ~MockAutofillDriver() override = default;
   MOCK_CONST_METHOD0(GetAxTreeId, ui::AXTreeID());
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(MockAutofillDriver);
 };
 
 class MockBrowserAutofillManager : public BrowserAutofillManager {
@@ -98,10 +97,9 @@ class MockBrowserAutofillManager : public BrowserAutofillManager {
                                client,
                                client->GetPersonalDataManager(),
                                client->GetAutocompleteHistoryManager()) {}
+  MockBrowserAutofillManager(MockBrowserAutofillManager&) = delete;
+  MockBrowserAutofillManager& operator=(MockBrowserAutofillManager&) = delete;
   ~MockBrowserAutofillManager() override = default;
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(MockBrowserAutofillManager);
 };
 
 class MockAutofillExternalDelegate : public AutofillExternalDelegate {
@@ -127,6 +125,8 @@ class MockAutofillExternalDelegate : public AutofillExternalDelegate {
 class MockAutofillPopupView : public AutofillPopupView {
  public:
   MockAutofillPopupView() = default;
+  MockAutofillPopupView(MockAutofillPopupView&) = delete;
+  MockAutofillPopupView& operator=(MockAutofillPopupView&) = delete;
   ~MockAutofillPopupView() override = default;
 
   MOCK_METHOD0(Show, void());
@@ -136,9 +136,6 @@ class MockAutofillPopupView : public AutofillPopupView {
                     absl::optional<int> current_row_selection));
   MOCK_METHOD0(OnSuggestionsChanged, void());
   MOCK_METHOD0(GetAxUniqueId, absl::optional<int32_t>());
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(MockAutofillPopupView);
 };
 
 class TestAutofillPopupController : public AutofillPopupControllerImpl {
@@ -182,6 +179,8 @@ class TestAutofillPopupController : public AutofillPopupControllerImpl {
 class MockAxTreeManager : public ui::AXTreeManager {
  public:
   MockAxTreeManager() = default;
+  MockAxTreeManager(MockAxTreeManager&) = delete;
+  MockAxTreeManager& operator=(MockAxTreeManager&) = delete;
   ~MockAxTreeManager() = default;
 
   MOCK_CONST_METHOD2(GetNodeFromTree,
@@ -196,33 +195,28 @@ class MockAxTreeManager : public ui::AXTreeManager {
   MOCK_CONST_METHOD0(GetParentTreeID, ui::AXTreeID());
   MOCK_CONST_METHOD0(GetRootAsAXNode, ui::AXNode*());
   MOCK_CONST_METHOD0(GetParentNodeFromParentTreeAsAXNode, ui::AXNode*());
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(MockAxTreeManager);
 };
 
 class MockAxPlatformNodeDelegate : public ui::AXPlatformNodeDelegateBase {
  public:
   MockAxPlatformNodeDelegate() = default;
+  MockAxPlatformNodeDelegate(MockAxPlatformNodeDelegate&) = delete;
+  MockAxPlatformNodeDelegate& operator=(MockAxPlatformNodeDelegate&) = delete;
   ~MockAxPlatformNodeDelegate() override = default;
 
   MOCK_METHOD1(GetFromNodeID, ui::AXPlatformNode*(int32_t id));
   MOCK_METHOD2(GetFromTreeIDAndNodeID,
                ui::AXPlatformNode*(const ui::AXTreeID& tree_id, int32_t id));
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(MockAxPlatformNodeDelegate);
 };
 
 class MockAxPlatformNode : public ui::AXPlatformNodeBase {
  public:
   MockAxPlatformNode() = default;
+  MockAxPlatformNode(MockAxPlatformNode&) = delete;
+  MockAxPlatformNode& operator=(MockAxPlatformNode&) = delete;
   ~MockAxPlatformNode() override = default;
 
   MOCK_CONST_METHOD0(GetDelegate, ui::AXPlatformNodeDelegate*());
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(MockAxPlatformNode);
 };
 
 static constexpr absl::optional<int> kNoSelection;
@@ -274,7 +268,9 @@ class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness {
     return autofill_popup_controller_;
   }
 
-  MockAutofillExternalDelegate* delegate() { return external_delegate_.get(); }
+  NiceMock<MockAutofillExternalDelegate>* delegate() {
+    return external_delegate_.get();
+  }
 
   MockAutofillPopupView* autofill_popup_view() {
     return autofill_popup_view_.get();
@@ -293,6 +289,10 @@ class AutofillPopupControllerAccessibilityUnitTest
  public:
   AutofillPopupControllerAccessibilityUnitTest()
       : accessibility_mode_setter_(ui::AXMode::kScreenReader) {}
+  AutofillPopupControllerAccessibilityUnitTest(
+      AutofillPopupControllerAccessibilityUnitTest&) = delete;
+  AutofillPopupControllerAccessibilityUnitTest& operator=(
+      AutofillPopupControllerAccessibilityUnitTest&) = delete;
   ~AutofillPopupControllerAccessibilityUnitTest() override = default;
 
   std::unique_ptr<NiceMock<MockAutofillExternalDelegate>>
@@ -309,9 +309,6 @@ class AutofillPopupControllerAccessibilityUnitTest
   std::unique_ptr<MockBrowserAutofillManager> autofill_manager_;
   std::unique_ptr<NiceMock<MockAutofillDriver>> autofill_driver_;
   content::testing::ScopedContentAXModeSetter accessibility_mode_setter_;
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(AutofillPopupControllerAccessibilityUnitTest);
 };
 #endif
 
@@ -596,8 +593,8 @@ TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) {
       ContentAutofillDriverFactory::FromWebContents(web_contents());
   ContentAutofillDriver* driver =
       factory->DriverForFrame(web_contents()->GetMainFrame());
-  MockAutofillExternalDelegate delegate(driver->browser_autofill_manager(),
-                                        driver);
+  NiceMock<MockAutofillExternalDelegate> delegate(
+      driver->browser_autofill_manager(), driver);
 
   WeakPtr<AutofillPopupControllerImpl> controller =
       AutofillPopupControllerImpl::GetOrCreate(
diff --git a/chrome/browser/ui/views/autofill/autofill_popup_view_native_views_unittest.cc b/chrome/browser/ui/views/autofill/autofill_popup_view_native_views_unittest.cc
index 322041601f79d..2237e64e33c69 100644
--- a/chrome/browser/ui/views/autofill/autofill_popup_view_native_views_unittest.cc
+++ b/chrome/browser/ui/views/autofill/autofill_popup_view_native_views_unittest.cc
@@ -22,6 +22,8 @@
 #include "ui/views/test/ax_event_counter.h"
 #include "ui/views/widget/widget_utils.h"
 
+using testing::NiceMock;
+
 namespace {
 
 struct TypeClicks {
@@ -52,6 +54,9 @@ const struct TypeClicks kClickTestCase[] = {
 class AutofillPopupViewNativeViewsTest : public ChromeViewsTestBase {
  public:
   AutofillPopupViewNativeViewsTest() = default;
+  AutofillPopupViewNativeViewsTest(AutofillPopupViewNativeViewsTest&) = delete;
+  AutofillPopupViewNativeViewsTest& operator=(
+      AutofillPopupViewNativeViewsTest&) = delete;
   ~AutofillPopupViewNativeViewsTest() override = default;
 
   void SetUp() override {
@@ -82,12 +87,9 @@ class AutofillPopupViewNativeViewsTest : public ChromeViewsTestBase {
 
  protected:
   std::unique_ptr<autofill::AutofillPopupViewNativeViews> view_;
-  autofill::MockAutofillPopupController autofill_popup_controller_;
+  NiceMock<autofill::MockAutofillPopupController> autofill_popup_controller_;
   std::unique_ptr<views::Widget> widget_;
   std::unique_ptr<ui::test::EventGenerator> generator_;
-
- private:
-  DISALLOW_COPY_AND_ASSIGN(AutofillPopupViewNativeViewsTest);
 };
 
 class AutofillPopupViewNativeViewsForEveryTypeTest
diff --git a/components/autofill/core/browser/test_autofill_client.h b/components/autofill/core/browser/test_autofill_client.h
index 9ae2bafe421ce..9088ea198aafb 100644
--- a/components/autofill/core/browser/test_autofill_client.h
+++ b/components/autofill/core/browser/test_autofill_client.h
@@ -225,7 +225,8 @@ class TestAutofillClient : public AutofillClient {
     return save_credit_card_options_.value();
   }
 
-  MockAutocompleteHistoryManager* GetMockAutocompleteHistoryManager() {
+  ::testing::NiceMock<MockAutocompleteHistoryManager>*
+  GetMockAutocompleteHistoryManager() {
     return &mock_autocomplete_history_manager_;
   }
 
@@ -253,7 +254,8 @@ class TestAutofillClient : public AutofillClient {
   syncer::SyncService* test_sync_service_ = nullptr;
   TestAddressNormalizer test_address_normalizer_;
   TestPersonalDataManager test_personal_data_manager_;
-  MockAutocompleteHistoryManager mock_autocomplete_history_manager_;
+  ::testing::NiceMock<MockAutocompleteHistoryManager>
+      mock_autocomplete_history_manager_;
   std::unique_ptr<AutofillOfferManager> autofill_offer_manager_;
 
   // NULL by default.