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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_view_unittest.cc

Issue 1570783003: [Autofill] Move functions from the AutofillPopupController to AutofillPopupLayoutModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 years, 11 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
6
7 #include <stddef.h>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h"
11 #include "chrome/browser/ui/autofill/popup_constants.h"
12 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
13 #include "components/autofill/core/browser/suggestion.h"
14 #include "content/public/browser/web_contents.h"
15 #include "grit/components_scaled_resources.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/gfx/geometry/point.h"
19 #include "ui/gfx/geometry/rect.h"
20 #include "ui/gfx/geometry/rect_f.h"
21 #include "ui/gfx/native_widget_types.h"
22
23 namespace autofill {
24
25 namespace {
26
27 class TestAutofillPopupViewDelegate : public AutofillPopupViewDelegate {
28 public:
29 explicit TestAutofillPopupViewDelegate(content::WebContents* web_contents)
30 : element_bounds_(0.0, 0.0, 100.0, 100.0),
31 container_view_(web_contents->GetNativeView()) {}
32
33 void Hide() override {}
34 void ViewDestroyed() override{};
35 void SetSelectionAtPoint(const gfx::Point& point) override {}
36 bool AcceptSelectedLine() override { return true; }
37 void SelectionCleared() override {}
38 gfx::Rect popup_bounds() const override { return gfx::Rect(0, 0, 100, 100); }
39 gfx::NativeView container_view() override { return container_view_; }
40 const gfx::RectF& element_bounds() const override { return element_bounds_; }
41 bool IsRTL() const override { return false; }
42
43 const std::vector<autofill::Suggestion> GetSuggestions() override {
44 // Give elements 1 and 3 subtexts and elements 2 and 3 icons, to ensure
45 // all combinations of subtexts and icons.
46 std::vector<Suggestion> suggestions;
47 suggestions.push_back(Suggestion("", "", "", 0));
48 suggestions.push_back(Suggestion("", "x", "", 0));
49 suggestions.push_back(Suggestion("", "", "americanExpressCC", 0));
50 suggestions.push_back(Suggestion("", "x", "genericCC", 0));
51 return suggestions;
52 }
53 #if !defined(OS_ANDROID)
54 int GetElidedValueWidthForRow(size_t row) override { return 0; }
55 int GetElidedLabelWidthForRow(size_t row) override { return 0; }
56 #endif
57
58 private:
59 gfx::RectF element_bounds_;
60 gfx::NativeView container_view_;
61 };
62
63 // Implementing the platform-specific bits of AutofillPopupView for testing.
64 class TestAutofillPopupView : public AutofillPopupView {
65 public:
66 explicit TestAutofillPopupView(AutofillPopupViewDelegate* delegate)
67 : AutofillPopupView(delegate) {}
68
69 void Show() override {}
70 void Hide() override {}
71 void InvalidateRow(size_t row) override {}
72 void UpdateBoundsAndRedrawPopup() override {}
73 };
74
75 class AutofillPopupViewTest : public ChromeRenderViewHostTestHarness {
76 public:
77 void SetUp() override {
78 ChromeRenderViewHostTestHarness::SetUp();
79
80 delegate_.reset(new TestAutofillPopupViewDelegate(web_contents()));
81 view_.reset(new TestAutofillPopupView(delegate_.get()));
82 }
83
84 AutofillPopupView* view() { return view_.get(); }
85
86 private:
87 scoped_ptr<TestAutofillPopupViewDelegate> delegate_;
88 scoped_ptr<AutofillPopupView> view_;
89 };
90
91 } // namespace
92
93 TEST_F(AutofillPopupViewTest, RowWidthWithoutText) {
94 int base_size =
95 AutofillPopupView::kEndPadding * 2 + kPopupBorderThickness * 2;
96 int subtext_increase = AutofillPopupView::kNamePadding;
97
98 // Refer to GetSuggestions() in TestAutofillPopupViewDelegate.
99 EXPECT_EQ(base_size, view()->RowWidthWithoutText(0, /* with_label= */ false));
100 EXPECT_EQ(base_size + subtext_increase,
101 view()->RowWidthWithoutText(1, /* with_label= */ true));
102 EXPECT_EQ(base_size + AutofillPopupView::kIconPadding +
103 ui::ResourceBundle::GetSharedInstance()
104 .GetImageNamed(IDR_AUTOFILL_CC_AMEX)
105 .Width(),
106 view()->RowWidthWithoutText(2, /* with_label= */ false));
107 EXPECT_EQ(base_size + subtext_increase + AutofillPopupView::kIconPadding +
108 ui::ResourceBundle::GetSharedInstance()
109 .GetImageNamed(IDR_AUTOFILL_CC_GENERIC)
110 .Width(),
111 view()->RowWidthWithoutText(3, /* with_label= */ true));
112 }
113
114 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698