| Index: chrome/browser/policy/device_local_account_browsertest.cc
|
| diff --git a/chrome/browser/policy/device_local_account_browsertest.cc b/chrome/browser/policy/device_local_account_browsertest.cc
|
| index 62e89315e432990e41a96d9b9e95f560d3f5cefc..a413bbca505cfbde0d7a9bee464f5d3ea1ad5f8a 100644
|
| --- a/chrome/browser/policy/device_local_account_browsertest.cc
|
| +++ b/chrome/browser/policy/device_local_account_browsertest.cc
|
| @@ -43,11 +43,12 @@
|
| #include "chromeos/dbus/cryptohome_client.h"
|
| #include "chromeos/dbus/dbus_method_call_status.h"
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| +#include "chromeos/dbus/fake_session_manager_client.h"
|
| #include "chromeos/dbus/mock_dbus_thread_manager.h"
|
| -#include "chromeos/dbus/session_manager_client.h"
|
| #include "content/public/browser/notification_observer.h"
|
| #include "content/public/browser/notification_registrar.h"
|
| #include "content/public/browser/notification_service.h"
|
| +#include "content/public/browser/notification_watcher.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "third_party/cros_system_api/dbus/service_constants.h"
|
| @@ -69,135 +70,6 @@ const char* kStartupURLs[] = {
|
| "chrome://about",
|
| };
|
|
|
| -// Observes a specific notification type and quits the message loop once a
|
| -// condition holds.
|
| -class NotificationWatcher : public content::NotificationObserver {
|
| - public:
|
| - // Callback invoked on notifications. Should return true when the condition
|
| - // that the caller is waiting for is satisfied.
|
| - typedef base::Callback<bool(void)> ConditionTestCallback;
|
| -
|
| - explicit NotificationWatcher(int notification_type,
|
| - const ConditionTestCallback& callback)
|
| - : type_(notification_type),
|
| - callback_(callback) {}
|
| -
|
| - void Run() {
|
| - if (callback_.Run())
|
| - return;
|
| -
|
| - content::NotificationRegistrar registrar;
|
| - registrar.Add(this, type_, content::NotificationService::AllSources());
|
| - run_loop_.Run();
|
| - }
|
| -
|
| - // content::NotificationObserver:
|
| - virtual void Observe(int type,
|
| - const content::NotificationSource& source,
|
| - const content::NotificationDetails& details) OVERRIDE {
|
| - if (callback_.Run())
|
| - run_loop_.Quit();
|
| - }
|
| -
|
| - private:
|
| - int type_;
|
| - ConditionTestCallback callback_;
|
| - base::RunLoop run_loop_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(NotificationWatcher);
|
| -};
|
| -
|
| -// A fake implementation of session_manager. Accepts policy blobs to be set and
|
| -// returns them unmodified.
|
| -class FakeSessionManagerClient : public chromeos::SessionManagerClient {
|
| - public:
|
| - FakeSessionManagerClient() {}
|
| - virtual ~FakeSessionManagerClient() {}
|
| -
|
| - // SessionManagerClient:
|
| - virtual void AddObserver(Observer* observer) OVERRIDE {}
|
| - virtual void RemoveObserver(Observer* observer) OVERRIDE {}
|
| - virtual bool HasObserver(Observer* observer) OVERRIDE { return false; }
|
| - virtual void EmitLoginPromptReady() OVERRIDE {}
|
| - virtual void EmitLoginPromptVisible() OVERRIDE {}
|
| - virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {}
|
| - virtual void RestartEntd() OVERRIDE {}
|
| - virtual void StartSession(const std::string& user_email) OVERRIDE {}
|
| - virtual void StopSession() OVERRIDE {}
|
| - virtual void StartDeviceWipe() OVERRIDE {}
|
| - virtual void RequestLockScreen() OVERRIDE {}
|
| - virtual void NotifyLockScreenShown() OVERRIDE {}
|
| - virtual void RequestUnlockScreen() OVERRIDE {}
|
| - virtual void NotifyLockScreenDismissed() OVERRIDE {}
|
| - virtual void RetrieveDevicePolicy(
|
| - const RetrievePolicyCallback& callback) OVERRIDE {
|
| - MessageLoop::current()->PostTask(FROM_HERE,
|
| - base::Bind(callback, device_policy_));
|
| - }
|
| - virtual void RetrieveUserPolicy(
|
| - const RetrievePolicyCallback& callback) OVERRIDE {
|
| - MessageLoop::current()->PostTask(FROM_HERE,
|
| - base::Bind(callback, user_policy_));
|
| - }
|
| - virtual void RetrieveDeviceLocalAccountPolicy(
|
| - const std::string& account_id,
|
| - const RetrievePolicyCallback& callback) OVERRIDE {
|
| - MessageLoop::current()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(callback, device_local_account_policy_[account_id]));
|
| - }
|
| - virtual void StoreDevicePolicy(const std::string& policy_blob,
|
| - const StorePolicyCallback& callback) OVERRIDE {
|
| - device_policy_ = policy_blob;
|
| - MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
|
| - }
|
| - virtual void StoreUserPolicy(const std::string& policy_blob,
|
| - const StorePolicyCallback& callback) OVERRIDE {
|
| - user_policy_ = policy_blob;
|
| - MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
|
| - }
|
| - virtual void StoreDeviceLocalAccountPolicy(
|
| - const std::string& account_id,
|
| - const std::string& policy_blob,
|
| - const StorePolicyCallback& callback) OVERRIDE {
|
| - device_local_account_policy_[account_id] = policy_blob;
|
| - MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
|
| - }
|
| -
|
| - const std::string& device_policy() const {
|
| - return device_policy_;
|
| - }
|
| - void set_device_policy(const std::string& policy_blob) {
|
| - device_policy_ = policy_blob;
|
| - }
|
| -
|
| - const std::string& user_policy() const {
|
| - return user_policy_;
|
| - }
|
| - void set_user_policy(const std::string& policy_blob) {
|
| - user_policy_ = policy_blob;
|
| - }
|
| -
|
| - const std::string& device_local_account_policy(
|
| - const std::string& account_id) const {
|
| - std::map<std::string, std::string>::const_iterator entry =
|
| - device_local_account_policy_.find(account_id);
|
| - return entry != device_local_account_policy_.end() ? entry->second
|
| - : EmptyString();
|
| - }
|
| - void set_device_local_account_policy(const std::string& account_id,
|
| - const std::string& policy_blob) {
|
| - device_local_account_policy_[account_id] = policy_blob;
|
| - }
|
| -
|
| - private:
|
| - std::string device_policy_;
|
| - std::string user_policy_;
|
| - std::map<std::string, std::string> device_local_account_policy_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(FakeSessionManagerClient);
|
| -};
|
| -
|
| class FakeCryptohomeClient : public chromeos::CryptohomeClient {
|
| public:
|
| using chromeos::CryptohomeClient::AsyncMethodCallback;
|
| @@ -484,7 +356,7 @@ class DeviceLocalAccountTest : public InProcessBrowserTest {
|
| LocalPolicyTestServer test_server_;
|
| base::ScopedTempDir temp_dir_;
|
|
|
| - FakeSessionManagerClient session_manager_client_;
|
| + chromeos::FakeSessionManagerClient session_manager_client_;
|
| FakeCryptohomeClient cryptohome_client_;
|
| };
|
|
|
| @@ -493,10 +365,10 @@ static bool IsKnownUser(const std::string& account_id) {
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) {
|
| - NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| - base::Bind(&IsKnownUser, kAccountId1)).Run();
|
| - NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| - base::Bind(&IsKnownUser, kAccountId2)).Run();
|
| + content::NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| + base::Bind(&IsKnownUser, kAccountId1)).Run();
|
| + content::NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| + base::Bind(&IsKnownUser, kAccountId2)).Run();
|
|
|
| CheckPublicSessionPresent(kAccountId1);
|
| CheckPublicSessionPresent(kAccountId2);
|
| @@ -513,7 +385,7 @@ static bool DisplayNameMatches(const std::string& account_id,
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) {
|
| - NotificationWatcher(
|
| + content::NotificationWatcher(
|
| chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| base::Bind(&DisplayNameMatches, kAccountId1, kDisplayName1)).Run();
|
| }
|
| @@ -523,7 +395,9 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyDownload) {
|
| // sure it gets fetched from the server. Note that the test setup doesn't set
|
| // up policy for kAccountId2, so the presence of the display name can be used
|
| // as signal to indicate successful policy download.
|
| - NotificationWatcher(
|
| + ASSERT_TRUE(session_manager_client_.device_local_account_policy(
|
| + kAccountId2).empty());
|
| + content::NotificationWatcher(
|
| chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| base::Bind(&DisplayNameMatches, kAccountId2, kDisplayName2)).Run();
|
|
|
| @@ -538,10 +412,10 @@ static bool IsNotKnownUser(const std::string& account_id) {
|
|
|
| IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DevicePolicyChange) {
|
| // Wait until the login screen is up.
|
| - NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| - base::Bind(&IsKnownUser, kAccountId1)).Run();
|
| - NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| - base::Bind(&IsKnownUser, kAccountId2)).Run();
|
| + content::NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| + base::Bind(&IsKnownUser, kAccountId1)).Run();
|
| + content::NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| + base::Bind(&IsKnownUser, kAccountId2)).Run();
|
|
|
| // Update policy to remove kAccountId2.
|
| em::ChromeDeviceSettingsProto policy;
|
| @@ -553,8 +427,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DevicePolicyChange) {
|
| g_browser_process->policy_service()->RefreshPolicies(base::Closure());
|
|
|
| // Make sure the second device-local account disappears.
|
| - NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| - base::Bind(&IsNotKnownUser, kAccountId2)).Run();
|
| + content::NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| + base::Bind(&IsNotKnownUser, kAccountId2)).Run();
|
| }
|
|
|
| static bool IsSessionStarted() {
|
| @@ -565,7 +439,7 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) {
|
| // This observes the display name becoming available as this indicates
|
| // device-local account policy is fully loaded, which is a prerequisite for
|
| // successful login.
|
| - NotificationWatcher(
|
| + content::NotificationWatcher(
|
| chrome::NOTIFICATION_USER_LIST_CHANGED,
|
| base::Bind(&DisplayNameMatches, kAccountId1, kDisplayName1)).Run();
|
|
|
| @@ -575,8 +449,8 @@ IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) {
|
| controller->LoginAsPublicAccount(kAccountId1);
|
|
|
| // Wait for the session to start.
|
| - NotificationWatcher(chrome::NOTIFICATION_SESSION_STARTED,
|
| - base::Bind(IsSessionStarted)).Run();
|
| + content::NotificationWatcher(chrome::NOTIFICATION_SESSION_STARTED,
|
| + base::Bind(IsSessionStarted)).Run();
|
|
|
| // Check that the startup pages specified in policy were opened.
|
| EXPECT_EQ(1U, chrome::GetTotalBrowserCount());
|
|
|