1 // Copyright 2013 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/screen_capture_notification_ui_cocoa.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
11 @interface ScreenCaptureNotificationController (ExposedForTesting)
12 - (NSButton*)stopButton;
13 - (NSButton*)minimizeButton;
16 @implementation ScreenCaptureNotificationController (ExposedForTesting)
17 - (NSButton*)stopButton {
21 - (NSButton*)minimizeButton {
22 return minimizeButton_;
26 class ScreenCaptureNotificationUICocoaTest : public CocoaTest {
28 ScreenCaptureNotificationUICocoaTest()
29 : callback_called_(0) {
32 void TearDown() override {
35 EXPECT_EQ(0, callback_called_);
37 CocoaTest::TearDown();
45 ScreenCaptureNotificationController* controller() {
46 return target_->windowController_.get();
49 scoped_ptr<ScreenCaptureNotificationUICocoa> target_;
52 DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUICocoaTest);
55 TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndDestroy) {
57 new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
60 TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndStart) {
62 new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
64 base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
65 base::Unretained(this)));
68 TEST_F(ScreenCaptureNotificationUICocoaTest, LongTitle) {
69 target_.reset(new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16(
70 "Very long title, with very very very very very very very very "
71 "very very very very very very very very very very very very many "
74 base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
75 base::Unretained(this)));
76 // The elided label sometimes is a few pixels longer than the max width. So
77 // allow a 5px off from the 1000px maximium.
78 EXPECT_LE(NSWidth([[controller() window] frame]), 1005);
81 TEST_F(ScreenCaptureNotificationUICocoaTest, ShortTitle) {
83 new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
85 base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
86 base::Unretained(this)));
87 EXPECT_EQ(460, NSWidth([[controller() window] frame]));
90 TEST_F(ScreenCaptureNotificationUICocoaTest, ClickStop) {
92 new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
94 base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
95 base::Unretained(this)));
97 [[controller() stopButton] performClick:nil];
98 EXPECT_EQ(1, callback_called_);
101 TEST_F(ScreenCaptureNotificationUICocoaTest, CloseWindow) {
103 new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
105 base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
106 base::Unretained(this)));
108 [[controller() window] close];
110 EXPECT_EQ(1, callback_called_);
113 TEST_F(ScreenCaptureNotificationUICocoaTest, MinimizeWindow) {
115 new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
117 base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
118 base::Unretained(this)));
120 [[controller() minimizeButton] performClick:nil];
122 EXPECT_EQ(0, callback_called_);
123 EXPECT_TRUE([[controller() window] isMiniaturized]);