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

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

Issue 688523002: [Cocoa] Tab audio mute control, behind a switch (off by default). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Prevent TabStripController from unconditionally causing creation of MediaIndicatorButton. Created 6 years, 1 month 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_view.h" 5 #import "chrome/browser/ui/cocoa/tabs/media_indicator_button.h"
6 6
7 #include <string>
8
9 #include "base/command_line.h"
7 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
8 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
9 #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"
10 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
11 #include "testing/platform_test.h" 15 #include "testing/platform_test.h"
12 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
13 namespace { 33 namespace {
14 34
15 class MediaIndicatorViewTest : public CocoaTest { 35 class MediaIndicatorButtonTest : public CocoaTest {
16 public: 36 public:
17 MediaIndicatorViewTest() { 37 MediaIndicatorButtonTest() {
18 view_.reset([[MediaIndicatorView alloc] init]); 38 base::CommandLine::ForCurrentProcess()->AppendSwitch(
19 EXPECT_TRUE(view_ != nil); 39 std::string("--") + switches::kEnableTabAudioMuting);
20 EXPECT_EQ(TAB_MEDIA_STATE_NONE, [view_ animatingMediaState]);
21 40
22 [[test_window() contentView] addSubview:view_.get()]; 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()];
23 45
24 [view_ updateIndicator:TAB_MEDIA_STATE_AUDIO_PLAYING]; 46 // Initially the button is disabled and showing no indicator.
25 EXPECT_EQ(TAB_MEDIA_STATE_AUDIO_PLAYING, [view_ animatingMediaState]); 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]);
26 } 82 }
27 83
28 base::scoped_nsobject<MediaIndicatorView> view_; 84 base::scoped_nsobject<MediaIndicatorButton> button_;
29 base::MessageLoopForUI message_loop_; // Needed for gfx::Animation. 85 base::MessageLoopForUI message_loop_; // Needed for gfx::Animation.
30 }; 86 };
31 87
32 TEST_VIEW(MediaIndicatorViewTest, view_) 88 TEST_VIEW(MediaIndicatorButtonTest, button_)
33 89
34 } // namespace 90 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698