| 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/sync/sync_error_notifier_ash.h" | 5 #include "chrome/browser/sync/sync_error_notifier_ash.h" |
| 6 | 6 |
| 7 #include "ash/test/ash_test_base.h" | 7 #include "ash/test/ash_test_base.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
| 11 #include "chrome/browser/notifications/notification_ui_manager.h" | 11 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 12 #include "chrome/browser/sync/profile_sync_service_mock.h" | 12 #include "chrome/browser/sync/profile_sync_service_mock.h" |
| 13 #include "chrome/browser/sync/sync_error_controller.h" | 13 #include "chrome/browser/sync/sync_error_controller.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 15 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 20 #include "chrome/test/base/testing_profile_manager.h" | 20 #include "chrome/test/base/testing_profile_manager.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/message_center/notification.h" | 23 #include "ui/message_center/notification.h" |
| 24 | 24 |
| 25 #if !defined(OS_CHROMEOS) | 25 #if defined(OS_WIN) |
| 26 #include "chrome/browser/ui/ash/ash_util.h" | 26 #include "chrome/browser/ui/ash/ash_util.h" |
| 27 #include "ui/aura/test/test_screen.h" | 27 #include "ui/aura/test/test_screen.h" |
| 28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
| 29 #include "ui/gfx/screen_type_delegate.h" | 29 #include "ui/gfx/screen_type_delegate.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 using ::testing::NiceMock; | 32 using ::testing::NiceMock; |
| 33 using ::testing::Return; | 33 using ::testing::Return; |
| 34 using ::testing::ReturnRef; | 34 using ::testing::ReturnRef; |
| 35 using ::testing::_; | 35 using ::testing::_; |
| 36 | 36 |
| 37 namespace ash { | 37 namespace ash { |
| 38 namespace test { | 38 namespace test { |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 static const char kTestAccountId[] = "testuser@test.com"; | 42 static const char kTestAccountId[] = "testuser@test.com"; |
| 43 | 43 |
| 44 // Notification ID corresponding to kProfileSyncNotificationId + kTestAccountId. | 44 // Notification ID corresponding to kProfileSyncNotificationId + kTestAccountId. |
| 45 static const std::string kNotificationId = | 45 static const std::string kNotificationId = |
| 46 "chrome://settings/sync/testuser@test.com"; | 46 "chrome://settings/sync/testuser@test.com"; |
| 47 | 47 |
| 48 #if !defined(OS_CHROMEOS) | 48 #if defined(OS_WIN) |
| 49 class ScreenTypeDelegateDesktop : public gfx::ScreenTypeDelegate { | 49 class ScreenTypeDelegateDesktop : public gfx::ScreenTypeDelegate { |
| 50 public: | 50 public: |
| 51 ScreenTypeDelegateDesktop() {} | 51 ScreenTypeDelegateDesktop() {} |
| 52 virtual ~ScreenTypeDelegateDesktop() {} | 52 virtual ~ScreenTypeDelegateDesktop() {} |
| 53 virtual gfx::ScreenType GetScreenTypeForNativeView( | 53 virtual gfx::ScreenType GetScreenTypeForNativeView( |
| 54 gfx::NativeView view) OVERRIDE { | 54 gfx::NativeView view) OVERRIDE { |
| 55 return chrome::IsNativeViewInAsh(view) ? | 55 return chrome::IsNativeViewInAsh(view) ? |
| 56 gfx::SCREEN_TYPE_ALTERNATE : | 56 gfx::SCREEN_TYPE_ALTERNATE : |
| 57 gfx::SCREEN_TYPE_NATIVE; | 57 gfx::SCREEN_TYPE_NATIVE; |
| 58 } | 58 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 ASSERT_TRUE(profile_manager_->SetUp()); | 102 ASSERT_TRUE(profile_manager_->SetUp()); |
| 103 | 103 |
| 104 profile_ = profile_manager_->CreateTestingProfile(kTestAccountId); | 104 profile_ = profile_manager_->CreateTestingProfile(kTestAccountId); |
| 105 | 105 |
| 106 TestingBrowserProcess::GetGlobal(); | 106 TestingBrowserProcess::GetGlobal(); |
| 107 AshTestBase::SetUp(); | 107 AshTestBase::SetUp(); |
| 108 | 108 |
| 109 // Set up a desktop screen for Windows to hold native widgets, used when | 109 // Set up a desktop screen for Windows to hold native widgets, used when |
| 110 // adding desktop widgets (i.e., message center notifications). | 110 // adding desktop widgets (i.e., message center notifications). |
| 111 #if defined(OS_WIN) | 111 #if defined(OS_WIN) |
| 112 aura::TestScreen* test_screen = aura::TestScreen::Create(gfx::Size()); | 112 test_screen_.reset(aura::TestScreen::Create(gfx::Size())); |
| 113 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen); | 113 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); |
| 114 gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateDesktop); | 114 gfx::Screen::SetScreenTypeDelegate(new ScreenTypeDelegateDesktop); |
| 115 #endif | 115 #endif |
| 116 | 116 |
| 117 service_.reset(new NiceMock<ProfileSyncServiceMock>(profile_)); | 117 service_.reset(new NiceMock<ProfileSyncServiceMock>(profile_)); |
| 118 | 118 |
| 119 FakeLoginUIService* login_ui_service = static_cast<FakeLoginUIService*>( | 119 FakeLoginUIService* login_ui_service = static_cast<FakeLoginUIService*>( |
| 120 LoginUIServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 120 LoginUIServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 121 profile_, BuildMockLoginUIService)); | 121 profile_, BuildMockLoginUIService)); |
| 122 login_ui_service->SetLoginUI(&login_ui_); | 122 login_ui_service->SetLoginUI(&login_ui_); |
| 123 | 123 |
| 124 error_controller_.reset(new SyncErrorController(service_.get())); | 124 error_controller_.reset(new SyncErrorController(service_.get())); |
| 125 error_notifier_.reset(new SyncErrorNotifier(error_controller_.get(), | 125 error_notifier_.reset(new SyncErrorNotifier(error_controller_.get(), |
| 126 profile_)); | 126 profile_)); |
| 127 | 127 |
| 128 notification_ui_manager_ = g_browser_process->notification_ui_manager(); | 128 notification_ui_manager_ = g_browser_process->notification_ui_manager(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 virtual void TearDown() OVERRIDE { | 131 virtual void TearDown() OVERRIDE { |
| 132 error_notifier_->Shutdown(); | 132 error_notifier_->Shutdown(); |
| 133 service_.reset(); | 133 service_.reset(); |
| 134 #if defined(OS_WIN) |
| 135 test_screen_.reset(); |
| 136 #endif |
| 134 profile_manager_.reset(); | 137 profile_manager_.reset(); |
| 135 | 138 |
| 136 AshTestBase::TearDown(); | 139 AshTestBase::TearDown(); |
| 137 } | 140 } |
| 138 | 141 |
| 139 protected: | 142 protected: |
| 140 // Utility function to test that SyncErrorNotifier behaves correctly for the | 143 // Utility function to test that SyncErrorNotifier behaves correctly for the |
| 141 // given error condition. | 144 // given error condition. |
| 142 void VerifySyncErrorNotifierResult(GoogleServiceAuthError::State error_state, | 145 void VerifySyncErrorNotifierResult(GoogleServiceAuthError::State error_state, |
| 143 bool is_signed_in, | 146 bool is_signed_in, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 158 if (is_error) { | 161 if (is_error) { |
| 159 ASSERT_TRUE(notification); | 162 ASSERT_TRUE(notification); |
| 160 ASSERT_FALSE(notification->title().empty()); | 163 ASSERT_FALSE(notification->title().empty()); |
| 161 ASSERT_FALSE(notification->title().empty()); | 164 ASSERT_FALSE(notification->title().empty()); |
| 162 ASSERT_EQ((size_t)1, notification->buttons().size()); | 165 ASSERT_EQ((size_t)1, notification->buttons().size()); |
| 163 } else { | 166 } else { |
| 164 ASSERT_FALSE(notification); | 167 ASSERT_FALSE(notification); |
| 165 } | 168 } |
| 166 } | 169 } |
| 167 | 170 |
| 171 #if defined(OS_WIN) |
| 172 scoped_ptr<gfx::Screen> test_screen_; |
| 173 #endif |
| 168 scoped_ptr<TestingProfileManager> profile_manager_; | 174 scoped_ptr<TestingProfileManager> profile_manager_; |
| 169 scoped_ptr<SyncErrorController> error_controller_; | 175 scoped_ptr<SyncErrorController> error_controller_; |
| 170 scoped_ptr<SyncErrorNotifier> error_notifier_; | 176 scoped_ptr<SyncErrorNotifier> error_notifier_; |
| 171 scoped_ptr<NiceMock<ProfileSyncServiceMock> > service_; | 177 scoped_ptr<NiceMock<ProfileSyncServiceMock> > service_; |
| 172 TestingProfile* profile_; | 178 TestingProfile* profile_; |
| 173 FakeLoginUI login_ui_; | 179 FakeLoginUI login_ui_; |
| 174 NotificationUIManager* notification_ui_manager_; | 180 NotificationUIManager* notification_ui_manager_; |
| 175 | 181 |
| 176 DISALLOW_COPY_AND_ASSIGN(SyncErrorNotifierTest); | 182 DISALLOW_COPY_AND_ASSIGN(SyncErrorNotifierTest); |
| 177 }; | 183 }; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 SCOPED_TRACE("Not expecting notification since sync setup is incomplete"); | 231 SCOPED_TRACE("Not expecting notification since sync setup is incomplete"); |
| 226 VerifySyncErrorNotifierResult( | 232 VerifySyncErrorNotifierResult( |
| 227 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, | 233 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS, |
| 228 false /* not signed in */, | 234 false /* not signed in */, |
| 229 false /* no error */); | 235 false /* no error */); |
| 230 } | 236 } |
| 231 } | 237 } |
| 232 | 238 |
| 233 } // namespace test | 239 } // namespace test |
| 234 } // namespace ash | 240 } // namespace ash |
| OLD | NEW |