| 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" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chromeos/login/login_state.h" | 15 #include "chromeos/login/login_state.h" |
| 15 #include "ui/message_center/message_center.h" | 16 #include "ui/message_center/message_center.h" |
| 16 #include "ui/message_center/notification.h" | 17 #include "ui/message_center/notification.h" |
| 17 | 18 |
| 19 using base::UTF8ToUTF16; |
| 20 |
| 18 class LoginStateNotificationBlockerChromeOSTest | 21 class LoginStateNotificationBlockerChromeOSTest |
| 19 : public ash::test::AshTestBase, | 22 : public ash::test::AshTestBase, |
| 20 public message_center::NotificationBlocker::Observer { | 23 public message_center::NotificationBlocker::Observer { |
| 21 public: | 24 public: |
| 22 LoginStateNotificationBlockerChromeOSTest() | 25 LoginStateNotificationBlockerChromeOSTest() |
| 23 : state_changed_count_(0) {} | 26 : state_changed_count_(0) {} |
| 24 ~LoginStateNotificationBlockerChromeOSTest() override {} | 27 ~LoginStateNotificationBlockerChromeOSTest() override {} |
| 25 | 28 |
| 26 // ash::tests::AshTestBase overrides: | 29 // ash::tests::AshTestBase overrides: |
| 27 void SetUp() override { | 30 void SetUp() override { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 47 } | 50 } |
| 48 | 51 |
| 49 int GetStateChangedCountAndReset() { | 52 int GetStateChangedCountAndReset() { |
| 50 int result = state_changed_count_; | 53 int result = state_changed_count_; |
| 51 state_changed_count_ = 0; | 54 state_changed_count_ = 0; |
| 52 return result; | 55 return result; |
| 53 } | 56 } |
| 54 | 57 |
| 55 bool ShouldShowNotificationAsPopup( | 58 bool ShouldShowNotificationAsPopup( |
| 56 const message_center::NotifierId& notifier_id) { | 59 const message_center::NotifierId& notifier_id) { |
| 57 return blocker_->ShouldShowNotificationAsPopup(notifier_id); | 60 message_center::Notification notification( |
| 61 message_center::NOTIFICATION_TYPE_SIMPLE, "chromeos-id", |
| 62 UTF8ToUTF16("chromeos-title"), UTF8ToUTF16("chromeos-message"), |
| 63 gfx::Image(), UTF8ToUTF16("chromeos-source"), GURL(), |
| 64 notifier_id, message_center::RichNotificationData(), NULL); |
| 65 return blocker_->ShouldShowNotificationAsPopup(notification); |
| 58 } | 66 } |
| 59 | 67 |
| 60 private: | 68 private: |
| 61 int state_changed_count_; | 69 int state_changed_count_; |
| 62 std::unique_ptr<message_center::NotificationBlocker> blocker_; | 70 std::unique_ptr<message_center::NotificationBlocker> blocker_; |
| 63 | 71 |
| 64 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSTest); | 72 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSTest); |
| 65 }; | 73 }; |
| 66 | 74 |
| 67 TEST_F(LoginStateNotificationBlockerChromeOSTest, BaseTest) { | 75 TEST_F(LoginStateNotificationBlockerChromeOSTest, BaseTest) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Lock. | 129 // Lock. |
| 122 ash::Shell::GetInstance()->OnLockStateChanged(true); | 130 ash::Shell::GetInstance()->OnLockStateChanged(true); |
| 123 EXPECT_EQ(1, GetStateChangedCountAndReset()); | 131 EXPECT_EQ(1, GetStateChangedCountAndReset()); |
| 124 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 132 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
| 125 | 133 |
| 126 // Unlock. | 134 // Unlock. |
| 127 ash::Shell::GetInstance()->OnLockStateChanged(false); | 135 ash::Shell::GetInstance()->OnLockStateChanged(false); |
| 128 EXPECT_EQ(1, GetStateChangedCountAndReset()); | 136 EXPECT_EQ(1, GetStateChangedCountAndReset()); |
| 129 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); | 137 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); |
| 130 } | 138 } |
| OLD | NEW |