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"
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_browsertest.h" #include "chrome/browser/extensions/extension_browsertest.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/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
...@@ -30,21 +30,21 @@ ...@@ -30,21 +30,21 @@
#include "extensions/browser/test_extension_registry_observer.h" #include "extensions/browser/test_extension_registry_observer.h"
#include "extensions/common/constants.h" #include "extensions/common/constants.h"
#include "extensions/test/background_page_watcher.h" #include "extensions/test/background_page_watcher.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h" #include "ui/message_center/notification.h"
#include "ui/message_center/notification_delegate.h" #include "ui/message_center/notification_delegate.h"
#include "ui/message_center/notification_list.h"
using content::NavigationController; using content::NavigationController;
using content::WebContents; using content::WebContents;
using extensions::Extension; using extensions::Extension;
using extensions::ExtensionRegistry; using extensions::ExtensionRegistry;
class ExtensionCrashRecoveryTestBase : public ExtensionBrowserTest { class ExtensionCrashRecoveryTest : public ExtensionBrowserTest {
protected: protected:
virtual void AcceptNotification(size_t index) = 0; void SetUpOnMainThread() override {
virtual void CancelNotification(size_t index) = 0; ExtensionBrowserTest::SetUpOnMainThread();
virtual size_t CountBalloons() = 0; display_service_ =
std::make_unique<NotificationDisplayServiceTester>(profile());
}
ExtensionService* GetExtensionService() { ExtensionService* GetExtensionService() {
return extensions::ExtensionSystem::Get(browser()->profile())-> return extensions::ExtensionSystem::Get(browser()->profile())->
...@@ -122,44 +122,25 @@ class ExtensionCrashRecoveryTestBase : public ExtensionBrowserTest { ...@@ -122,44 +122,25 @@ class ExtensionCrashRecoveryTestBase : public ExtensionBrowserTest {
CheckExtensionConsistency(second_extension_id_); CheckExtensionConsistency(second_extension_id_);
} }
std::string first_extension_id_; void AcceptNotification(const std::string& extension_id) {
std::string second_extension_id_;
};
class ExtensionCrashRecoveryTest : public ExtensionCrashRecoveryTestBase {
protected:
void AcceptNotification(size_t index) override {
message_center::MessageCenter* message_center =
message_center::MessageCenter::Get();
ASSERT_GT(message_center->NotificationCount(), index);
message_center::NotificationList::Notifications::reverse_iterator it =
message_center->GetVisibleNotifications().rbegin();
for (size_t i = 0; i < index; ++i)
++it;
std::string id = (*it)->id();
extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry()); extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry());
message_center->ClickOnNotification(id); display_service_->SimulateClick(NotificationHandler::Type::TRANSIENT,
"app.background.crashed." + extension_id,
base::nullopt, base::nullopt);
auto* extension = observer.WaitForExtensionLoaded(); auto* extension = observer.WaitForExtensionLoaded();
extensions::BackgroundPageWatcher(GetProcessManager(), extension) extensions::BackgroundPageWatcher(GetProcessManager(), extension)
.WaitForOpen(); .WaitForOpen();
} }
void CancelNotification(size_t index) override { size_t CountNotifications() {
message_center::MessageCenter* message_center = return display_service_
message_center::MessageCenter::Get(); ->GetDisplayedNotificationsForType(NotificationHandler::Type::TRANSIENT)
ASSERT_GT(message_center->NotificationCount(), index); .size();
message_center::NotificationList::Notifications::reverse_iterator it =
message_center->GetVisibleNotifications().rbegin();
for (size_t i = 0; i < index; ++i)
++it;
ASSERT_TRUE(g_browser_process->notification_ui_manager()->CancelById(
(*it)->id(),
NotificationUIManager::GetProfileID(browser()->profile())));
} }
size_t CountBalloons() override { std::string first_extension_id_;
return message_center::MessageCenter::Get()->NotificationCount(); std::string second_extension_id_;
} std::unique_ptr<NotificationDisplayServiceTester> display_service_;
}; };
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) { IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) {
...@@ -169,7 +150,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) { ...@@ -169,7 +150,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, Basic) {
CrashExtension(first_extension_id_); CrashExtension(first_extension_id_);
ASSERT_EQ(count_before, GetEnabledExtensionCount()); ASSERT_EQ(count_before, GetEnabledExtensionCount());
ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
SCOPED_TRACE("after clicking the balloon"); SCOPED_TRACE("after clicking the balloon");
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
...@@ -186,7 +167,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, DISABLED_CloseAndReload) { ...@@ -186,7 +167,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, DISABLED_CloseAndReload) {
ASSERT_EQ(count_before, GetEnabledExtensionCount()); ASSERT_EQ(count_before, GetEnabledExtensionCount());
ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
ASSERT_NO_FATAL_FAILURE(CancelNotification(0)); // In 2013, when this test became flaky, this line was part of the test.
// CancelNotification() no longer exists.
// ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
ReloadExtension(first_extension_id_); ReloadExtension(first_extension_id_);
SCOPED_TRACE("after reloading"); SCOPED_TRACE("after reloading");
...@@ -211,7 +194,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) { ...@@ -211,7 +194,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ReloadIndependently) {
// The balloon should automatically hide after the extension is successfully // The balloon should automatically hide after the extension is successfully
// reloaded. // reloaded.
ASSERT_EQ(0U, CountBalloons()); ASSERT_EQ(0U, CountNotifications());
} }
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
...@@ -224,7 +207,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -224,7 +207,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
WebContents* original_tab = WebContents* original_tab =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(original_tab); ASSERT_TRUE(original_tab);
ASSERT_EQ(1U, CountBalloons()); ASSERT_EQ(1U, CountNotifications());
// Open a new tab, but the balloon will still be there. // Open a new tab, but the balloon will still be there.
chrome::NewTab(browser()); chrome::NewTab(browser());
...@@ -232,7 +215,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -232,7 +215,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(new_current_tab); ASSERT_TRUE(new_current_tab);
ASSERT_NE(new_current_tab, original_tab); ASSERT_NE(new_current_tab, original_tab);
ASSERT_EQ(1U, CountBalloons()); ASSERT_EQ(1U, CountNotifications());
ReloadExtension(first_extension_id_); ReloadExtension(first_extension_id_);
...@@ -241,7 +224,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -241,7 +224,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
// The balloon should automatically hide after the extension is successfully // The balloon should automatically hide after the extension is successfully
// reloaded. // reloaded.
ASSERT_EQ(0U, CountBalloons()); ASSERT_EQ(0U, CountNotifications());
} }
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
...@@ -254,14 +237,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -254,14 +237,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
WebContents* current_tab = WebContents* current_tab =
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(current_tab); ASSERT_TRUE(current_tab);
ASSERT_EQ(1U, CountBalloons()); ASSERT_EQ(1U, CountNotifications());
// Navigate to another page. // Navigate to another page.
ui_test_utils::NavigateToURL( ui_test_utils::NavigateToURL(
browser(), ui_test_utils::GetTestUrl( browser(), ui_test_utils::GetTestUrl(
base::FilePath(base::FilePath::kCurrentDirectory), base::FilePath(base::FilePath::kCurrentDirectory),
base::FilePath(FILE_PATH_LITERAL("title1.html")))); base::FilePath(FILE_PATH_LITERAL("title1.html"))));
ASSERT_EQ(1U, CountBalloons()); ASSERT_EQ(1U, CountNotifications());
ReloadExtension(first_extension_id_); ReloadExtension(first_extension_id_);
...@@ -270,7 +253,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -270,7 +253,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
// The balloon should automatically hide after the extension is successfully // The balloon should automatically hide after the extension is successfully
// reloaded. // reloaded.
ASSERT_EQ(0U, CountBalloons()); ASSERT_EQ(0U, CountNotifications());
} }
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ShutdownWhileCrashed) { IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ShutdownWhileCrashed) {
...@@ -286,7 +269,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) { ...@@ -286,7 +269,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashFirst) {
LoadSecondExtension(); LoadSecondExtension();
CrashExtension(first_extension_id_); CrashExtension(first_extension_id_);
ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
SCOPED_TRACE("after clicking the balloon"); SCOPED_TRACE("after clicking the balloon");
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
...@@ -299,7 +282,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) { ...@@ -299,7 +282,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsCrashSecond) {
LoadSecondExtension(); LoadSecondExtension();
CrashExtension(second_extension_id_); CrashExtension(second_extension_id_);
ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
SCOPED_TRACE("after clicking the balloon"); SCOPED_TRACE("after clicking the balloon");
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
...@@ -321,13 +304,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -321,13 +304,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
{ {
SCOPED_TRACE("first balloon"); SCOPED_TRACE("first balloon");
ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
} }
{ {
SCOPED_TRACE("second balloon"); SCOPED_TRACE("second balloon");
ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(second_extension_id_); CheckExtensionConsistency(second_extension_id_);
} }
...@@ -344,13 +327,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) { ...@@ -344,13 +327,13 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, TwoExtensionsOneByOne) {
{ {
SCOPED_TRACE("first balloon"); SCOPED_TRACE("first balloon");
ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
} }
{ {
SCOPED_TRACE("second balloon"); SCOPED_TRACE("second balloon");
ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(second_extension_id_); CheckExtensionConsistency(second_extension_id_);
} }
...@@ -384,8 +367,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -384,8 +367,10 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
// Accept notification 1 before canceling notification 0. // Accept notification 1 before canceling notification 0.
// Otherwise, on Linux and Windows, there is a race here, in which // Otherwise, on Linux and Windows, there is a race here, in which
// canceled notifications do not immediately go away. // canceled notifications do not immediately go away.
ASSERT_NO_FATAL_FAILURE(AcceptNotification(1)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(first_extension_id_));
ASSERT_NO_FATAL_FAILURE(CancelNotification(0)); // In 2013, when this test became flaky, these lines were part of the test.
// CancelNotification() no longer exists.
// ASSERT_NO_FATAL_FAILURE(CancelNotification(0));
SCOPED_TRACE("balloons done"); SCOPED_TRACE("balloons done");
ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
...@@ -408,16 +393,16 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -408,16 +393,16 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
browser()->tab_strip_model()->GetActiveWebContents(); browser()->tab_strip_model()->GetActiveWebContents();
ASSERT_TRUE(current_tab); ASSERT_TRUE(current_tab);
// At the beginning we should have one balloon displayed for each extension. // At the beginning we should have one balloon displayed for each extension.
ASSERT_EQ(2U, CountBalloons()); ASSERT_EQ(2U, CountNotifications());
ReloadExtension(first_extension_id_); ReloadExtension(first_extension_id_);
// One of the balloons should hide after the extension is reloaded. // One of the balloons should hide after the extension is reloaded.
ASSERT_EQ(1U, CountBalloons()); ASSERT_EQ(1U, CountNotifications());
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
} }
{ {
SCOPED_TRACE("second: balloon"); SCOPED_TRACE("second: balloon");
ASSERT_NO_FATAL_FAILURE(AcceptNotification(0)); ASSERT_NO_FATAL_FAILURE(AcceptNotification(second_extension_id_));
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
CheckExtensionConsistency(second_extension_id_); CheckExtensionConsistency(second_extension_id_);
} }
...@@ -432,14 +417,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) { ...@@ -432,14 +417,14 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUninstall) {
ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); ASSERT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
ASSERT_EQ(1U, CountBalloons()); ASSERT_EQ(1U, CountNotifications());
UninstallExtension(first_extension_id_); UninstallExtension(first_extension_id_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
SCOPED_TRACE("after uninstalling"); SCOPED_TRACE("after uninstalling");
ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount()); ASSERT_EQ(crash_count_before, GetTerminatedExtensionCount());
ASSERT_EQ(0U, CountBalloons()); ASSERT_EQ(0U, CountNotifications());
} }
IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUnloadAll) { IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, CrashAndUnloadAll) {
...@@ -480,18 +465,23 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest, ...@@ -480,18 +465,23 @@ IN_PROC_BROWSER_TEST_F(ExtensionCrashRecoveryTest,
EXPECT_EQ(count_before, GetEnabledExtensionCount()); EXPECT_EQ(count_before, GetEnabledExtensionCount());
EXPECT_EQ(crash_count_before + 1, GetTerminatedExtensionCount()); EXPECT_EQ(crash_count_before + 1, GetTerminatedExtensionCount());
extensions::TestExtensionRegistryObserver observer(GetExtensionRegistry());
{ {
content::WindowedNotificationObserver observer( content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP, content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>( content::Source<NavigationController>(&browser()
&browser()->tab_strip_model()->GetActiveWebContents()-> ->tab_strip_model()
GetController())); ->GetActiveWebContents()
->GetController()));
chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB); chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
observer.Wait(); observer.Wait();
} }
auto* extension = observer.WaitForExtensionLoaded();
EXPECT_EQ(first_extension_id_, extension->id());
// Extension should now be loaded. // Extension should now be loaded.
SCOPED_TRACE("after reloading the tab"); SCOPED_TRACE("after reloading the tab");
CheckExtensionConsistency(first_extension_id_); CheckExtensionConsistency(first_extension_id_);
ASSERT_EQ(count_before + 1, GetEnabledExtensionCount()); ASSERT_EQ(count_before + 1, GetEnabledExtensionCount());
ASSERT_EQ(0U, CountBalloons()); ASSERT_EQ(0U, CountNotifications());
} }
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