| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signin/signin_error_notifier_ash.h" | 5 #include "chrome/browser/signin/signin_error_notifier_ash.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "components/signin/core/browser/signin_error_controller.h" | 24 #include "components/signin/core/browser/signin_error_controller.h" |
| 25 #include "components/signin/core/browser/signin_manager.h" | 25 #include "components/signin/core/browser/signin_manager.h" |
| 26 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "ui/message_center/notification.h" | 28 #include "ui/message_center/notification.h" |
| 29 | 29 |
| 30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 31 #include "chrome/browser/ui/ash/ash_util.h" | 31 #include "chrome/browser/ui/ash/ash_util.h" |
| 32 #include "ui/aura/test/test_screen.h" | 32 #include "ui/aura/test/test_screen.h" |
| 33 #include "ui/gfx/screen.h" | 33 #include "ui/gfx/screen.h" |
| 34 #include "ui/gfx/screen_type_delegate.h" | |
| 35 #endif | 34 #endif |
| 36 | 35 |
| 37 namespace ash { | 36 namespace ash { |
| 38 namespace test { | 37 namespace test { |
| 39 | 38 |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 static const char kTestAccountId[] = "testuser@test.com"; | 41 static const char kTestAccountId[] = "testuser@test.com"; |
| 43 | 42 |
| 44 // Notification ID corresponding to kProfileSigninNotificationId + | 43 // Notification ID corresponding to kProfileSigninNotificationId + |
| 45 // kTestAccountId. | 44 // kTestAccountId. |
| 46 static const std::string kNotificationId = | 45 static const std::string kNotificationId = |
| 47 "chrome://settings/signin/testuser@test.com"; | 46 "chrome://settings/signin/testuser@test.com"; |
| 48 } | 47 } |
| 49 | 48 |
| 50 #if defined(OS_WIN) | |
| 51 class ScreenTypeDelegateDesktop : public gfx::ScreenTypeDelegate { | |
| 52 public: | |
| 53 ScreenTypeDelegateDesktop() {} | |
| 54 gfx::ScreenType GetScreenTypeForNativeView(gfx::NativeView view) override { | |
| 55 return chrome::IsNativeViewInAsh(view) ? | |
| 56 gfx::SCREEN_TYPE_ALTERNATE : | |
| 57 gfx::SCREEN_TYPE_NATIVE; | |
| 58 } | |
| 59 private: | |
| 60 DISALLOW_COPY_AND_ASSIGN(ScreenTypeDelegateDesktop); | |
| 61 }; | |
| 62 #endif | |
| 63 | |
| 64 class SigninErrorNotifierTest : public AshTestBase { | 49 class SigninErrorNotifierTest : public AshTestBase { |
| 65 public: | 50 public: |
| 66 void SetUp() override { | 51 void SetUp() override { |
| 67 // Create a signed-in profile. | 52 // Create a signed-in profile. |
| 68 TestingProfile::Builder builder; | 53 TestingProfile::Builder builder; |
| 69 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), | 54 builder.AddTestingFactory(SigninManagerFactory::GetInstance(), |
| 70 BuildFakeSigninManagerBase); | 55 BuildFakeSigninManagerBase); |
| 71 profile_ = builder.Build(); | 56 profile_ = builder.Build(); |
| 72 profile_->set_profile_name(kTestAccountId); | 57 profile_->set_profile_name(kTestAccountId); |
| 73 | 58 |
| 74 profile_manager_.reset( | 59 profile_manager_.reset( |
| 75 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 60 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 76 ASSERT_TRUE(profile_manager_->SetUp()); | 61 ASSERT_TRUE(profile_manager_->SetUp()); |
| 77 | 62 |
| 78 TestingBrowserProcess::GetGlobal(); | 63 TestingBrowserProcess::GetGlobal(); |
| 79 AshTestBase::SetUp(); | 64 AshTestBase::SetUp(); |
| 80 | 65 |
| 81 // Set up screen for Windows. | 66 // Set up screen for Windows. |
| 82 #if defined(OS_WIN) | 67 #if defined(OS_WIN) |
| 83 test_screen_.reset(aura::TestScreen::Create(gfx::Size())); | 68 test_screen_.reset(aura::TestScreen::Create(gfx::Size())); |
| 84 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); | 69 gfx::Screen::SetScreenInstance(test_screen_.get()); |
| 85 gfx::Screen::SetScreenTypeDelegate(&screen_type_delegate_); | |
| 86 #endif | 70 #endif |
| 87 | 71 |
| 88 error_controller_ = SigninErrorControllerFactory::GetForProfile( | 72 error_controller_ = SigninErrorControllerFactory::GetForProfile( |
| 89 profile_.get()); | 73 profile_.get()); |
| 90 SigninErrorNotifierFactory::GetForProfile(profile_.get()); | 74 SigninErrorNotifierFactory::GetForProfile(profile_.get()); |
| 91 notification_ui_manager_ = g_browser_process->notification_ui_manager(); | 75 notification_ui_manager_ = g_browser_process->notification_ui_manager(); |
| 92 } | 76 } |
| 93 | 77 |
| 94 void TearDown() override { | 78 void TearDown() override { |
| 95 #if defined(OS_WIN) | 79 #if defined(OS_WIN) |
| 96 gfx::Screen::SetScreenTypeDelegate(nullptr); | 80 gfx::Screen::SetScreenInstance(nullptr); |
| 97 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, nullptr); | |
| 98 test_screen_.reset(); | 81 test_screen_.reset(); |
| 99 #endif | 82 #endif |
| 100 profile_manager_.reset(); | 83 profile_manager_.reset(); |
| 101 | 84 |
| 102 AshTestBase::TearDown(); | 85 AshTestBase::TearDown(); |
| 103 } | 86 } |
| 104 | 87 |
| 105 protected: | 88 protected: |
| 106 void GetMessage(base::string16* message) { | 89 void GetMessage(base::string16* message) { |
| 107 const Notification* notification = | 90 const Notification* notification = |
| 108 g_browser_process->notification_ui_manager()->FindById( | 91 g_browser_process->notification_ui_manager()->FindById( |
| 109 kNotificationId, | 92 kNotificationId, |
| 110 NotificationUIManager::GetProfileID(profile_.get())); | 93 NotificationUIManager::GetProfileID(profile_.get())); |
| 111 ASSERT_FALSE(notification == NULL); | 94 ASSERT_FALSE(notification == NULL); |
| 112 *message = notification->message(); | 95 *message = notification->message(); |
| 113 } | 96 } |
| 114 | 97 |
| 115 #if defined(OS_WIN) | 98 #if defined(OS_WIN) |
| 116 ScreenTypeDelegateDesktop screen_type_delegate_; | |
| 117 scoped_ptr<gfx::Screen> test_screen_; | 99 scoped_ptr<gfx::Screen> test_screen_; |
| 118 #endif | 100 #endif |
| 119 scoped_ptr<TestingProfileManager> profile_manager_; | 101 scoped_ptr<TestingProfileManager> profile_manager_; |
| 120 scoped_ptr<TestingProfile> profile_; | 102 scoped_ptr<TestingProfile> profile_; |
| 121 SigninErrorController* error_controller_; | 103 SigninErrorController* error_controller_; |
| 122 NotificationUIManager* notification_ui_manager_; | 104 NotificationUIManager* notification_ui_manager_; |
| 123 }; | 105 }; |
| 124 | 106 |
| 125 TEST_F(SigninErrorNotifierTest, NoErrorAuthStatusProviders) { | 107 TEST_F(SigninErrorNotifierTest, NoErrorAuthStatusProviders) { |
| 126 ASSERT_FALSE(notification_ui_manager_->FindById( | 108 ASSERT_FALSE(notification_ui_manager_->FindById( |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 EXPECT_FALSE(notification->title().empty()); | 231 EXPECT_FALSE(notification->title().empty()); |
| 250 EXPECT_FALSE(notification->message().empty()); | 232 EXPECT_FALSE(notification->message().empty()); |
| 251 EXPECT_EQ((size_t)1, notification->buttons().size()); | 233 EXPECT_EQ((size_t)1, notification->buttons().size()); |
| 252 } | 234 } |
| 253 } | 235 } |
| 254 } | 236 } |
| 255 #endif | 237 #endif |
| 256 | 238 |
| 257 } // namespace test | 239 } // namespace test |
| 258 } // namespace ash | 240 } // namespace ash |
| OLD | NEW |