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.
6 #include "ash/system/system_notifier.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/chromeos/login/login_manager_test.h"
9 #include "chrome/browser/chromeos/login/startup_utils.h"
10 #include "chrome/browser/chromeos/login/user_adding_screen.h"
11 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "content/public/test/test_utils.h"
14 #include "ui/message_center/message_center.h"
16 using namespace testing
;
20 const char* kTestUsers
[] = {"test-user@gmail.com",
21 "test-user1@gmail.com"};
23 } // anonymous namespace
25 class LoginStateNotificationBlockerChromeOSBrowserTest
26 : public chromeos::LoginManagerTest
,
27 public message_center::NotificationBlocker::Observer
{
29 LoginStateNotificationBlockerChromeOSBrowserTest()
30 : chromeos::LoginManagerTest(false),
31 state_changed_count_(0) {}
32 virtual ~LoginStateNotificationBlockerChromeOSBrowserTest() {}
34 // InProcessBrowserTest overrides:
35 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
36 LoginManagerTest::SetUpCommandLine(command_line
);
37 command_line
->AppendSwitch(::switches::kMultiProfiles
);
40 virtual void SetUpOnMainThread() OVERRIDE
{
41 chromeos::LoginState::Get()->set_always_logged_in(false);
44 virtual void CleanUpOnMainThread() OVERRIDE
{
46 blocker_
->RemoveObserver(this);
48 chromeos::LoginManagerTest::CleanUpOnMainThread();
52 void CreateBlocker() {
53 blocker_
.reset(new LoginStateNotificationBlockerChromeOS(
54 message_center::MessageCenter::Get()));
55 blocker_
->AddObserver(this);
58 // message_center::NotificationBlocker::Observer ovverrides:
59 virtual void OnBlockingStateChanged(
60 message_center::NotificationBlocker
* blocker
) OVERRIDE
{
61 state_changed_count_
++;
64 int GetStateChangedCountAndReset() {
65 int result
= state_changed_count_
;
66 state_changed_count_
= 0;
70 bool ShouldShowNotificationAsPopup(
71 const message_center::NotifierId
& notifier_id
) {
72 return blocker_
->ShouldShowNotificationAsPopup(notifier_id
);
76 int state_changed_count_
;
77 scoped_ptr
<message_center::NotificationBlocker
> blocker_
;
79 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSBrowserTest
);
82 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest
,
84 RegisterUser(kTestUsers
[0]);
85 RegisterUser(kTestUsers
[1]);
86 chromeos::StartupUtils::MarkOobeCompleted();
89 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest
,
92 message_center::NotifierId
notifier_id(
93 message_center::NotifierId::APPLICATION
, "test-notifier");
95 // Logged in as a normal user.
96 EXPECT_CALL(login_utils(), DoBrowserLaunch(_
, _
)).Times(1);
97 LoginUser(kTestUsers
[0]);
98 EXPECT_EQ(1, GetStateChangedCountAndReset());
99 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id
));
101 // Multi-login user switch.
102 chromeos::UserAddingScreen::Get()->Start();
103 content::RunAllPendingInMessageLoop();
104 EXPECT_EQ(1, GetStateChangedCountAndReset());
105 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id
));
107 // Multi-login user switch off.
108 chromeos::UserAddingScreen::Get()->Cancel();
109 content::RunAllPendingInMessageLoop();
110 EXPECT_EQ(1, GetStateChangedCountAndReset());
111 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id
));
114 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest
,
115 PRE_AlwaysAllowedNotifier
) {
116 RegisterUser(kTestUsers
[0]);
117 RegisterUser(kTestUsers
[1]);
118 chromeos::StartupUtils::MarkOobeCompleted();
121 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest
,
122 AlwaysAllowedNotifier
) {
125 // NOTIFIER_DISPLAY is allowed to shown in the login screen.
126 message_center::NotifierId
notifier_id(
127 message_center::NotifierId::SYSTEM_COMPONENT
,
128 ash::system_notifier::kNotifierDisplay
);
130 // Logged in as a normal user.
131 EXPECT_CALL(login_utils(), DoBrowserLaunch(_
, _
)).Times(1);
132 LoginUser(kTestUsers
[0]);
133 EXPECT_EQ(1, GetStateChangedCountAndReset());
134 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id
));
136 // Multi-login user switch.
137 chromeos::UserAddingScreen::Get()->Start();
138 content::RunAllPendingInMessageLoop();
139 EXPECT_EQ(1, GetStateChangedCountAndReset());
140 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id
));
142 // Multi-login user switch off.
143 chromeos::UserAddingScreen::Get()->Cancel();
144 content::RunAllPendingInMessageLoop();
145 EXPECT_EQ(1, GetStateChangedCountAndReset());
146 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id
));