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

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

Issue 2851593002: Use ScopedTaskEnvironment instead of MessageLoopForUI in chrome tests. (Closed)
Patch Set: self-review Created 3 years, 7 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/alert_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/test/scoped_task_environment.h"
12 #import "chrome/browser/ui/cocoa/test/cocoa_test_helper.h" 12 #import "chrome/browser/ui/cocoa/test/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 AlertIndicatorButtonTestTarget : 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 AlertIndicatorButtonTestTarget 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 AlertIndicatorButtonTest : public CocoaTest { 35 class AlertIndicatorButtonTest : public CocoaTest {
36 public: 36 public:
37 AlertIndicatorButtonTest() { 37 AlertIndicatorButtonTest()
38 : scoped_task_environment_(
39 base::test::ScopedTaskEnvironment::MainThreadType::UI) {
38 base::CommandLine::ForCurrentProcess()->AppendSwitch( 40 base::CommandLine::ForCurrentProcess()->AppendSwitch(
39 std::string("--") + switches::kEnableTabAudioMuting); 41 std::string("--") + switches::kEnableTabAudioMuting);
40 42
41 // Create the AlertIndicatorButton and add it to a view. 43 // Create the AlertIndicatorButton and add it to a view.
42 button_.reset([[AlertIndicatorButton alloc] init]); 44 button_.reset([[AlertIndicatorButton alloc] init]);
43 EXPECT_TRUE(button_ != nil); 45 EXPECT_TRUE(button_ != nil);
44 [[test_window() contentView] addSubview:button_.get()]; 46 [[test_window() contentView] addSubview:button_.get()];
45 47
46 // Initially the button is disabled and showing no indicator. 48 // Initially the button is disabled and showing no indicator.
47 EXPECT_EQ(TabAlertState::NONE, [button_ showingAlertState]); 49 EXPECT_EQ(TabAlertState::NONE, [button_ showingAlertState]);
(...skipping 27 matching lines...) Expand all
75 // should only be drawing the indicator icon (i.e., there is nothing to 77 // should only be drawing the indicator icon (i.e., there is nothing to
76 // mute). A click should NOT result in another click notification. 78 // mute). A click should NOT result in another click notification.
77 [button_ transitionToAlertState:TabAlertState::TAB_CAPTURING]; 79 [button_ transitionToAlertState:TabAlertState::TAB_CAPTURING];
78 EXPECT_EQ(TabAlertState::TAB_CAPTURING, [button_ showingAlertState]); 80 EXPECT_EQ(TabAlertState::TAB_CAPTURING, [button_ showingAlertState]);
79 EXPECT_FALSE([button_ isEnabled]); 81 EXPECT_FALSE([button_ isEnabled]);
80 [button_ performClick:button_]; 82 [button_ performClick:button_];
81 EXPECT_EQ(2, [clickTarget count]); 83 EXPECT_EQ(2, [clickTarget count]);
82 } 84 }
83 85
84 base::scoped_nsobject<AlertIndicatorButton> button_; 86 base::scoped_nsobject<AlertIndicatorButton> button_;
85 base::MessageLoopForUI message_loop_; // Needed for gfx::Animation. 87 base::test::ScopedTaskEnvironment
88 scoped_task_environment_; // Needed for gfx::Animation.
sky 2017/04/27 22:17:46 Move the comment above the member.
fdoray 2017/05/01 17:44:59 Done.
86 }; 89 };
87 90
88 TEST_VIEW(AlertIndicatorButtonTest, button_) 91 TEST_VIEW(AlertIndicatorButtonTest, button_)
89 92
90 } // namespace 93 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698