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

Side by Side Diff: chrome/browser/ui/autofill/autofill_popup_layout_model_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: layout model 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_layout_model.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 AutofillPopupLayoutModelTest : public ChromeRenderViewHostTestHarness {
65 public:
66 void SetUp() override {
67 ChromeRenderViewHostTestHarness::SetUp();
68
69 delegate_.reset(new TestAutofillPopupViewDelegate(web_contents()));
70 layout_model_.reset(new AutofillPopupLayoutModel(delegate_.get()));
71 }
72
73 AutofillPopupLayoutModel* layout_model() { return layout_model_.get(); }
74
75 private:
76 scoped_ptr<TestAutofillPopupViewDelegate> delegate_;
77 scoped_ptr<AutofillPopupLayoutModel> layout_model_;
78 };
79
80 } // namespace
81
82 #if !defined(OS_ANDROID)
83 TEST_F(AutofillPopupLayoutModelTest, RowWidthWithoutText) {
84 int base_size =
85 AutofillPopupLayoutModel::kEndPadding * 2 + kPopupBorderThickness * 2;
86 int subtext_increase = AutofillPopupLayoutModel::kNamePadding;
87
88 // Refer to GetSuggestions() in TestAutofillPopupViewDelegate.
89 EXPECT_EQ(base_size,
90 layout_model()->RowWidthWithoutText(0, /* with_label= */ false));
91 EXPECT_EQ(base_size + subtext_increase,
92 layout_model()->RowWidthWithoutText(1, /* with_label= */ true));
93 EXPECT_EQ(base_size + AutofillPopupLayoutModel::kIconPadding +
94 ui::ResourceBundle::GetSharedInstance()
95 .GetImageNamed(IDR_AUTOFILL_CC_AMEX)
96 .Width(),
97 layout_model()->RowWidthWithoutText(2, /* with_label= */ false));
98 EXPECT_EQ(base_size + subtext_increase +
99 AutofillPopupLayoutModel::kIconPadding +
100 ui::ResourceBundle::GetSharedInstance()
101 .GetImageNamed(IDR_AUTOFILL_CC_GENERIC)
102 .Width(),
103 layout_model()->RowWidthWithoutText(3, /* with_label= */ true));
104 }
105 #endif
106
107 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698