Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Unified Diff: chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc

Issue 2727233003: Uses child views in Autofill Popup so we can trigger (Closed)
Patch Set: Combines 2 calls to InvalidateRow to 1 OnSelectedRowChanged call. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
diff --git a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
index a6ef0406f1470abf07411f11d52bf338f4b68616..d9685b07f3359894c01408cc0fbdd3d45ee3b9a7 100644
--- a/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
+++ b/chrome/browser/ui/autofill/autofill_popup_controller_unittest.cc
@@ -69,6 +69,21 @@ class MockAutofillClient : public autofill::TestAutofillClient {
DISALLOW_COPY_AND_ASSIGN(MockAutofillClient);
};
+class MockAutofillPopupView : public AutofillPopupView {
+ public:
+ MockAutofillPopupView() {}
+
+ MOCK_METHOD0(Show, void());
+ MOCK_METHOD0(Hide, void());
+ MOCK_METHOD2(OnSelectedRowChanged,
+ void(size_t previous_row_selection,
+ size_t current_row_selection));
+ MOCK_METHOD0(OnSuggestionsChanged, void());
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockAutofillPopupView);
+};
+
class TestAutofillPopupController : public AutofillPopupControllerImpl {
public:
TestAutofillPopupController(
@@ -95,16 +110,12 @@ class TestAutofillPopupController : public AutofillPopupControllerImpl {
using AutofillPopupControllerImpl::element_bounds;
using AutofillPopupControllerImpl::SetValues;
using AutofillPopupControllerImpl::GetWeakPtr;
- MOCK_METHOD1(InvalidateRow, void(size_t));
- MOCK_METHOD0(UpdateBoundsAndRedrawPopup, void());
+ MOCK_METHOD0(OnSuggestionsChanged, void());
MOCK_METHOD0(Hide, void());
void DoHide() {
AutofillPopupControllerImpl::Hide();
}
-
- private:
- void ShowView() override {}
};
} // namespace
@@ -132,10 +143,10 @@ class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness {
new NiceMock<MockAutofillExternalDelegate>(
driver->autofill_manager(),
driver));
-
- autofill_popup_controller_ =
- new testing::NiceMock<TestAutofillPopupController>(
- external_delegate_->GetWeakPtr(), gfx::RectF());
+ autofill_popup_view_.reset(new NiceMock<MockAutofillPopupView>());
+ autofill_popup_controller_ = new NiceMock<TestAutofillPopupController>(
+ external_delegate_->GetWeakPtr(), gfx::RectF());
+ autofill_popup_controller_->SetViewForTesting(autofill_popup_view());
}
void TearDown() override {
@@ -156,10 +167,15 @@ class AutofillPopupControllerUnitTest : public ChromeRenderViewHostTestHarness {
return external_delegate_.get();
}
+ MockAutofillPopupView* autofill_popup_view() {
+ return autofill_popup_view_.get();
+ }
+
protected:
std::unique_ptr<MockAutofillClient> autofill_client_;
std::unique_ptr<NiceMock<MockAutofillExternalDelegate>> external_delegate_;
- testing::NiceMock<TestAutofillPopupController>* autofill_popup_controller_;
+ std::unique_ptr<NiceMock<MockAutofillPopupView>> autofill_popup_view_;
+ NiceMock<TestAutofillPopupController>* autofill_popup_controller_;
};
TEST_F(AutofillPopupControllerUnitTest, ChangeSelectedLine) {
@@ -196,16 +212,16 @@ TEST_F(AutofillPopupControllerUnitTest, RedrawSelectedLine) {
// Make sure that when a new line is selected, it is invalidated so it can
// be updated to show it is selected.
int selected_line = 0;
- EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line));
+ EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(-1, selected_line));
+
autofill_popup_controller_->SetSelectedLine(selected_line);
// Ensure that the row isn't invalidated if it didn't change.
- EXPECT_CALL(*autofill_popup_controller_,
- InvalidateRow(selected_line)).Times(0);
+ EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(_, _)).Times(0);
autofill_popup_controller_->SetSelectedLine(selected_line);
// Change back to no selection.
- EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(selected_line));
+ EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(selected_line, -1));
autofill_popup_controller_->SetSelectedLine(-1);
}
@@ -227,7 +243,7 @@ TEST_F(AutofillPopupControllerUnitTest, RemoveLine) {
// Remove the first entry. The popup should be redrawn since its size has
// changed.
- EXPECT_CALL(*autofill_popup_controller_, UpdateBoundsAndRedrawPopup());
+ EXPECT_CALL(*autofill_popup_controller_, OnSuggestionsChanged());
autofill_popup_controller_->SetSelectedLine(0);
EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine());
@@ -253,7 +269,7 @@ TEST_F(AutofillPopupControllerUnitTest, RemoveOnlyLine) {
// Remove the only line. There should be no row invalidation and the popup
// should then be hidden since there are no Autofill entries left.
EXPECT_CALL(*autofill_popup_controller_, Hide());
- EXPECT_CALL(*autofill_popup_controller_, InvalidateRow(_)).Times(0);
+ EXPECT_CALL(*autofill_popup_view_, OnSelectedRowChanged(_, _)).Times(0);
EXPECT_TRUE(autofill_popup_controller_->RemoveSelectedLine());
}
@@ -386,9 +402,9 @@ TEST_F(AutofillPopupControllerUnitTest, GetOrCreate) {
EXPECT_EQ(controller.get(), controller2.get());
controller->Hide();
- testing::NiceMock<TestAutofillPopupController>* test_controller =
- new testing::NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(),
- gfx::RectF());
+ NiceMock<TestAutofillPopupController>* test_controller =
+ new NiceMock<TestAutofillPopupController>(delegate.GetWeakPtr(),
+ gfx::RectF());
EXPECT_CALL(*test_controller, Hide());
gfx::RectF bounds(0.f, 0.f, 1.f, 2.f);
@@ -414,7 +430,7 @@ TEST_F(AutofillPopupControllerUnitTest, ProperlyResetController) {
std::vector<Suggestion> suggestions;
suggestions.push_back(Suggestion("", "", "", 0));
suggestions.push_back(Suggestion("", "", "", 0));
- popup_controller()->SetValues(suggestions);
+ popup_controller()->Show(suggestions);
popup_controller()->SetSelectedLine(0);
// Now show a new popup with the same controller, but with fewer items.

Powered by Google App Engine
This is Rietveld 408576698