Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / omnibox / omnibox_popup_view_mac_unittest.mm
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.
4
5 #import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h"
6
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 "ui/gfx/font_list.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/text_elider.h"
16
17 namespace {
18
19 class MockOmniboxPopupViewMac : public OmniboxPopupViewMac {
20  public:
21   MockOmniboxPopupViewMac(OmniboxView* omnibox_view,
22                           OmniboxEditModel* edit_model,
23                           NSTextField* field)
24       : OmniboxPopupViewMac(omnibox_view, edit_model, field) {
25   }
26
27   void SetResultCount(size_t count) {
28     ACMatches matches;
29     for (size_t i = 0; i < count; ++i)
30       matches.push_back(AutocompleteMatch());
31     result_.Reset();
32     result_.AppendMatches(matches);
33   }
34
35  protected:
36   const AutocompleteResult& GetResult() const override { return result_; }
37
38  private:
39   AutocompleteResult result_;
40 };
41
42 class OmniboxPopupViewMacTest : public CocoaProfileTest {
43  public:
44   OmniboxPopupViewMacTest() {}
45
46  private:
47   DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewMacTest);
48 };
49
50 TEST_F(OmniboxPopupViewMacTest, UpdatePopupAppearance) {
51   base::scoped_nsobject<NSTextField> field(
52       [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 20)]);
53   [[test_window() contentView] addSubview:field];
54
55   OmniboxViewMac view(NULL, profile(), NULL, NULL);
56   MockOmniboxPopupViewMac popup_view(&view, view.model(), field);
57
58   popup_view.UpdatePopupAppearance();
59   EXPECT_FALSE(popup_view.IsOpen());
60   EXPECT_EQ(0, [popup_view.matrix() numberOfRows]);
61
62   popup_view.SetResultCount(3);
63   popup_view.UpdatePopupAppearance();
64   EXPECT_TRUE(popup_view.IsOpen());
65   EXPECT_EQ(3, [popup_view.matrix() numberOfRows]);
66
67   int old_height = popup_view.GetTargetBounds().height();
68   popup_view.SetResultCount(5);
69   popup_view.UpdatePopupAppearance();
70   EXPECT_GT(popup_view.GetTargetBounds().height(), old_height);
71   EXPECT_EQ(5, [popup_view.matrix() numberOfRows]);
72
73   popup_view.SetResultCount(0);
74   popup_view.UpdatePopupAppearance();
75   EXPECT_FALSE(popup_view.IsOpen());
76   EXPECT_EQ(0, [popup_view.matrix() numberOfRows]);
77 }
78
79 }  // namespace