Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: chrome/browser/policy/device_local_account_browsertest.cc

Issue 12218078: Implement a policy to autologin a public account. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: split out FakeSessionManagerClient Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 25 matching lines...) Expand all
36 #include "chrome/browser/ui/browser_finder.h" 36 #include "chrome/browser/ui/browser_finder.h"
37 #include "chrome/browser/ui/host_desktop.h" 37 #include "chrome/browser/ui/host_desktop.h"
38 #include "chrome/browser/ui/tabs/tab_strip_model.h" 38 #include "chrome/browser/ui/tabs/tab_strip_model.h"
39 #include "chrome/common/chrome_notification_types.h" 39 #include "chrome/common/chrome_notification_types.h"
40 #include "chrome/common/chrome_paths.h" 40 #include "chrome/common/chrome_paths.h"
41 #include "chrome/common/chrome_switches.h" 41 #include "chrome/common/chrome_switches.h"
42 #include "chrome/test/base/in_process_browser_test.h" 42 #include "chrome/test/base/in_process_browser_test.h"
43 #include "chromeos/dbus/cryptohome_client.h" 43 #include "chromeos/dbus/cryptohome_client.h"
44 #include "chromeos/dbus/dbus_method_call_status.h" 44 #include "chromeos/dbus/dbus_method_call_status.h"
45 #include "chromeos/dbus/dbus_thread_manager.h" 45 #include "chromeos/dbus/dbus_thread_manager.h"
46 #include "chromeos/dbus/fake_session_manager_client.h"
bartfab (slow) 2013/02/25 16:51:23 You should update the list of includes, removing t
dconnelly 2013/02/26 18:04:15 Done.
46 #include "chromeos/dbus/mock_dbus_thread_manager.h" 47 #include "chromeos/dbus/mock_dbus_thread_manager.h"
47 #include "chromeos/dbus/session_manager_client.h" 48 #include "chromeos/dbus/session_manager_client.h"
48 #include "content/public/browser/notification_observer.h" 49 #include "content/public/browser/notification_observer.h"
49 #include "content/public/browser/notification_registrar.h" 50 #include "content/public/browser/notification_registrar.h"
50 #include "content/public/browser/notification_service.h" 51 #include "content/public/browser/notification_service.h"
51 #include "content/public/browser/web_contents.h" 52 #include "content/public/browser/web_contents.h"
52 #include "testing/gmock/include/gmock/gmock.h" 53 #include "testing/gmock/include/gmock/gmock.h"
53 #include "third_party/cros_system_api/dbus/service_constants.h" 54 #include "third_party/cros_system_api/dbus/service_constants.h"
54 55
55 namespace em = enterprise_management; 56 namespace em = enterprise_management;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 101 }
101 102
102 private: 103 private:
103 int type_; 104 int type_;
104 ConditionTestCallback callback_; 105 ConditionTestCallback callback_;
105 base::RunLoop run_loop_; 106 base::RunLoop run_loop_;
106 107
107 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher); 108 DISALLOW_COPY_AND_ASSIGN(NotificationWatcher);
108 }; 109 };
109 110
110 // A fake implementation of session_manager. Accepts policy blobs to be set and
111 // returns them unmodified.
112 class FakeSessionManagerClient : public chromeos::SessionManagerClient {
113 public:
114 FakeSessionManagerClient() {}
115 virtual ~FakeSessionManagerClient() {}
116
117 // SessionManagerClient:
118 virtual void AddObserver(Observer* observer) OVERRIDE {}
119 virtual void RemoveObserver(Observer* observer) OVERRIDE {}
120 virtual bool HasObserver(Observer* observer) OVERRIDE { return false; }
121 virtual void EmitLoginPromptReady() OVERRIDE {}
122 virtual void EmitLoginPromptVisible() OVERRIDE {}
123 virtual void RestartJob(int pid, const std::string& command_line) OVERRIDE {}
124 virtual void RestartEntd() OVERRIDE {}
125 virtual void StartSession(const std::string& user_email) OVERRIDE {}
126 virtual void StopSession() OVERRIDE {}
127 virtual void StartDeviceWipe() OVERRIDE {}
128 virtual void RequestLockScreen() OVERRIDE {}
129 virtual void NotifyLockScreenShown() OVERRIDE {}
130 virtual void RequestUnlockScreen() OVERRIDE {}
131 virtual void NotifyLockScreenDismissed() OVERRIDE {}
132 virtual void RetrieveDevicePolicy(
133 const RetrievePolicyCallback& callback) OVERRIDE {
134 MessageLoop::current()->PostTask(FROM_HERE,
135 base::Bind(callback, device_policy_));
136 }
137 virtual void RetrieveUserPolicy(
138 const RetrievePolicyCallback& callback) OVERRIDE {
139 MessageLoop::current()->PostTask(FROM_HERE,
140 base::Bind(callback, user_policy_));
141 }
142 virtual void RetrieveDeviceLocalAccountPolicy(
143 const std::string& account_id,
144 const RetrievePolicyCallback& callback) OVERRIDE {
145 MessageLoop::current()->PostTask(
146 FROM_HERE,
147 base::Bind(callback, device_local_account_policy_[account_id]));
148 }
149 virtual void StoreDevicePolicy(const std::string& policy_blob,
150 const StorePolicyCallback& callback) OVERRIDE {
151 device_policy_ = policy_blob;
152 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
153 }
154 virtual void StoreUserPolicy(const std::string& policy_blob,
155 const StorePolicyCallback& callback) OVERRIDE {
156 user_policy_ = policy_blob;
157 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
158 }
159 virtual void StoreDeviceLocalAccountPolicy(
160 const std::string& account_id,
161 const std::string& policy_blob,
162 const StorePolicyCallback& callback) OVERRIDE {
163 device_local_account_policy_[account_id] = policy_blob;
164 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(callback, true));
165 }
166
167 const std::string& device_policy() const {
168 return device_policy_;
169 }
170 void set_device_policy(const std::string& policy_blob) {
171 device_policy_ = policy_blob;
172 }
173
174 const std::string& user_policy() const {
175 return user_policy_;
176 }
177 void set_user_policy(const std::string& policy_blob) {
178 user_policy_ = policy_blob;
179 }
180
181 const std::string& device_local_account_policy(
182 const std::string& account_id) const {
183 std::map<std::string, std::string>::const_iterator entry =
184 device_local_account_policy_.find(account_id);
185 return entry != device_local_account_policy_.end() ? entry->second
186 : EmptyString();
187 }
188 void set_device_local_account_policy(const std::string& account_id,
189 const std::string& policy_blob) {
190 device_local_account_policy_[account_id] = policy_blob;
191 }
192
193 private:
194 std::string device_policy_;
195 std::string user_policy_;
196 std::map<std::string, std::string> device_local_account_policy_;
197
198 DISALLOW_COPY_AND_ASSIGN(FakeSessionManagerClient);
199 };
200
201 class FakeCryptohomeClient : public chromeos::CryptohomeClient { 111 class FakeCryptohomeClient : public chromeos::CryptohomeClient {
202 public: 112 public:
203 using chromeos::CryptohomeClient::AsyncMethodCallback; 113 using chromeos::CryptohomeClient::AsyncMethodCallback;
204 using chromeos::CryptohomeClient::AsyncCallStatusHandler; 114 using chromeos::CryptohomeClient::AsyncCallStatusHandler;
205 using chromeos::CryptohomeClient::AsyncCallStatusWithDataHandler; 115 using chromeos::CryptohomeClient::AsyncCallStatusWithDataHandler;
206 116
207 FakeCryptohomeClient() {} 117 FakeCryptohomeClient() {}
208 virtual ~FakeCryptohomeClient() {} 118 virtual ~FakeCryptohomeClient() {}
209 119
210 virtual void SetAsyncCallStatusHandlers( 120 virtual void SetAsyncCallStatusHandlers(
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 void CheckPublicSessionPresent(const std::string& id) { 382 void CheckPublicSessionPresent(const std::string& id) {
473 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(id); 383 const chromeos::User* user = chromeos::UserManager::Get()->FindUser(id);
474 ASSERT_TRUE(user); 384 ASSERT_TRUE(user);
475 EXPECT_EQ(id, user->email()); 385 EXPECT_EQ(id, user->email());
476 EXPECT_EQ(chromeos::User::USER_TYPE_PUBLIC_ACCOUNT, user->GetType()); 386 EXPECT_EQ(chromeos::User::USER_TYPE_PUBLIC_ACCOUNT, user->GetType());
477 } 387 }
478 388
479 LocalPolicyTestServer test_server_; 389 LocalPolicyTestServer test_server_;
480 base::ScopedTempDir temp_dir_; 390 base::ScopedTempDir temp_dir_;
481 391
482 FakeSessionManagerClient session_manager_client_; 392 chromeos::FakeSessionManagerClient session_manager_client_;
483 FakeCryptohomeClient cryptohome_client_; 393 FakeCryptohomeClient cryptohome_client_;
484 }; 394 };
485 395
486 static bool IsKnownUser(const std::string& account_id) { 396 static bool IsKnownUser(const std::string& account_id) {
487 return chromeos::UserManager::Get()->IsKnownUser(account_id); 397 return chromeos::UserManager::Get()->IsKnownUser(account_id);
488 } 398 }
489 399
490 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { 400 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) {
491 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED, 401 NotificationWatcher(chrome::NOTIFICATION_USER_LIST_CHANGED,
492 base::Bind(&IsKnownUser, kAccountId1)).Run(); 402 base::Bind(&IsKnownUser, kAccountId1)).Run();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 499
590 TabStripModel* tabs = browser->tab_strip_model(); 500 TabStripModel* tabs = browser->tab_strip_model();
591 ASSERT_TRUE(tabs); 501 ASSERT_TRUE(tabs);
592 int expected_tab_count = static_cast<int>(arraysize(kStartupURLs)); 502 int expected_tab_count = static_cast<int>(arraysize(kStartupURLs));
593 EXPECT_EQ(expected_tab_count, tabs->count()); 503 EXPECT_EQ(expected_tab_count, tabs->count());
594 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i) 504 for (int i = 0; i < expected_tab_count && i < tabs->count(); ++i)
595 EXPECT_EQ(GURL(kStartupURLs[i]), tabs->GetWebContentsAt(i)->GetURL()); 505 EXPECT_EQ(GURL(kStartupURLs[i]), tabs->GetWebContentsAt(i)->GetURL());
596 } 506 }
597 507
598 } // namespace policy 508 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698