Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / screen_capture_notification_ui_cocoa_unittest.mm
blobe7da2c4e2f3a346b84afd74949523d13db7a38c3
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 - (NSButton*)minimizeButton;
14 @end
16 @implementation ScreenCaptureNotificationController (ExposedForTesting)
17 - (NSButton*)stopButton {
18   return stopButton_;
21 - (NSButton*)minimizeButton {
22   return minimizeButton_;
24 @end
26 class ScreenCaptureNotificationUICocoaTest : public CocoaTest {
27  public:
28   ScreenCaptureNotificationUICocoaTest()
29       : callback_called_(0) {
30   }
32   void TearDown() override {
33     callback_called_ = 0;
34     target_.reset();
35     EXPECT_EQ(0, callback_called_);
37     CocoaTest::TearDown();
38   }
40   void StopCallback() {
41     ++callback_called_;
42   }
44  protected:
45   ScreenCaptureNotificationController* controller() {
46     return target_->windowController_.get();
47   }
49   scoped_ptr<ScreenCaptureNotificationUICocoa> target_;
50   int callback_called_;
52   DISALLOW_COPY_AND_ASSIGN(ScreenCaptureNotificationUICocoaTest);
55 TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndDestroy) {
56   target_.reset(
57       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
60 TEST_F(ScreenCaptureNotificationUICocoaTest, CreateAndStart) {
61   target_.reset(
62       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
63   target_->OnStarted(
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 "
72       "words")));
73   target_->OnStarted(
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) {
82   target_.reset(
83       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
84   target_->OnStarted(
85       base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
86                  base::Unretained(this)));
87   EXPECT_EQ(460, NSWidth([[controller() window] frame]));
90 TEST_F(ScreenCaptureNotificationUICocoaTest, ClickStop) {
91   target_.reset(
92       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
93   target_->OnStarted(
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) {
102   target_.reset(
103       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
104   target_->OnStarted(
105       base::Bind(&ScreenCaptureNotificationUICocoaTest::StopCallback,
106                  base::Unretained(this)));
108   [[controller() window] close];
110   EXPECT_EQ(1, callback_called_);
113 TEST_F(ScreenCaptureNotificationUICocoaTest, MinimizeWindow) {
114   target_.reset(
115       new ScreenCaptureNotificationUICocoa(base::UTF8ToUTF16("Title")));
116   target_->OnStarted(
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]);