Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / screen_capture_notification_ui_cocoa_unittest.mm
blob284ca3e63288831d6cb9844e63b3b1458900dcf6
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"
7 #include "base/bind.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 @end
15 @implementation ScreenCaptureNotificationController (ExposedForTesting)
16 - (NSButton*)stopButton {
17   return stopButton_;
19 @end
21 class ScreenCaptureNotificationUICocoaTest : public CocoaTest {
22  public:
23   ScreenCaptureNotificationUICocoaTest()
24       : callback_called_(0) {
25   }
27   virtual void TearDown() OVERRIDE {
28     callback_called_ = 0;
29     target_.reset();
30     EXPECT_EQ(0, callback_called_);
32     CocoaTest::TearDown();
33   }
35   void StopCallback() {
36     ++callback_called_;
37   }
39  protected:
40   ScreenCaptureNotificationController* controller() {
41     return target_->windowController_.get();
42   }
44   scoped_ptr<ScreenCaptureNotificationUICocoa> target_;
45   int callback_called_;
47   DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUICocoaTest);
50 TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndDestroy) {
51   target_.reset(
52       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
55 TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndStart) {
56   target_.reset(
57       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
58   target_->OnStarted(
59       base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
60                  base::Unretained(this)));
63 TEST_F(ScreenCaptureNotificationUICocoaTest, LongTitle) {
64   target_.reset(new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16(
65       "Very long title, with very very very very very very very very "
66       "very very very very very very very very very very very very many "
67       "words")));
68   target_->OnStarted(
69       base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
70                  base::Unretained(this)));
71   EXPECT_LE(NSWidth([[controller() window] frame]), 1000);
74 TEST_F(ScreenCaptureNotificationUICocoaTest, ShortTitle) {
75   target_.reset(
76       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
77   target_->OnStarted(
78       base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
79                  base::Unretained(this)));
80   EXPECT_EQ(460, NSWidth([[controller() window] frame]));
83 TEST_F(ScreenCaptureNotificationUICocoaTest, ClickStop) {
84   target_.reset(
85       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
86   target_->OnStarted(
87       base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
88                  base::Unretained(this)));
90   [[controller() stopButton] performClick:nil];
91   EXPECT_EQ(1, callback_called_);
94 TEST_F(ScreenCaptureNotificationUICocoaTest, CloseWindow) {
95   target_.reset(
96       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
97   target_->OnStarted(
98       base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
99                  base::Unretained(this)));
101   [[controller() window] close];
103   EXPECT_EQ(1, callback_called_);