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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_view_helper_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: remove scoped_ptr and rename mac delegate 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_helper.h"
6
7 #include <stddef.h>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/ui/autofill/autofill_popup_view.h"
11 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h"
12 #include "chrome/browser/ui/autofill/popup_constants.h"
13 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
14 #include "components/autofill/core/browser/suggestion.h"
15 #include "content/public/browser/web_contents.h"
16 #include "grit/components_scaled_resources.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/gfx/geometry/point.h"
20 #include "ui/gfx/geometry/rect.h"
21 #include "ui/gfx/geometry/rect_f.h"
22 #include "ui/gfx/native_widget_types.h"
23
24 namespace autofill {
25
26 namespace {
27
28 class TestAutofillPopupViewDelegate : public AutofillPopupViewDelegate {
29 public:
30 explicit TestAutofillPopupViewDelegate(content::WebContents* web_contents)
31 : element_bounds_(0.0, 0.0, 100.0, 100.0),
32 container_view_(web_contents->GetNativeView()) {}
33
34 void Hide() override {}
35 void ViewDestroyed() override{};
36 void SetSelectionAtPoint(const gfx::Point& point) override {}
37 bool AcceptSelectedLine() override { return true; }
38 void SelectionCleared() override {}
39 gfx::Rect popup_bounds() const override { return gfx::Rect(0, 0, 100, 100); }
40 gfx::NativeView container_view() override { return container_view_; }
41 const gfx::RectF& element_bounds() const override { return element_bounds_; }
42 bool IsRTL() const override { return false; }
43
44 const std::vector<autofill::Suggestion> GetSuggestions() override {
45 // Give elements 1 and 3 subtexts and elements 2 and 3 icons, to ensure
46 // all combinations of subtexts and icons.
47 std::vector<Suggestion> suggestions;
48 suggestions.push_back(Suggestion("", "", "", 0));
49 suggestions.push_back(Suggestion("", "x", "", 0));
50 suggestions.push_back(Suggestion("", "", "americanExpressCC", 0));
51 suggestions.push_back(Suggestion("", "x", "genericCC", 0));
52 return suggestions;
53 }
54 #if !defined(OS_ANDROID)
55 int GetElidedValueWidthForRow(size_t row) override { return 0; }
56 int GetElidedLabelWidthForRow(size_t row) override { return 0; }
57 #endif
58
59 private:
60 gfx::RectF element_bounds_;
61 gfx::NativeView container_view_;
62 };
63
64 class AutofillPopupViewHelperTest : public ChromeRenderViewHostTestHarness {
65 public:
66 void SetUp() override {
67 ChromeRenderViewHostTestHarness::SetUp();
68
69 delegate_.reset(new TestAutofillPopupViewDelegate(web_contents()));
70 view_helper_.reset(new AutofillPopupViewHelper(delegate_.get()));
71 }
72
73 AutofillPopupViewHelper* view_helper() { return view_helper_.get(); }
74
75 private:
76 scoped_ptr<TestAutofillPopupViewDelegate> delegate_;
77 scoped_ptr<AutofillPopupViewHelper> view_helper_;
78 };
79
80 } // namespace
81
82 #if !defined(OS_ANDROID)
83 TEST_F(AutofillPopupViewHelperTest, RowWidthWithoutText) {
84 int base_size =
85 AutofillPopupView::kEndPadding * 2 + kPopupBorderThickness * 2;
86 int subtext_increase = AutofillPopupView::kNamePadding;
87
88 // Refer to GetSuggestions() in TestAutofillPopupViewDelegate.
89 EXPECT_EQ(base_size,
90 view_helper()->RowWidthWithoutText(0, /* with_label= */ false));
91 EXPECT_EQ(base_size + subtext_increase,
92 view_helper()->RowWidthWithoutText(1, /* with_label= */ true));
93 EXPECT_EQ(base_size + AutofillPopupView::kIconPadding +
94 ui::ResourceBundle::GetSharedInstance()
95 .GetImageNamed(IDR_AUTOFILL_CC_AMEX)
96 .Width(),
97 view_helper()->RowWidthWithoutText(2, /* with_label= */ false));
98 EXPECT_EQ(base_size + subtext_increase + AutofillPopupView::kIconPadding +
99 ui::ResourceBundle::GetSharedInstance()
100 .GetImageNamed(IDR_AUTOFILL_CC_GENERIC)
101 .Width(),
102 view_helper()->RowWidthWithoutText(3, /* with_label= */ true));
103 }
104 #endif
105
106 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698