Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(885)

Side by Side Diff: chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa_unittest.mm

Issue 1827083004: UI: Rename MediaState to AlertState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-tab-indicator
Patch Set: Keep gypi ordered Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/tabs/media_indicator_button_cocoa.h" 5 #import "chrome/browser/ui/cocoa/tabs/alert_indicator_button_cocoa.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" 12 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
16 16
17 // A simple target to confirm an action was invoked. 17 // A simple target to confirm an action was invoked.
18 @interface MediaIndicatorButtonTestTarget : NSObject { 18 @interface AlertIndicatorButtonTestTarget : NSObject {
19 @private 19 @private
20 int count_; 20 int count_;
21 } 21 }
22 @property(readonly, nonatomic) int count; 22 @property(readonly, nonatomic) int count;
23 - (void)incrementCount:(id)sender; 23 - (void)incrementCount:(id)sender;
24 @end 24 @end
25 25
26 @implementation MediaIndicatorButtonTestTarget 26 @implementation AlertIndicatorButtonTestTarget
27 @synthesize count = count_; 27 @synthesize count = count_;
28 - (void)incrementCount:(id)sender { 28 - (void)incrementCount:(id)sender {
29 ++count_; 29 ++count_;
30 } 30 }
31 @end 31 @end
32 32
33 namespace { 33 namespace {
34 34
35 class MediaIndicatorButtonTest : public CocoaTest { 35 class AlertIndicatorButtonTest : public CocoaTest {
36 public: 36 public:
37 MediaIndicatorButtonTest() { 37 AlertIndicatorButtonTest() {
38 base::CommandLine::ForCurrentProcess()->AppendSwitch( 38 base::CommandLine::ForCurrentProcess()->AppendSwitch(
39 std::string("--") + switches::kEnableTabAudioMuting); 39 std::string("--") + switches::kEnableTabAudioMuting);
40 40
41 // Create the MediaIndicatorButton and add it to a view. 41 // Create the AlertIndicatorButton and add it to a view.
42 button_.reset([[MediaIndicatorButton alloc] init]); 42 button_.reset([[AlertIndicatorButton alloc] init]);
43 EXPECT_TRUE(button_ != nil); 43 EXPECT_TRUE(button_ != nil);
44 [[test_window() contentView] addSubview:button_.get()]; 44 [[test_window() contentView] addSubview:button_.get()];
45 45
46 // Initially the button is disabled and showing no indicator. 46 // Initially the button is disabled and showing no indicator.
47 EXPECT_EQ(TAB_MEDIA_STATE_NONE, [button_ showingMediaState]); 47 EXPECT_EQ(TabAlertState::NONE, [button_ showingAlertState]);
48 EXPECT_FALSE([button_ isEnabled]); 48 EXPECT_FALSE([button_ isEnabled]);
49 49
50 // Register target to be notified of clicks. 50 // Register target to be notified of clicks.
51 base::scoped_nsobject<MediaIndicatorButtonTestTarget> clickTarget( 51 base::scoped_nsobject<AlertIndicatorButtonTestTarget> clickTarget(
52 [[MediaIndicatorButtonTestTarget alloc] init]); 52 [[AlertIndicatorButtonTestTarget alloc] init]);
53 EXPECT_EQ(0, [clickTarget count]); 53 EXPECT_EQ(0, [clickTarget count]);
54 [button_ setClickTarget:clickTarget withAction:@selector(incrementCount:)]; 54 [button_ setClickTarget:clickTarget withAction:@selector(incrementCount:)];
55 55
56 // Transition to audio indicator mode, and expect button is enabled. 56 // Transition to audio indicator mode, and expect button is enabled.
57 [button_ transitionToMediaState:TAB_MEDIA_STATE_AUDIO_PLAYING]; 57 [button_ transitionToAlertState:TabAlertState::AUDIO_PLAYING];
58 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [button_ showingMediaState]); 58 EXPECT_EQ(TabAlertState::AUDIO_PLAYING, [button_ showingAlertState]);
59 EXPECT_TRUE([button_ isEnabled]); 59 EXPECT_TRUE([button_ isEnabled]);
60 60
61 // Click, and expect one click notification. 61 // Click, and expect one click notification.
62 EXPECT_EQ(0, [clickTarget count]); 62 EXPECT_EQ(0, [clickTarget count]);
63 [button_ performClick:button_]; 63 [button_ performClick:button_];
64 EXPECT_EQ(1, [clickTarget count]); 64 EXPECT_EQ(1, [clickTarget count]);
65 65
66 // Transition to audio muting mode, and expect button is still enabled. A 66 // Transition to audio muting mode, and expect button is still enabled. A
67 // click should result in another click notification. 67 // click should result in another click notification.
68 [button_ transitionToMediaState:TAB_MEDIA_STATE_AUDIO_MUTING]; 68 [button_ transitionToAlertState:TabAlertState::AUDIO_MUTING];
69 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_MUTING, [button_ showingMediaState]); 69 EXPECT_EQ(TabAlertState::AUDIO_MUTING, [button_ showingAlertState]);
70 EXPECT_TRUE([button_ isEnabled]); 70 EXPECT_TRUE([button_ isEnabled]);
71 [button_ performClick:button_]; 71 [button_ performClick:button_];
72 EXPECT_EQ(2, [clickTarget count]); 72 EXPECT_EQ(2, [clickTarget count]);
73 73
74 // Transition to capturing mode. Now, the button is disabled since it 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 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. 76 // mute). A click should NOT result in another click notification.
77 [button_ transitionToMediaState:TAB_MEDIA_STATE_CAPTURING]; 77 [button_ transitionToAlertState:TabAlertState::TAB_CAPTURING];
78 EXPECT_EQ(TAB_MEDIA_STATE_CAPTURING, [button_ showingMediaState]); 78 EXPECT_EQ(TabAlertState::TAB_CAPTURING, [button_ showingAlertState]);
79 EXPECT_FALSE([button_ isEnabled]); 79 EXPECT_FALSE([button_ isEnabled]);
80 [button_ performClick:button_]; 80 [button_ performClick:button_];
81 EXPECT_EQ(2, [clickTarget count]); 81 EXPECT_EQ(2, [clickTarget count]);
82 } 82 }
83 83
84 base::scoped_nsobject<MediaIndicatorButton> button_; 84 base::scoped_nsobject<AlertIndicatorButton> button_;
85 base::MessageLoopForUI message_loop_; // Needed for gfx::Animation. 85 base::MessageLoopForUI message_loop_; // Needed for gfx::Animation.
86 }; 86 };
87 87
88 TEST_VIEW(MediaIndicatorButtonTest, button_) 88 TEST_VIEW(AlertIndicatorButtonTest, button_)
89 89
90 } // namespace 90 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698