- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / screen_capture_notification_ui_cocoa_unittest.mm
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.
4
5 #import "chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.h"
6
7 #include "base/bind.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/cocoa/cocoa_test_helper.h"
10
11 @interface ScreenCaptureNotificationController (ExposedForTesting)
12 - (NSButton*)stopButton;
13 @end
14
15 @implementation ScreenCaptureNotificationController (ExposedForTesting)
16 - (NSButton*)stopButton {
17   return stopButton_;
18 }
19 @end
20
21 class ScreenCaptureNotificationUICocoaTest : public CocoaTest {
22  public:
23   ScreenCaptureNotificationUICocoaTest()
24       : callback_called_(0) {
25   }
26
27   virtual void TearDown() OVERRIDE {
28     callback_called_ = 0;
29     target_.reset();
30     EXPECT_EQ(0, callback_called_);
31
32     CocoaTest::TearDown();
33   }
34
35   void StopCallback() {
36     ++callback_called_;
37   }
38
39  protected:
40   ScreenCaptureNotificationController* controller() {
41     return target_->windowController_.get();
42   }
43
44   scoped_ptr<ScreenCaptureNotificationUICocoa> target_;
45   int callback_called_;
46
47   DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUICocoaTest);
48 };
49
50 TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndDestroy) {
51   target_.reset(
52       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
53 }
54
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)));
61 }
62
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);
72 }
73
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]));
81 }
82
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)));
89
90   [[controller() stopButton] performClick:nil];
91   EXPECT_EQ(1, callback_called_);
92 }
93
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)));
100
101   [[controller() window] close];
102
103   EXPECT_EQ(1, callback_called_);
104 }