File: find_bar_cocoa_controller_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 (136 lines) | stat: -rw-r--r-- 4,503 bytes parent folder | download | duplicates (2)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) 2011 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.

#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
#import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h"
#import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h"
#include "chrome/browser/ui/find_bar/find_notification_details.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#import "ui/base/cocoa/find_pasteboard.h"

// Expose private variables to make testing easier.
@interface FindBarCocoaController(Testing)
- (FindBarTextField*)findTextField;
@end

@implementation FindBarCocoaController(Testing)
- (FindBarTextField*)findTextField {
  return findText_;
}

- (NSButton*)nextButton {
  return nextButton_;
}

- (NSButton*)previousButton {
  return previousButton_;
}
@end

namespace {

class FindBarCocoaControllerTest : public CocoaTest {
 public:
  void SetUp() override {
    CocoaTest::SetUp();
    controller_.reset([[FindBarCocoaController alloc] initWithBrowser:nil]);
    [[test_window() contentView] addSubview:[controller_ view]];
  }

  void TearDown() override {
    CocoaTest::TearDown();
    [controller_ stopAnimation];
  }

 protected:
  base::scoped_nsobject<FindBarCocoaController> controller_;
};

TEST_VIEW(FindBarCocoaControllerTest, [controller_ view])

TEST_F(FindBarCocoaControllerTest, ImagesLoadedProperly) {
  EXPECT_TRUE([[[controller_ nextButton] image] isValid]);
  EXPECT_TRUE([[[controller_ previousButton] image] isValid]);
}

TEST_F(FindBarCocoaControllerTest, ShowAndHide) {
  NSView* findBarView = [controller_ findBarView];

  ASSERT_GT([findBarView frame].origin.y, 0);
  ASSERT_FALSE([controller_ isFindBarVisible]);
  ASSERT_TRUE([[controller_ view] isHidden]);

  [controller_ showFindBar:NO];
  EXPECT_EQ([findBarView frame].origin.y, 0);
  EXPECT_TRUE([controller_ isFindBarVisible]);
  ASSERT_FALSE([[controller_ view] isHidden]);

  [controller_ hideFindBar:NO];
  EXPECT_GT([findBarView frame].origin.y, 0);
  EXPECT_FALSE([controller_ isFindBarVisible]);
  ASSERT_TRUE([[controller_ view] isHidden]);
}

TEST_F(FindBarCocoaControllerTest, SetFindText) {
  NSTextField* findTextField = [controller_ findTextField];

  // Start by making the find bar visible.
  [controller_ showFindBar:NO];
  EXPECT_TRUE([controller_ isFindBarVisible]);

  // Set the find text.
  NSString* const kFindText = @"Google";
  [controller_ setFindText:kFindText selectedRange:NSMakeRange(NSNotFound, 0)];
  EXPECT_EQ(
      NSOrderedSame,
      [[findTextField stringValue] compare:kFindText]);

  // Call clearResults, which doesn't actually clear the find text but
  // simply sets it back to what it was before.  This is silly, but
  // matches the behavior on other platforms.  |details| isn't used by
  // our implementation of clearResults, so it's ok to pass in an
  // empty |details|.
  FindNotificationDetails details;
  [controller_ clearResults:details];
  EXPECT_EQ(
      NSOrderedSame,
      [[findTextField stringValue] compare:kFindText]);
}

TEST_F(FindBarCocoaControllerTest, ResultLabelUpdatesCorrectly) {
  // TODO(rohitrao): Test this.  It may involve creating some dummy
  // FindNotificationDetails objects.
}

TEST_F(FindBarCocoaControllerTest, FindTextIsGlobal) {
  base::scoped_nsobject<FindBarCocoaController> otherController(
      [[FindBarCocoaController alloc] initWithBrowser:nil]);
  [[test_window() contentView] addSubview:[otherController view]];

  // Setting the text in one controller should update the other controller's
  // text as well.
  NSString* const kFindText = @"Respect to the man in the ice cream van";
  [controller_ setFindText:kFindText selectedRange:NSMakeRange(NSNotFound, 0)];
  EXPECT_EQ(
      NSOrderedSame,
      [[controller_ findText] compare:kFindText]);
  EXPECT_EQ(
      NSOrderedSame,
      [[otherController.get() findText] compare:kFindText]);
}

TEST_F(FindBarCocoaControllerTest, SettingFindTextUpdatesFindPboard) {
  NSString* const kFindText =
      @"It's not a bird, it's not a plane, it must be Dave who's on the train";
  [controller_ setFindText:kFindText selectedRange:NSMakeRange(NSNotFound, 0)];
  EXPECT_EQ(
      NSOrderedSame,
      [[[FindPasteboard sharedInstance] findText] compare:kFindText]);
}

}  // namespace