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

Side by Side Diff: chrome/browser/notifications/login_state_notification_blocker_chromeos_browsertest.cc

Issue 270563002: Componentize LoginManagerTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 #include "ash/shell.h" 5 #include "ash/shell.h"
6 #include "ash/system/system_notifier.h" 6 #include "ash/system/system_notifier.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/chromeos/login/login_manager_test.h" 8 #include "chrome/browser/chromeos/login/login_manager_test_helper.h"
9 #include "chrome/browser/chromeos/login/startup_utils.h" 9 #include "chrome/browser/chromeos/login/startup_utils.h"
10 #include "chrome/browser/chromeos/login/user_adding_screen.h" 10 #include "chrome/browser/chromeos/login/user_adding_screen.h"
11 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h" 11 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/test/base/in_process_browser_test.h"
13 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
14 #include "ui/message_center/message_center.h" 15 #include "ui/message_center/message_center.h"
15 16
16 using namespace testing; 17 using namespace testing;
17 18
18 namespace { 19 namespace {
19 20
20 const char* kTestUsers[] = {"test-user@gmail.com", 21 const char* kTestUsers[] = {"test-user@gmail.com",
21 "test-user1@gmail.com"}; 22 "test-user1@gmail.com"};
22 23
23 } // anonymous namespace 24 } // anonymous namespace
24 25
25 class LoginStateNotificationBlockerChromeOSBrowserTest 26 class LoginStateNotificationBlockerChromeOSBrowserTest
26 : public chromeos::LoginManagerTest, 27 : public InProcessBrowserTest,
27 public message_center::NotificationBlocker::Observer { 28 public message_center::NotificationBlocker::Observer {
28 public: 29 public:
29 LoginStateNotificationBlockerChromeOSBrowserTest() 30 LoginStateNotificationBlockerChromeOSBrowserTest()
30 : chromeos::LoginManagerTest(false), 31 : login_manager_test_helper_(new chromeos::LoginManagerTestHelper(false)),
31 state_changed_count_(0) {} 32 state_changed_count_(0) {
33 set_exit_when_last_browser_closes(false);
34 }
35
32 virtual ~LoginStateNotificationBlockerChromeOSBrowserTest() {} 36 virtual ~LoginStateNotificationBlockerChromeOSBrowserTest() {}
33 37
34 // InProcessBrowserTest overrides: 38 // InProcessBrowserTest overrides:
35 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 39 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
36 LoginManagerTest::SetUpCommandLine(command_line); 40 login_manager_test_helper_->SetUpCommandLine(command_line);
37 command_line->AppendSwitch(::switches::kMultiProfiles); 41 command_line->AppendSwitch(::switches::kMultiProfiles);
38 } 42 }
39 43
40 virtual void SetUpOnMainThread() OVERRIDE { 44 virtual void SetUpOnMainThread() OVERRIDE {
michaelpg 2014/05/07 00:55:05 this doesn't call LoginManagerTestSetUpOnMainThrea
Jun Mukai 2014/05/07 01:01:41 Probably. I didn't noticed this missing. Thanks fo
41 chromeos::LoginState::Get()->set_always_logged_in(false); 45 chromeos::LoginState::Get()->set_always_logged_in(false);
42 } 46 }
43 47
48 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
49 login_manager_test_helper_->SetUpLoginUtils();
50 }
51
44 virtual void CleanUpOnMainThread() OVERRIDE { 52 virtual void CleanUpOnMainThread() OVERRIDE {
45 if (blocker_) 53 if (blocker_)
46 blocker_->RemoveObserver(this); 54 blocker_->RemoveObserver(this);
47 blocker_.reset(); 55 blocker_.reset();
48 chromeos::LoginManagerTest::CleanUpOnMainThread(); 56 login_manager_test_helper_->CleanUp();
49 } 57 }
50 58
51 protected: 59 protected:
52 void CreateBlocker() { 60 void CreateBlocker() {
53 blocker_.reset(new LoginStateNotificationBlockerChromeOS( 61 blocker_.reset(new LoginStateNotificationBlockerChromeOS(
54 message_center::MessageCenter::Get())); 62 message_center::MessageCenter::Get()));
55 blocker_->AddObserver(this); 63 blocker_->AddObserver(this);
56 } 64 }
57 65
58 // message_center::NotificationBlocker::Observer ovverrides: 66 // message_center::NotificationBlocker::Observer ovverrides:
59 virtual void OnBlockingStateChanged( 67 virtual void OnBlockingStateChanged(
60 message_center::NotificationBlocker* blocker) OVERRIDE { 68 message_center::NotificationBlocker* blocker) OVERRIDE {
61 state_changed_count_++; 69 state_changed_count_++;
62 } 70 }
63 71
64 int GetStateChangedCountAndReset() { 72 int GetStateChangedCountAndReset() {
65 int result = state_changed_count_; 73 int result = state_changed_count_;
66 state_changed_count_ = 0; 74 state_changed_count_ = 0;
67 return result; 75 return result;
68 } 76 }
69 77
70 bool ShouldShowNotificationAsPopup( 78 bool ShouldShowNotificationAsPopup(
71 const message_center::NotifierId& notifier_id) { 79 const message_center::NotifierId& notifier_id) {
72 return blocker_->ShouldShowNotificationAsPopup(notifier_id); 80 return blocker_->ShouldShowNotificationAsPopup(notifier_id);
73 } 81 }
74 82
83 protected:
84 scoped_ptr<chromeos::LoginManagerTestHelper> login_manager_test_helper_;
85
75 private: 86 private:
76 int state_changed_count_; 87 int state_changed_count_;
77 scoped_ptr<message_center::NotificationBlocker> blocker_; 88 scoped_ptr<message_center::NotificationBlocker> blocker_;
78 89
79 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSBrowserTest); 90 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSBrowserTest);
80 }; 91 };
81 92
82 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, 93 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
83 PRE_BaseTest) { 94 PRE_BaseTest) {
84 RegisterUser(kTestUsers[0]); 95 login_manager_test_helper_->RegisterUser(kTestUsers[0]);
85 RegisterUser(kTestUsers[1]); 96 login_manager_test_helper_->RegisterUser(kTestUsers[1]);
86 chromeos::StartupUtils::MarkOobeCompleted(); 97 chromeos::StartupUtils::MarkOobeCompleted();
87 } 98 }
88 99
89 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, 100 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
90 BaseTest) { 101 BaseTest) {
91 CreateBlocker(); 102 CreateBlocker();
92 message_center::NotifierId notifier_id( 103 message_center::NotifierId notifier_id(
93 message_center::NotifierId::APPLICATION, "test-notifier"); 104 message_center::NotifierId::APPLICATION, "test-notifier");
94 105
95 // Logged in as a normal user. 106 // Logged in as a normal user.
96 EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1); 107 EXPECT_CALL(login_manager_test_helper_->login_utils(),
97 LoginUser(kTestUsers[0]); 108 DoBrowserLaunch(_, _)).Times(1);
109 login_manager_test_helper_->LogInUser(kTestUsers[0]);
98 EXPECT_EQ(1, GetStateChangedCountAndReset()); 110 EXPECT_EQ(1, GetStateChangedCountAndReset());
99 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 111 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
100 112
101 // Multi-login user switch. 113 // Multi-login user switch.
102 chromeos::UserAddingScreen::Get()->Start(); 114 chromeos::UserAddingScreen::Get()->Start();
103 content::RunAllPendingInMessageLoop(); 115 content::RunAllPendingInMessageLoop();
104 EXPECT_EQ(1, GetStateChangedCountAndReset()); 116 EXPECT_EQ(1, GetStateChangedCountAndReset());
105 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id)); 117 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id));
106 118
107 // Multi-login user switch off. 119 // Multi-login user switch off.
108 chromeos::UserAddingScreen::Get()->Cancel(); 120 chromeos::UserAddingScreen::Get()->Cancel();
109 content::RunAllPendingInMessageLoop(); 121 content::RunAllPendingInMessageLoop();
110 EXPECT_EQ(1, GetStateChangedCountAndReset()); 122 EXPECT_EQ(1, GetStateChangedCountAndReset());
111 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 123 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
112 } 124 }
113 125
114 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, 126 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
115 PRE_AlwaysAllowedNotifier) { 127 PRE_AlwaysAllowedNotifier) {
116 RegisterUser(kTestUsers[0]); 128 login_manager_test_helper_->RegisterUser(kTestUsers[0]);
117 RegisterUser(kTestUsers[1]); 129 login_manager_test_helper_->RegisterUser(kTestUsers[1]);
118 chromeos::StartupUtils::MarkOobeCompleted(); 130 chromeos::StartupUtils::MarkOobeCompleted();
119 } 131 }
120 132
121 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, 133 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
122 AlwaysAllowedNotifier) { 134 AlwaysAllowedNotifier) {
123 CreateBlocker(); 135 CreateBlocker();
124 136
125 // NOTIFIER_DISPLAY is allowed to shown in the login screen. 137 // NOTIFIER_DISPLAY is allowed to shown in the login screen.
126 message_center::NotifierId notifier_id( 138 message_center::NotifierId notifier_id(
127 message_center::NotifierId::SYSTEM_COMPONENT, 139 message_center::NotifierId::SYSTEM_COMPONENT,
128 ash::system_notifier::kNotifierDisplay); 140 ash::system_notifier::kNotifierDisplay);
129 141
130 // Logged in as a normal user. 142 // Logged in as a normal user.
131 EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1); 143 EXPECT_CALL(login_manager_test_helper_->login_utils(),
132 LoginUser(kTestUsers[0]); 144 DoBrowserLaunch(_, _)).Times(1);
145 login_manager_test_helper_->LogInUser(kTestUsers[0]);
133 EXPECT_EQ(1, GetStateChangedCountAndReset()); 146 EXPECT_EQ(1, GetStateChangedCountAndReset());
134 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 147 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
135 148
136 // Multi-login user switch. 149 // Multi-login user switch.
137 chromeos::UserAddingScreen::Get()->Start(); 150 chromeos::UserAddingScreen::Get()->Start();
138 content::RunAllPendingInMessageLoop(); 151 content::RunAllPendingInMessageLoop();
139 EXPECT_EQ(1, GetStateChangedCountAndReset()); 152 EXPECT_EQ(1, GetStateChangedCountAndReset());
140 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 153 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
141 154
142 // Multi-login user switch off. 155 // Multi-login user switch off.
143 chromeos::UserAddingScreen::Get()->Cancel(); 156 chromeos::UserAddingScreen::Get()->Cancel();
144 content::RunAllPendingInMessageLoop(); 157 content::RunAllPendingInMessageLoop();
145 EXPECT_EQ(1, GetStateChangedCountAndReset()); 158 EXPECT_EQ(1, GetStateChangedCountAndReset());
146 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); 159 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
147 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698