File: omnibox_popup_view_mac_unittest.mm

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (85 lines) | stat: -rw-r--r-- 2,669 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h"

#include <stddef.h>

#include <memory>

#include "base/macros.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "chrome/browser/ui/cocoa/omnibox/omnibox_view_mac.h"
#include "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
#include "chrome/test/base/testing_profile.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_result.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/text_elider.h"

namespace {

class MockOmniboxPopupViewMac : public OmniboxPopupViewMac {
 public:
  MockOmniboxPopupViewMac(OmniboxView* omnibox_view,
                          OmniboxEditModel* edit_model,
                          NSTextField* field)
      : OmniboxPopupViewMac(omnibox_view, edit_model, field) {
  }

  void SetResultCount(size_t count) {
    ACMatches matches;
    for (size_t i = 0; i < count; ++i)
      matches.push_back(AutocompleteMatch());
    result_.Reset();
    result_.AppendMatches(AutocompleteInput(), matches);
  }

 protected:
  const AutocompleteResult& GetResult() const override { return result_; }

 private:
  AutocompleteResult result_;
};

class OmniboxPopupViewMacTest : public CocoaProfileTest {
 public:
  OmniboxPopupViewMacTest() {}

 private:
  DISALLOW_COPY_AND_ASSIGN(OmniboxPopupViewMacTest);
};

TEST_F(OmniboxPopupViewMacTest, UpdatePopupAppearance) {
  base::scoped_nsobject<NSTextField> field(
      [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 20)]);
  [[test_window() contentView] addSubview:field];

  OmniboxViewMac view(NULL, profile(), NULL, NULL);
  MockOmniboxPopupViewMac popup_view(&view, view.model(), field);

  popup_view.UpdatePopupAppearance();
  EXPECT_FALSE(popup_view.IsOpen());
  EXPECT_EQ(0, [popup_view.matrix() numberOfRows]);

  popup_view.SetResultCount(3);
  popup_view.UpdatePopupAppearance();
  EXPECT_TRUE(popup_view.IsOpen());
  EXPECT_EQ(3, [popup_view.matrix() numberOfRows]);

  int old_height = popup_view.GetTargetBounds().height();
  popup_view.SetResultCount(5);
  popup_view.UpdatePopupAppearance();
  EXPECT_GT(popup_view.GetTargetBounds().height(), old_height);
  EXPECT_EQ(5, [popup_view.matrix() numberOfRows]);

  popup_view.SetResultCount(0);
  popup_view.UpdatePopupAppearance();
  EXPECT_FALSE(popup_view.IsOpen());
  EXPECT_EQ(0, [popup_view.matrix() numberOfRows]);
}

}  // namespace