Commit bde44090 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Update more tests to use NotificationDisplayServiceTester. (try 2)

For the changes to FileManagerBrowserTestBase, you can run affected
tests with --gtest_filter=DriveSpecific*

This is identical to 2a3c7c84 but should work now after the fix
which landed as 7a379f73

Bug: 783018
Change-Id: Ie77f44e2e7a5af15e24e630c412bebe5788cb5a0
Reviewed-on: https://chromium-review.googlesource.com/881681Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532050}
parent 0c8f45aa
...@@ -11,10 +11,8 @@ ...@@ -11,10 +11,8 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h" #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
#include "chrome/browser/chromeos/login/users/mock_user_manager.h" #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
#include "chrome/browser/notifications/notification_test_util.h" #include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_auth_policy_client.h" #include "chromeos/dbus/fake_auth_policy_client.h"
...@@ -52,15 +50,14 @@ class AuthPolicyCredentialsManagerTest : public testing::Test { ...@@ -52,15 +50,14 @@ class AuthPolicyCredentialsManagerTest : public testing::Test {
chromeos::NetworkHandler::Initialize(); chromeos::NetworkHandler::Initialize();
fake_auth_policy_client()->DisableOperationDelayForTesting(); fake_auth_policy_client()->DisableOperationDelayForTesting();
TestingBrowserProcess::GetGlobal()->SetNotificationUIManager(
std::make_unique<StubNotificationUIManager>());
TestingProfile::Builder profile_builder; TestingProfile::Builder profile_builder;
profile_builder.SetProfileName("user@gmail.com"); profile_builder.SetProfileName("user@gmail.com");
profile_ = profile_builder.Build(); profile_ = profile_builder.Build();
account_id_ = AccountId::AdFromUserEmailObjGuid( account_id_ = AccountId::AdFromUserEmailObjGuid(
profile()->GetProfileUserName(), "1234567890"); profile()->GetProfileUserName(), "1234567890");
mock_user_manager()->AddUser(account_id_); mock_user_manager()->AddUser(account_id_);
display_service_ =
std::make_unique<NotificationDisplayServiceTester>(profile());
base::RunLoop run_loop; base::RunLoop run_loop;
fake_auth_policy_client()->set_on_get_status_closure( fake_auth_policy_client()->set_on_get_status_closure(
...@@ -99,19 +96,18 @@ class AuthPolicyCredentialsManagerTest : public testing::Test { ...@@ -99,19 +96,18 @@ class AuthPolicyCredentialsManagerTest : public testing::Test {
} }
int GetNumberOfNotifications() { int GetNumberOfNotifications() {
return TestingBrowserProcess::GetGlobal() return display_service_
->notification_ui_manager() ->GetDisplayedNotificationsForType(NotificationHandler::Type::TRANSIENT)
->GetAllIdsByProfile(profile())
.size(); .size();
} }
bool CancelNotificationById(int message_id) { void CancelNotificationById(int message_id) {
const std::string notification_id = kProfileSigninNotificationId + const std::string notification_id = kProfileSigninNotificationId +
profile()->GetProfileUserName() + profile()->GetProfileUserName() +
std::to_string(message_id); std::to_string(message_id);
return TestingBrowserProcess::GetGlobal() EXPECT_TRUE(display_service_->GetNotification(notification_id));
->notification_ui_manager() display_service_->RemoveNotification(NotificationHandler::Type::TRANSIENT,
->CancelById(notification_id, profile()); notification_id, false);
} }
void CallGetUserStatusAndWait() { void CallGetUserStatusAndWait() {
...@@ -123,7 +119,6 @@ class AuthPolicyCredentialsManagerTest : public testing::Test { ...@@ -123,7 +119,6 @@ class AuthPolicyCredentialsManagerTest : public testing::Test {
testing::Mock::VerifyAndClearExpectations(mock_user_manager()); testing::Mock::VerifyAndClearExpectations(mock_user_manager());
} }
private:
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
AccountId account_id_; AccountId account_id_;
std::unique_ptr<TestingProfile> profile_; std::unique_ptr<TestingProfile> profile_;
...@@ -132,6 +127,9 @@ class AuthPolicyCredentialsManagerTest : public testing::Test { ...@@ -132,6 +127,9 @@ class AuthPolicyCredentialsManagerTest : public testing::Test {
AuthPolicyCredentialsManager* auth_policy_credentials_manager_; AuthPolicyCredentialsManager* auth_policy_credentials_manager_;
user_manager::ScopedUserManager user_manager_enabler_; user_manager::ScopedUserManager user_manager_enabler_;
std::unique_ptr<NotificationDisplayServiceTester> display_service_;
private:
DISALLOW_COPY_AND_ASSIGN(AuthPolicyCredentialsManagerTest); DISALLOW_COPY_AND_ASSIGN(AuthPolicyCredentialsManagerTest);
}; };
...@@ -162,7 +160,7 @@ TEST_F(AuthPolicyCredentialsManagerTest, ShowSameNotificationOnce) { ...@@ -162,7 +160,7 @@ TEST_F(AuthPolicyCredentialsManagerTest, ShowSameNotificationOnce) {
EXPECT_CALL(*mock_user_manager(), SaveForceOnlineSignin(account_id(), true)); EXPECT_CALL(*mock_user_manager(), SaveForceOnlineSignin(account_id(), true));
CallGetUserStatusAndWait(); CallGetUserStatusAndWait();
EXPECT_EQ(1, GetNumberOfNotifications()); EXPECT_EQ(1, GetNumberOfNotifications());
EXPECT_TRUE(CancelNotificationById(IDS_ACTIVE_DIRECTORY_PASSWORD_EXPIRED)); CancelNotificationById(IDS_ACTIVE_DIRECTORY_PASSWORD_EXPIRED);
// Do not show the same notification twice. // Do not show the same notification twice.
EXPECT_CALL(*mock_user_manager(), SaveForceOnlineSignin(account_id(), true)); EXPECT_CALL(*mock_user_manager(), SaveForceOnlineSignin(account_id(), true));
...@@ -181,8 +179,8 @@ TEST_F(AuthPolicyCredentialsManagerTest, ShowDifferentNotifications) { ...@@ -181,8 +179,8 @@ TEST_F(AuthPolicyCredentialsManagerTest, ShowDifferentNotifications) {
EXPECT_CALL(*mock_user_manager(), SaveForceOnlineSignin(account_id(), true)); EXPECT_CALL(*mock_user_manager(), SaveForceOnlineSignin(account_id(), true));
CallGetUserStatusAndWait(); CallGetUserStatusAndWait();
EXPECT_EQ(2, GetNumberOfNotifications()); EXPECT_EQ(2, GetNumberOfNotifications());
EXPECT_TRUE(CancelNotificationById(IDS_ACTIVE_DIRECTORY_PASSWORD_CHANGED)); CancelNotificationById(IDS_ACTIVE_DIRECTORY_PASSWORD_CHANGED);
EXPECT_TRUE(CancelNotificationById(IDS_ACTIVE_DIRECTORY_REFRESH_AUTH_TOKEN)); CancelNotificationById(IDS_ACTIVE_DIRECTORY_REFRESH_AUTH_TOKEN);
EXPECT_EQ(0, GetNumberOfNotifications()); EXPECT_EQ(0, GetNumberOfNotifications());
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/component_loader.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/notifications/notification_ui_manager.h" #include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chromeos/chromeos_switches.h" #include "chromeos/chromeos_switches.h"
#include "components/drive/chromeos/file_system_interface.h" #include "components/drive/chromeos/file_system_interface.h"
...@@ -549,6 +549,9 @@ void FileManagerBrowserTestBase::SetUpOnMainThread() { ...@@ -549,6 +549,9 @@ void FileManagerBrowserTestBase::SetUpOnMainThread() {
drive_volume_->ConfigureShareUrlBase(share_url_base); drive_volume_->ConfigureShareUrlBase(share_url_base);
test_util::WaitUntilDriveMountPointIsAdded(profile()); test_util::WaitUntilDriveMountPointIsAdded(profile());
} }
display_service_ =
std::make_unique<NotificationDisplayServiceTester>(profile());
} }
void FileManagerBrowserTestBase::SetUpCommandLine( void FileManagerBrowserTestBase::SetUpCommandLine(
...@@ -729,12 +732,13 @@ void FileManagerBrowserTestBase::OnMessage(const std::string& name, ...@@ -729,12 +732,13 @@ void FileManagerBrowserTestBase::OnMessage(const std::string& name,
ASSERT_TRUE(value.GetInteger("index", &index)); ASSERT_TRUE(value.GetInteger("index", &index));
const std::string delegate_id = extension_id + "-" + notification_id; const std::string delegate_id = extension_id + "-" + notification_id;
const message_center::Notification* notification =
g_browser_process->notification_ui_manager()->FindById(delegate_id,
profile());
ASSERT_TRUE(notification);
notification->delegate()->ButtonClick(index); base::Optional<message_center::Notification> notification =
display_service_->GetNotification(delegate_id);
EXPECT_TRUE(notification);
display_service_->SimulateClick(NotificationHandler::Type::EXTENSION,
delegate_id, index, base::nullopt);
return; return;
} }
......
...@@ -20,13 +20,15 @@ ...@@ -20,13 +20,15 @@
#define DISABLE_SLOW_FILESAPP_TESTS #define DISABLE_SLOW_FILESAPP_TESTS
#endif #endif
class NotificationDisplayServiceTester;
namespace file_manager { namespace file_manager {
enum GuestMode { NOT_IN_GUEST_MODE, IN_GUEST_MODE, IN_INCOGNITO }; enum GuestMode { NOT_IN_GUEST_MODE, IN_GUEST_MODE, IN_INCOGNITO };
class LocalTestVolume;
class DriveTestVolume; class DriveTestVolume;
class FakeTestVolume; class FakeTestVolume;
class LocalTestVolume;
// The base test class. // The base test class.
class FileManagerBrowserTestBase : public ExtensionApiTest { class FileManagerBrowserTestBase : public ExtensionApiTest {
...@@ -72,6 +74,7 @@ class FileManagerBrowserTestBase : public ExtensionApiTest { ...@@ -72,6 +74,7 @@ class FileManagerBrowserTestBase : public ExtensionApiTest {
create_drive_integration_service_; create_drive_integration_service_;
std::unique_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> std::unique_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest>
service_factory_for_test_; service_factory_for_test_;
std::unique_ptr<NotificationDisplayServiceTester> display_service_;
}; };
} // namespace file_manager } // namespace file_manager
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "chrome/browser/notifications/notification_display_service_tester.h" #include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/notifications/notification_handler.h" #include "chrome/browser/notifications/notification_handler.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/browser_with_test_window_test.h" #include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_browser_process.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment