OLD | NEW |
| (Empty) |
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/tabs/media_indicator_button_cocoa.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/command_line.h" | |
10 #include "base/mac/scoped_nsobject.h" | |
11 #include "base/message_loop/message_loop.h" | |
12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | |
13 #include "chrome/common/chrome_switches.h" | |
14 #include "testing/gtest/include/gtest/gtest.h" | |
15 #include "testing/platform_test.h" | |
16 | |
17 // A simple target to confirm an action was invoked. | |
18 @interface MediaIndicatorButtonTestTarget : NSObject { | |
19 @private | |
20 int count_; | |
21 } | |
22 @property(readonly, nonatomic) int count; | |
23 - (void)incrementCount:(id)sender; | |
24 @end | |
25 | |
26 @implementation MediaIndicatorButtonTestTarget | |
27 @synthesize count = count_; | |
28 - (void)incrementCount:(id)sender { | |
29 ++count_; | |
30 } | |
31 @end | |
32 | |
33 namespace { | |
34 | |
35 class MediaIndicatorButtonTest : public CocoaTest { | |
36 public: | |
37 MediaIndicatorButtonTest() { | |
38 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
39 std::string("--") + switches::kEnableTabAudioMuting); | |
40 | |
41 // Create the MediaIndicatorButton and add it to a view. | |
42 button_.reset([[MediaIndicatorButton alloc] init]); | |
43 EXPECT_TRUE(button_ != nil); | |
44 [[test_window() contentView] addSubview:button_.get()]; | |
45 | |
46 // Initially the button is disabled and showing no indicator. | |
47 EXPECT_EQ(TAB_MEDIA_STATE_NONE, [button_ showingMediaState]); | |
48 EXPECT_FALSE([button_ isEnabled]); | |
49 | |
50 // Register target to be notified of clicks. | |
51 base::scoped_nsobject<MediaIndicatorButtonTestTarget> clickTarget( | |
52 [[MediaIndicatorButtonTestTarget alloc] init]); | |
53 EXPECT_EQ(0, [clickTarget count]); | |
54 [button_ setClickTarget:clickTarget withAction:@selector(incrementCount:)]; | |
55 | |
56 // Transition to audio indicator mode, and expect button is enabled. | |
57 [button_ transitionToMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING]; | |
58 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [button_ showingMediaState]); | |
59 EXPECT_TRUE([button_ isEnabled]); | |
60 | |
61 // Click, and expect one click notification. | |
62 EXPECT_EQ(0, [clickTarget count]); | |
63 [button_ performClick:button_]; | |
64 EXPECT_EQ(1, [clickTarget count]); | |
65 | |
66 // Transition to audio muting mode, and expect button is still enabled. A | |
67 // click should result in another click notification. | |
68 [button_ transitionToMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; | |
69 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_MUTING, [button_ showingMediaState]); | |
70 EXPECT_TRUE([button_ isEnabled]); | |
71 [button_ performClick:button_]; | |
72 EXPECT_EQ(2, [clickTarget count]); | |
73 | |
74 // Transition to capturing mode. Now, the button is disabled since it | |
75 // should only be drawing the indicator icon (i.e., there is nothing to | |
76 // mute). A click should NOT result in another click notification. | |
77 [button_ transitionToMediaState:TAB_MEDIA_STATE_CAPTURING]; | |
78 EXPECT_EQ(TAB_MEDIA_STATE_CAPTURING, [button_ showingMediaState]); | |
79 EXPECT_FALSE([button_ isEnabled]); | |
80 [button_ performClick:button_]; | |
81 EXPECT_EQ(2, [clickTarget count]); | |
82 } | |
83 | |
84 base::scoped_nsobject<MediaIndicatorButton> button_; | |
85 base::MessageLoopForUI message_loop_; // Needed for gfx::Animation. | |
86 }; | |
87 | |
88 TEST_VIEW(MediaIndicatorButtonTest, button_) | |
89 | |
90 } // namespace | |
OLD | NEW |