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
|
// Copyright 2013 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/screen_capture_notification_ui_cocoa.h"
#include "base/bind.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
@interface ScreenCaptureNotificationController (ExposedForTesting)
- (NSButton*)stopButton;
- (NSButton*)minimizeButton;
@end
@implementation ScreenCaptureNotificationController (ExposedForTesting)
- (NSButton*)stopButton {
return stopButton_;
}
- (NSButton*)minimizeButton {
return minimizeButton_;
}
@end
class ScreenCaptureNotificationUICocoaTest : public CocoaTest {
public:
ScreenCaptureNotificationUICocoaTest()
: callback_called_(0) {
}
void TearDown() override {
callback_called_ = 0;
target_.reset();
EXPECT_EQ(0, callback_called_);
CocoaTest::TearDown();
}
void StopCallback() {
++callback_called_;
}
protected:
ScreenCaptureNotificationController* controller() {
return target_->windowController_.get();
}
scoped_ptr<ScreenCaptureNotificationUICocoa> target_;
int callback_called_;
DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUICocoaTest);
};
TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndDestroy) {
target_.reset(
new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
}
TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndStart) {
target_.reset(
new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
target_->OnStarted(
base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
base::Unretained(this)));
}
TEST_F(ScreenCaptureNotificationUICocoaTest, LongTitle) {
target_.reset(new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16(
"Very long title, with very very very very very very very very "
"very very very very very very very very very very very very many "
"words")));
target_->OnStarted(
base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
base::Unretained(this)));
// The elided label sometimes is a few pixels longer than the max width. So
// allow a 5px off from the 1000px maximium.
EXPECT_LE(NSWidth([[controller() window] frame]), 1005);
}
TEST_F(ScreenCaptureNotificationUICocoaTest, ShortTitle) {
target_.reset(
new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
target_->OnStarted(
base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
base::Unretained(this)));
EXPECT_EQ(460, NSWidth([[controller() window] frame]));
}
TEST_F(ScreenCaptureNotificationUICocoaTest, ClickStop) {
target_.reset(
new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
target_->OnStarted(
base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
base::Unretained(this)));
[[controller() stopButton] performClick:nil];
EXPECT_EQ(1, callback_called_);
}
TEST_F(ScreenCaptureNotificationUICocoaTest, CloseWindow) {
target_.reset(
new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
target_->OnStarted(
base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
base::Unretained(this)));
[[controller() window] close];
EXPECT_EQ(1, callback_called_);
}
TEST_F(ScreenCaptureNotificationUICocoaTest, MinimizeWindow) {
target_.reset(
new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
target_->OnStarted(
base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
base::Unretained(this)));
[[controller() minimizeButton] performClick:nil];
EXPECT_EQ(0, callback_called_);
EXPECT_TRUE([[controller() window] isMiniaturized]);
}
|