OLD | NEW |
---|---|
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 "chrome/browser/notifications/login_state_notification_blocker_chromeos .h" | 5 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos .h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/common/system/system_notifier.h" | 9 #include "ash/common/system/system_notifier.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 bool ShouldShowNotificationAsPopup( | 58 bool ShouldShowNotificationAsPopup( |
59 const message_center::NotifierId& notifier_id) { | 59 const message_center::NotifierId& notifier_id) { |
60 message_center::Notification notification( | 60 message_center::Notification notification( |
61 message_center::NOTIFICATION_TYPE_SIMPLE, "chromeos-id", | 61 message_center::NOTIFICATION_TYPE_SIMPLE, "chromeos-id", |
62 UTF8ToUTF16("chromeos-title"), UTF8ToUTF16("chromeos-message"), | 62 UTF8ToUTF16("chromeos-title"), UTF8ToUTF16("chromeos-message"), |
63 gfx::Image(), UTF8ToUTF16("chromeos-source"), GURL(), | 63 gfx::Image(), UTF8ToUTF16("chromeos-source"), GURL(), |
64 notifier_id, message_center::RichNotificationData(), NULL); | 64 notifier_id, message_center::RichNotificationData(), NULL); |
65 return blocker_->ShouldShowNotificationAsPopup(notification); | 65 return blocker_->ShouldShowNotificationAsPopup(notification); |
66 } | 66 } |
67 | 67 |
68 void SetLockedState(bool locked) { | |
69 // TODO(xiyuan): Use SessionManager and not call ash. | |
70 static_cast<ash::SessionStateObserver*>(ash::Shell::Get()) | |
stevenjb
2017/04/10 15:52:44
Why do we need the static_cast here?
xiyuan
2017/04/10 16:09:53
It is because LockStateChanged is now part of Sess
| |
71 ->LockStateChanged(locked); | |
72 } | |
73 | |
68 private: | 74 private: |
69 int state_changed_count_; | 75 int state_changed_count_; |
70 std::unique_ptr<message_center::NotificationBlocker> blocker_; | 76 std::unique_ptr<message_center::NotificationBlocker> blocker_; |
71 | 77 |
72 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSTest); | 78 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSTest); |
73 }; | 79 }; |
74 | 80 |
75 TEST_F(LoginStateNotificationBlockerChromeOSTest, BaseTest) { | 81 TEST_F(LoginStateNotificationBlockerChromeOSTest, BaseTest) { |
76 // Default status: OOBE. | 82 // Default status: OOBE. |
77 message_center::NotifierId notifier_id( | 83 message_center::NotifierId notifier_id( |
78 message_center::NotifierId::APPLICATION, "test-notifier"); | 84 message_center::NotifierId::APPLICATION, "test-notifier"); |
79 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id)); | 85 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id)); |
80 | 86 |
81 // Login screen. | 87 // Login screen. |
82 chromeos::LoginState::Get()->SetLoggedInState( | 88 chromeos::LoginState::Get()->SetLoggedInState( |
83 chromeos::LoginState::LOGGED_IN_NONE, | 89 chromeos::LoginState::LOGGED_IN_NONE, |
84 chromeos::LoginState::LOGGED_IN_USER_NONE); | 90 chromeos::LoginState::LOGGED_IN_USER_NONE); |
85 EXPECT_EQ(0, GetStateChangedCountAndReset()); | 91 EXPECT_EQ(0, GetStateChangedCountAndReset()); |
86 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id)); | 92 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id)); |
87 | 93 |
88 // Logged in as a normal user. | 94 // Logged in as a normal user. |
89 chromeos::LoginState::Get()->SetLoggedInState( | 95 chromeos::LoginState::Get()->SetLoggedInState( |
90 chromeos::LoginState::LOGGED_IN_ACTIVE, | 96 chromeos::LoginState::LOGGED_IN_ACTIVE, |
91 chromeos::LoginState::LOGGED_IN_USER_REGULAR); | 97 chromeos::LoginState::LOGGED_IN_USER_REGULAR); |
92 EXPECT_EQ(1, GetStateChangedCountAndReset()); | 98 EXPECT_EQ(1, GetStateChangedCountAndReset()); |
93 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 99 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
94 | 100 |
95 // Lock. | 101 // Lock. |
96 ash::Shell::Get()->OnLockStateChanged(true); | 102 SetLockedState(true); |
97 EXPECT_EQ(1, GetStateChangedCountAndReset()); | 103 EXPECT_EQ(1, GetStateChangedCountAndReset()); |
98 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id)); | 104 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id)); |
99 | 105 |
100 // Unlock. | 106 // Unlock. |
101 ash::Shell::Get()->OnLockStateChanged(false); | 107 SetLockedState(false); |
102 EXPECT_EQ(1, GetStateChangedCountAndReset()); | 108 EXPECT_EQ(1, GetStateChangedCountAndReset()); |
103 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 109 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
104 } | 110 } |
105 | 111 |
106 TEST_F(LoginStateNotificationBlockerChromeOSTest, AlwaysAllowedNotifier) { | 112 TEST_F(LoginStateNotificationBlockerChromeOSTest, AlwaysAllowedNotifier) { |
107 // NOTIFIER_DISPLAY is allowed to shown in the login screen. | 113 // NOTIFIER_DISPLAY is allowed to shown in the login screen. |
108 message_center::NotifierId notifier_id( | 114 message_center::NotifierId notifier_id( |
109 message_center::NotifierId::SYSTEM_COMPONENT, | 115 message_center::NotifierId::SYSTEM_COMPONENT, |
110 ash::system_notifier::kNotifierDisplay); | 116 ash::system_notifier::kNotifierDisplay); |
111 | 117 |
112 // Default status: OOBE. | 118 // Default status: OOBE. |
113 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 119 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
114 | 120 |
115 // Login screen. | 121 // Login screen. |
116 chromeos::LoginState::Get()->SetLoggedInState( | 122 chromeos::LoginState::Get()->SetLoggedInState( |
117 chromeos::LoginState::LOGGED_IN_NONE, | 123 chromeos::LoginState::LOGGED_IN_NONE, |
118 chromeos::LoginState::LOGGED_IN_USER_NONE); | 124 chromeos::LoginState::LOGGED_IN_USER_NONE); |
119 EXPECT_EQ(0, GetStateChangedCountAndReset()); | 125 EXPECT_EQ(0, GetStateChangedCountAndReset()); |
120 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 126 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
121 | 127 |
122 // Logged in as a normal user. | 128 // Logged in as a normal user. |
123 chromeos::LoginState::Get()->SetLoggedInState( | 129 chromeos::LoginState::Get()->SetLoggedInState( |
124 chromeos::LoginState::LOGGED_IN_ACTIVE, | 130 chromeos::LoginState::LOGGED_IN_ACTIVE, |
125 chromeos::LoginState::LOGGED_IN_USER_REGULAR); | 131 chromeos::LoginState::LOGGED_IN_USER_REGULAR); |
126 EXPECT_EQ(1, GetStateChangedCountAndReset()); | 132 EXPECT_EQ(1, GetStateChangedCountAndReset()); |
127 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 133 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
128 | 134 |
129 // Lock. | 135 // Lock. |
130 ash::Shell::Get()->OnLockStateChanged(true); | 136 SetLockedState(true); |
131 EXPECT_EQ(1, GetStateChangedCountAndReset()); | 137 EXPECT_EQ(1, GetStateChangedCountAndReset()); |
132 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 138 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
133 | 139 |
134 // Unlock. | 140 // Unlock. |
135 ash::Shell::Get()->OnLockStateChanged(false); | 141 SetLockedState(false); |
136 EXPECT_EQ(1, GetStateChangedCountAndReset()); | 142 EXPECT_EQ(1, GetStateChangedCountAndReset()); |
137 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 143 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
138 } | 144 } |
OLD | NEW |