Chromium Code Reviews| Index: chrome/browser/chromeos/policy/device_local_account_browsertest.cc |
| diff --git a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc |
| index f7f4019c27ed75f3215cf4ef700a07c8959a003b..26ec17b9e4df08d6501414cecf9f5b2e20d4751f 100644 |
| --- a/chrome/browser/chromeos/policy/device_local_account_browsertest.cc |
| +++ b/chrome/browser/chromeos/policy/device_local_account_browsertest.cc |
| @@ -121,10 +121,12 @@ |
| #include "extensions/browser/app_window/app_window.h" |
| #include "extensions/browser/app_window/app_window_registry.h" |
| #include "extensions/browser/app_window/native_app_window.h" |
| +#include "extensions/browser/extension_registry.h" |
| #include "extensions/browser/extension_system.h" |
| #include "extensions/browser/install/crx_install_error.h" |
| #include "extensions/browser/management_policy.h" |
| #include "extensions/browser/notification_types.h" |
| +#include "extensions/browser/test_extension_registry_observer.h" |
| #include "extensions/common/constants.h" |
| #include "extensions/common/extension.h" |
| #include "net/base/url_util.h" |
| @@ -373,13 +375,6 @@ void DictionaryPrefValueWaiter::QuitLoopIfExpectedValueFound() { |
| } |
| } |
| -bool DoesInstallSuccessReferToId(const std::string& id, |
| - const content::NotificationSource& source, |
| - const content::NotificationDetails& details) { |
| - return content::Details<const extensions::InstalledExtensionInfo>(details)-> |
| - extension->id() == id; |
| -} |
| - |
| bool DoesInstallFailureReferToId(const std::string& id, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| @@ -811,6 +806,59 @@ static bool IsKnownUser(const AccountId& account_id) { |
| return user_manager::UserManager::Get()->IsKnownUser(account_id); |
| } |
| +// Helper that listen extension installation when new profile is created. |
| +class ExtensionInstallObserver : public content::NotificationObserver, |
| + public extensions::ExtensionRegistryObserver { |
| + public: |
| + ExtensionInstallObserver() : registry_(nullptr) { |
| + registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED, |
| + content::NotificationService::AllSources()); |
| + } |
| + |
| + ~ExtensionInstallObserver() override { |
| + if (registry_ != nullptr) |
| + registry_->RemoveObserver(this); |
| + } |
| + |
| + // Wait until an extension with |extension_id| is installed. |
| + void Wait(const std::string& extension_id) { |
| + waiting_extension_id_ = extension_id; |
| + run_loop_.Run(); |
| + } |
| + |
| + private: |
| + // extensions::ExtensionRegistryObserver: |
| + void OnExtensionWillBeInstalled(content::BrowserContext* browser_context, |
| + const extensions::Extension* extension, |
| + bool is_update, |
| + bool from_ephemeral, |
| + const std::string& old_name) override { |
| + DCHECK_EQ(waiting_extension_id_, extension->id()); |
| + |
| + run_loop_.Quit(); |
| + } |
| + |
| + // content::NotificationObserver: |
| + void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) override { |
| + DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CREATED, type); |
|
cschuet (SLOW)
2015/11/17 15:02:48
You should probably check whether the app has alre
limasdf
2015/11/17 17:00:57
Done.
|
| + |
| + Profile* profile = content::Source<Profile>(source).ptr(); |
| + registry_ = extensions::ExtensionRegistry::Get(profile); |
| + |
| + // Start listening for extension installation. |
| + registry_->AddObserver(this); |
| + } |
| + |
| + extensions::ExtensionRegistry* registry_; |
| + base::RunLoop run_loop_; |
| + content::NotificationRegistrar registrar_; |
| + std::string waiting_extension_id_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ExtensionInstallObserver); |
| +}; |
| + |
| IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { |
| AddPublicSessionToDevicePolicy(kAccountId1); |
| AddPublicSessionToDevicePolicy(kAccountId2); |
| @@ -1046,19 +1094,16 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExtensionsUncached) { |
| WaitForPolicy(); |
| // Start listening for app/extension installation results. |
| - content::WindowedNotificationObserver hosted_app_observer( |
| - extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| - base::Bind(DoesInstallSuccessReferToId, kHostedAppID)); |
| + ExtensionInstallObserver install_observer; |
| content::WindowedNotificationObserver extension_observer( |
| extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); |
| - |
| ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); |
| // Wait for the hosted app installation to succeed and the extension |
| // installation to fail (because hosted apps are whitelisted for use in |
| // device-local accounts and extensions are not). |
| - hosted_app_observer.Wait(); |
| + install_observer.Wait(kHostedAppID); |
| extension_observer.Wait(); |
| // Verify that the hosted app was installed. |
| @@ -1127,9 +1172,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExtensionsCached) { |
| WaitForPolicy(); |
| // Start listening for app/extension installation results. |
| - content::WindowedNotificationObserver hosted_app_observer( |
| - extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| - base::Bind(DoesInstallSuccessReferToId, kHostedAppID)); |
| + ExtensionInstallObserver install_observer; |
| content::WindowedNotificationObserver extension_observer( |
| extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); |
| @@ -1138,7 +1181,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExtensionsCached) { |
| // Wait for the hosted app installation to succeed and the extension |
| // installation to fail. |
| - hosted_app_observer.Wait(); |
| + install_observer.Wait(kHostedAppID); |
| extension_observer.Wait(); |
| // Verify that the hosted app was installed. |
| @@ -1258,9 +1301,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExtensionCacheImplTest) { |
| WaitForPolicy(); |
| // Start listening for app/extension installation results. |
| - content::WindowedNotificationObserver hosted_app_observer( |
| - extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| - base::Bind(DoesInstallSuccessReferToId, kHostedAppID)); |
| + ExtensionInstallObserver install_observer; |
| content::WindowedNotificationObserver extension_observer( |
| extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, |
| base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); |
| @@ -1270,7 +1311,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExtensionCacheImplTest) { |
| // Wait for the hosted app installation to succeed and the extension |
| // installation to fail (because hosted apps are whitelisted for use in |
| // device-local accounts and extensions are not). |
| - hosted_app_observer.Wait(); |
| + install_observer.Wait(kHostedAppID); |
| extension_observer.Wait(); |
| // Verify that the extension was kept in the local cache. |
| @@ -2199,12 +2240,10 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyForExtensions) { |
| WaitForPolicy(); |
| // Observe the app installation after login. |
| - content::WindowedNotificationObserver extension_observer( |
| - extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED, |
| - base::Bind(DoesInstallSuccessReferToId, kShowManagedStorageID)); |
| + ExtensionInstallObserver install_observer; |
| ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); |
| WaitForSessionStart(); |
| - extension_observer.Wait(); |
| + install_observer.Wait(kShowManagedStorageID); |
| // Verify that the app was installed. |
| Profile* profile = GetProfileForTest(); |