BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / omnibox / omnibox_popup_view_mac_unittest.mm
blob5bc6be2f36f421839b5db608c04d65c64d00856a
1 // Copyright (c) 2012 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.
5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/sys_string_conversions.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
11 #import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
12 #include "chrome/test/base/testing_profile.h"
13 #include "components/omnibox/browser/autocomplete_input.h"
14 #include "ui/gfx/font_list.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/text_elider.h"
18 namespace {
20 class MockOmniboxPopupViewMac : public OmniboxPopupViewMac {
21  public:
22   MockOmniboxPopupViewMac(OmniboxView* omnibox_view,
23                           OmniboxEditModel* edit_model,
24                           NSTextField* field)
25       : OmniboxPopupViewMac(omnibox_view, edit_model, field) {
26   }
28   void SetResultCount(size_t count) {
29     ACMatches matches;
30     for (size_t i = 0; i < count; ++i)
31       matches.push_back(AutocompleteMatch());
32     result_.Reset();
33     result_.AppendMatches(AutocompleteInput(), matches);
34   }
36  protected:
37   const AutocompleteResult& GetResult() const override { return result_; }
39  private:
40   AutocompleteResult result_;
43 class OmniboxPopupViewMacTest : public CocoaProfileTest {
44  public:
45   OmniboxPopupViewMacTest() {}
47  private:
48   DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewMacTest);
51 TEST_F(OmniboxPopupViewMacTest, UpdatePopupAppearance) {
52   base::scoped_nsobject<NSTextField> field(
53       [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 20)]);
54   [[test_window() contentView] addSubview:field];
56   OmniboxViewMac view(NULL, profile(), NULL, NULL);
57   MockOmniboxPopupViewMac popup_view(&view, view.model(), field);
59   popup_view.UpdatePopupAppearance();
60   EXPECT_FALSE(popup_view.IsOpen());
61   EXPECT_EQ(0, [popup_view.matrix() numberOfRows]);
63   popup_view.SetResultCount(3);
64   popup_view.UpdatePopupAppearance();
65   EXPECT_TRUE(popup_view.IsOpen());
66   EXPECT_EQ(3, [popup_view.matrix() numberOfRows]);
68   int old_height = popup_view.GetTargetBounds().height();
69   popup_view.SetResultCount(5);
70   popup_view.UpdatePopupAppearance();
71   EXPECT_GT(popup_view.GetTargetBounds().height(), old_height);
72   EXPECT_EQ(5, [popup_view.matrix() numberOfRows]);
74   popup_view.SetResultCount(0);
75   popup_view.UpdatePopupAppearance();
76   EXPECT_FALSE(popup_view.IsOpen());
77   EXPECT_EQ(0, [popup_view.matrix() numberOfRows]);
80 }  // namespace