| OLD | NEW |
| 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 "apps/app_window_registry.h" | 8 #include "apps/app_window_registry.h" |
| 9 #include "apps/ui/native_app_window.h" | 9 #include "apps/ui/native_app_window.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/system/chromeos/session/logout_confirmation_controller.h" | 11 #include "ash/system/chromeos/session/logout_confirmation_controller.h" |
| 12 #include "ash/system/chromeos/session/logout_confirmation_dialog.h" | 12 #include "ash/system/chromeos/session/logout_confirmation_dialog.h" |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/callback.h" | 16 #include "base/callback.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/json/json_reader.h" | 20 #include "base/json/json_reader.h" |
| 21 #include "base/json/json_writer.h" | 21 #include "base/json/json_writer.h" |
| 22 #include "base/location.h" | 22 #include "base/location.h" |
| 23 #include "base/macros.h" |
| 23 #include "base/memory/ref_counted.h" | 24 #include "base/memory/ref_counted.h" |
| 24 #include "base/memory/scoped_ptr.h" | 25 #include "base/memory/scoped_ptr.h" |
| 25 #include "base/message_loop/message_loop.h" | 26 #include "base/message_loop/message_loop.h" |
| 26 #include "base/message_loop/message_loop_proxy.h" | 27 #include "base/message_loop/message_loop_proxy.h" |
| 27 #include "base/path_service.h" | 28 #include "base/path_service.h" |
| 29 #include "base/prefs/pref_change_registrar.h" |
| 28 #include "base/prefs/pref_service.h" | 30 #include "base/prefs/pref_service.h" |
| 29 #include "base/run_loop.h" | 31 #include "base/run_loop.h" |
| 30 #include "base/sequenced_task_runner.h" | 32 #include "base/sequenced_task_runner.h" |
| 31 #include "base/strings/string_number_conversions.h" | 33 #include "base/strings/string_number_conversions.h" |
| 32 #include "base/strings/string_util.h" | 34 #include "base/strings/string_util.h" |
| 33 #include "base/strings/stringprintf.h" | 35 #include "base/strings/stringprintf.h" |
| 34 #include "base/strings/utf_string_conversions.h" | 36 #include "base/strings/utf_string_conversions.h" |
| 35 #include "base/values.h" | 37 #include "base/values.h" |
| 36 #include "chrome/browser/browser_process.h" | 38 #include "chrome/browser/browser_process.h" |
| 37 #include "chrome/browser/chrome_notification_types.h" | 39 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 using testing::Return; | 137 using testing::Return; |
| 136 using testing::_; | 138 using testing::_; |
| 137 | 139 |
| 138 namespace policy { | 140 namespace policy { |
| 139 | 141 |
| 140 namespace { | 142 namespace { |
| 141 | 143 |
| 142 const char kDomain[] = "example.com"; | 144 const char kDomain[] = "example.com"; |
| 143 const char kAccountId1[] = "dla1@example.com"; | 145 const char kAccountId1[] = "dla1@example.com"; |
| 144 const char kAccountId2[] = "dla2@example.com"; | 146 const char kAccountId2[] = "dla2@example.com"; |
| 145 const char kDisplayName[] = "display name"; | 147 const char kDisplayName1[] = "display name 1"; |
| 148 const char kDisplayName2[] = "display name 2"; |
| 146 const char* kStartupURLs[] = { | 149 const char* kStartupURLs[] = { |
| 147 "chrome://policy", | 150 "chrome://policy", |
| 148 "chrome://about", | 151 "chrome://about", |
| 149 }; | 152 }; |
| 150 const char kExistentTermsOfServicePath[] = "chromeos/enterprise/tos.txt"; | 153 const char kExistentTermsOfServicePath[] = "chromeos/enterprise/tos.txt"; |
| 151 const char kNonexistentTermsOfServicePath[] = "chromeos/enterprise/tos404.txt"; | 154 const char kNonexistentTermsOfServicePath[] = "chromeos/enterprise/tos404.txt"; |
| 152 const char kRelativeUpdateURL[] = "/service/update2/crx"; | 155 const char kRelativeUpdateURL[] = "/service/update2/crx"; |
| 153 const char kUpdateManifestHeader[] = | 156 const char kUpdateManifestHeader[] = |
| 154 "<?xml version='1.0' encoding='UTF-8'?>\n" | 157 "<?xml version='1.0' encoding='UTF-8'?>\n" |
| 155 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>\n"; | 158 "<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>\n"; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 GURL crx_url; | 205 GURL crx_url; |
| 203 }; | 206 }; |
| 204 typedef std::map<std::string, Update> UpdateMap; | 207 typedef std::map<std::string, Update> UpdateMap; |
| 205 UpdateMap updates_; | 208 UpdateMap updates_; |
| 206 | 209 |
| 207 const std::string relative_update_url_; | 210 const std::string relative_update_url_; |
| 208 | 211 |
| 209 DISALLOW_COPY_AND_ASSIGN(TestingUpdateManifestProvider); | 212 DISALLOW_COPY_AND_ASSIGN(TestingUpdateManifestProvider); |
| 210 }; | 213 }; |
| 211 | 214 |
| 215 // Helper that observes the dictionary |pref| in local state and waits until the |
| 216 // value stored for |key| matches |expected_value|. |
| 217 class DictionaryPrefValueWaiter { |
| 218 public: |
| 219 DictionaryPrefValueWaiter(const std::string& pref, |
| 220 const std::string& key, |
| 221 const std::string& expected_value); |
| 222 ~DictionaryPrefValueWaiter(); |
| 223 |
| 224 void Wait(); |
| 225 |
| 226 private: |
| 227 void QuitLoopIfExpectedValueFound(); |
| 228 |
| 229 const std::string pref_; |
| 230 const std::string key_; |
| 231 const std::string expected_value_; |
| 232 |
| 233 base::RunLoop run_loop_; |
| 234 PrefChangeRegistrar pref_change_registrar_; |
| 235 |
| 236 DISALLOW_COPY_AND_ASSIGN(DictionaryPrefValueWaiter); |
| 237 }; |
| 238 |
| 212 TestingUpdateManifestProvider::Update::Update(const std::string& version, | 239 TestingUpdateManifestProvider::Update::Update(const std::string& version, |
| 213 const GURL& crx_url) | 240 const GURL& crx_url) |
| 214 : version(version), | 241 : version(version), |
| 215 crx_url(crx_url) { | 242 crx_url(crx_url) { |
| 216 } | 243 } |
| 217 | 244 |
| 218 TestingUpdateManifestProvider::Update::Update() { | 245 TestingUpdateManifestProvider::Update::Update() { |
| 219 } | 246 } |
| 220 | 247 |
| 221 TestingUpdateManifestProvider::TestingUpdateManifestProvider( | 248 TestingUpdateManifestProvider::TestingUpdateManifestProvider( |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 285 } |
| 259 content += kUpdateManifestFooter; | 286 content += kUpdateManifestFooter; |
| 260 scoped_ptr<net::test_server::BasicHttpResponse> | 287 scoped_ptr<net::test_server::BasicHttpResponse> |
| 261 http_response(new net::test_server::BasicHttpResponse); | 288 http_response(new net::test_server::BasicHttpResponse); |
| 262 http_response->set_code(net::HTTP_OK); | 289 http_response->set_code(net::HTTP_OK); |
| 263 http_response->set_content(content); | 290 http_response->set_content(content); |
| 264 http_response->set_content_type("text/xml"); | 291 http_response->set_content_type("text/xml"); |
| 265 return http_response.PassAs<net::test_server::HttpResponse>(); | 292 return http_response.PassAs<net::test_server::HttpResponse>(); |
| 266 } | 293 } |
| 267 | 294 |
| 295 DictionaryPrefValueWaiter::DictionaryPrefValueWaiter( |
| 296 const std::string& pref, |
| 297 const std::string& key, |
| 298 const std::string& expected_value) |
| 299 : pref_(pref), |
| 300 key_(key), |
| 301 expected_value_(expected_value) { |
| 302 pref_change_registrar_.Init(g_browser_process->local_state()); |
| 303 } |
| 304 |
| 305 DictionaryPrefValueWaiter::~DictionaryPrefValueWaiter() { |
| 306 } |
| 307 |
| 308 void DictionaryPrefValueWaiter::Wait() { |
| 309 pref_change_registrar_.Add( |
| 310 pref_.c_str(), |
| 311 base::Bind(&DictionaryPrefValueWaiter::QuitLoopIfExpectedValueFound, |
| 312 base::Unretained(this))); |
| 313 QuitLoopIfExpectedValueFound(); |
| 314 run_loop_.Run(); |
| 315 } |
| 316 |
| 317 void DictionaryPrefValueWaiter::QuitLoopIfExpectedValueFound() { |
| 318 const base::DictionaryValue* pref = |
| 319 pref_change_registrar_.prefs()->GetDictionary(pref_.c_str()); |
| 320 ASSERT_TRUE(pref); |
| 321 std::string actual_value; |
| 322 if (pref->GetStringWithoutPathExpansion(key_, &actual_value) && |
| 323 actual_value == expected_value_) { |
| 324 run_loop_.Quit(); |
| 325 } |
| 326 } |
| 327 |
| 268 bool DoesInstallSuccessReferToId(const std::string& id, | 328 bool DoesInstallSuccessReferToId(const std::string& id, |
| 269 const content::NotificationSource& source, | 329 const content::NotificationSource& source, |
| 270 const content::NotificationDetails& details) { | 330 const content::NotificationDetails& details) { |
| 271 return content::Details<const extensions::InstalledExtensionInfo>(details)-> | 331 return content::Details<const extensions::InstalledExtensionInfo>(details)-> |
| 272 extension->id() == id; | 332 extension->id() == id; |
| 273 } | 333 } |
| 274 | 334 |
| 275 bool DoesInstallFailureReferToId(const std::string& id, | 335 bool DoesInstallFailureReferToId(const std::string& id, |
| 276 const content::NotificationSource& source, | 336 const content::NotificationSource& source, |
| 277 const content::NotificationDetails& details) { | 337 const content::NotificationDetails& details) { |
| 278 return content::Details<const base::string16>(details)-> | 338 return content::Details<const base::string16>(details)-> |
| 279 find(base::UTF8ToUTF16(id)) != base::string16::npos; | 339 find(base::UTF8ToUTF16(id)) != base::string16::npos; |
| 280 } | 340 } |
| 281 | 341 |
| 282 scoped_ptr<net::FakeURLFetcher> RunCallbackAndReturnFakeURLFetcher( | 342 scoped_ptr<net::FakeURLFetcher> RunCallbackAndReturnFakeURLFetcher( |
| 283 scoped_refptr<base::SequencedTaskRunner> task_runner, | 343 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 284 const base::Closure& callback, | 344 const base::Closure& callback, |
| 285 const GURL& url, | 345 const GURL& url, |
| 286 net::URLFetcherDelegate* delegate, | 346 net::URLFetcherDelegate* delegate, |
| 287 const std::string& response_data, | 347 const std::string& response_data, |
| 288 net::HttpStatusCode response_code, | 348 net::HttpStatusCode response_code, |
| 289 net::URLRequestStatus::Status status) { | 349 net::URLRequestStatus::Status status) { |
| 290 task_runner->PostTask(FROM_HERE, callback); | 350 task_runner->PostTask(FROM_HERE, callback); |
| 291 return make_scoped_ptr(new net::FakeURLFetcher( | 351 return make_scoped_ptr(new net::FakeURLFetcher( |
| 292 url, delegate, response_data, response_code, status)); | 352 url, delegate, response_data, response_code, status)); |
| 293 } | 353 } |
| 294 | 354 |
| 295 bool DisplayNameMatches(const std::string& account_id, | |
| 296 const std::string& display_name) { | |
| 297 const user_manager::User* user = | |
| 298 chromeos::UserManager::Get()->FindUser(account_id); | |
| 299 if (!user || user->display_name().empty()) | |
| 300 return false; | |
| 301 EXPECT_EQ(base::UTF8ToUTF16(display_name), user->display_name()); | |
| 302 return true; | |
| 303 } | |
| 304 | |
| 305 bool IsSessionStarted() { | 355 bool IsSessionStarted() { |
| 306 return chromeos::UserManager::Get()->IsSessionStarted(); | 356 return chromeos::UserManager::Get()->IsSessionStarted(); |
| 307 } | 357 } |
| 308 | 358 |
| 309 } // namespace | 359 } // namespace |
| 310 | 360 |
| 311 class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest, | 361 class DeviceLocalAccountTest : public DevicePolicyCrosBrowserTest, |
| 312 public chromeos::UserManager::Observer, | 362 public chromeos::UserManager::Observer, |
| 313 public chrome::BrowserListObserver, | 363 public chrome::BrowserListObserver, |
| 314 public apps::AppWindowRegistry::Observer { | 364 public apps::AppWindowRegistry::Observer { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 452 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 403 proto.mutable_show_user_names()->set_show_user_names(true); | 453 proto.mutable_show_user_names()->set_show_user_names(true); |
| 404 | 454 |
| 405 device_local_account_policy_.policy_data().set_policy_type( | 455 device_local_account_policy_.policy_data().set_policy_type( |
| 406 dm_protocol::kChromePublicAccountPolicyType); | 456 dm_protocol::kChromePublicAccountPolicyType); |
| 407 device_local_account_policy_.policy_data().set_username(kAccountId1); | 457 device_local_account_policy_.policy_data().set_username(kAccountId1); |
| 408 device_local_account_policy_.policy_data().set_settings_entity_id( | 458 device_local_account_policy_.policy_data().set_settings_entity_id( |
| 409 kAccountId1); | 459 kAccountId1); |
| 410 device_local_account_policy_.policy_data().set_public_key_version(1); | 460 device_local_account_policy_.policy_data().set_public_key_version(1); |
| 411 device_local_account_policy_.payload().mutable_userdisplayname()->set_value( | 461 device_local_account_policy_.payload().mutable_userdisplayname()->set_value( |
| 412 kDisplayName); | 462 kDisplayName1); |
| 413 } | 463 } |
| 414 | 464 |
| 415 void BuildDeviceLocalAccountPolicy() { | 465 void BuildDeviceLocalAccountPolicy() { |
| 416 device_local_account_policy_.SetDefaultSigningKey(); | 466 device_local_account_policy_.SetDefaultSigningKey(); |
| 417 device_local_account_policy_.Build(); | 467 device_local_account_policy_.Build(); |
| 418 } | 468 } |
| 419 | 469 |
| 420 void UploadDeviceLocalAccountPolicy() { | 470 void UploadDeviceLocalAccountPolicy() { |
| 421 BuildDeviceLocalAccountPolicy(); | 471 BuildDeviceLocalAccountPolicy(); |
| 422 test_server_.UpdatePolicy( | 472 test_server_.UpdatePolicy( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 return GetExtensionCacheDirectoryForAccountID(account_id) | 516 return GetExtensionCacheDirectoryForAccountID(account_id) |
| 467 .Append(base::StringPrintf("%s-%s.crx", id.c_str(), version.c_str())); | 517 .Append(base::StringPrintf("%s-%s.crx", id.c_str(), version.c_str())); |
| 468 } | 518 } |
| 469 | 519 |
| 470 // Returns a profile which can be used for testing. | 520 // Returns a profile which can be used for testing. |
| 471 Profile* GetProfileForTest() { | 521 Profile* GetProfileForTest() { |
| 472 // Any profile can be used here since this test does not test multi profile. | 522 // Any profile can be used here since this test does not test multi profile. |
| 473 return ProfileManager::GetActiveUserProfile(); | 523 return ProfileManager::GetActiveUserProfile(); |
| 474 } | 524 } |
| 475 | 525 |
| 526 void WaitForDisplayName(const std::string& user_id, |
| 527 const std::string& expected_display_name) { |
| 528 DictionaryPrefValueWaiter("UserDisplayName", |
| 529 user_id, |
| 530 expected_display_name).Wait(); |
| 531 } |
| 532 |
| 476 void WaitForPolicy() { | 533 void WaitForPolicy() { |
| 477 // This observes the display name becoming available as this indicates | 534 // Wait for the display name becoming available as that indicates |
| 478 // device-local account policy is fully loaded, which is a prerequisite for | 535 // device-local account policy is fully loaded, which is a prerequisite for |
| 479 // successful login. | 536 // successful login. |
| 480 content::WindowedNotificationObserver( | 537 WaitForDisplayName(user_id_1_, kDisplayName1); |
| 481 chrome::NOTIFICATION_USER_LIST_CHANGED, | |
| 482 base::Bind(&DisplayNameMatches, user_id_1_, kDisplayName)).Wait(); | |
| 483 } | 538 } |
| 484 | 539 |
| 485 void GetWebContents(content::WebContents** contents) { | 540 void GetWebContents(content::WebContents** contents) { |
| 486 chromeos::LoginDisplayHostImpl* host = | 541 chromeos::LoginDisplayHostImpl* host = |
| 487 reinterpret_cast<chromeos::LoginDisplayHostImpl*>( | 542 reinterpret_cast<chromeos::LoginDisplayHostImpl*>( |
| 488 chromeos::LoginDisplayHostImpl::default_host()); | 543 chromeos::LoginDisplayHostImpl::default_host()); |
| 489 ASSERT_TRUE(host); | 544 ASSERT_TRUE(host); |
| 490 chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView(); | 545 chromeos::WebUILoginView* web_ui_login_view = host->GetWebUILoginView(); |
| 491 ASSERT_TRUE(web_ui_login_view); | 546 ASSERT_TRUE(web_ui_login_view); |
| 492 content::WebUI* web_ui = web_ui_login_view->GetWebUI(); | 547 content::WebUI* web_ui = web_ui_login_view->GetWebUI(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 return chromeos::UserManager::Get()->IsKnownUser(account_id); | 627 return chromeos::UserManager::Get()->IsKnownUser(account_id); |
| 573 } | 628 } |
| 574 | 629 |
| 575 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { | 630 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { |
| 576 AddPublicSessionToDevicePolicy(kAccountId1); | 631 AddPublicSessionToDevicePolicy(kAccountId1); |
| 577 AddPublicSessionToDevicePolicy(kAccountId2); | 632 AddPublicSessionToDevicePolicy(kAccountId2); |
| 578 | 633 |
| 579 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, | 634 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, |
| 580 base::Bind(&IsKnownUser, user_id_1_)) | 635 base::Bind(&IsKnownUser, user_id_1_)) |
| 581 .Wait(); | 636 .Wait(); |
| 582 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, | 637 EXPECT_TRUE(IsKnownUser(user_id_2_)); |
| 583 base::Bind(&IsKnownUser, user_id_2_)) | |
| 584 .Wait(); | |
| 585 | 638 |
| 586 CheckPublicSessionPresent(user_id_1_); | 639 CheckPublicSessionPresent(user_id_1_); |
| 587 CheckPublicSessionPresent(user_id_2_); | 640 CheckPublicSessionPresent(user_id_2_); |
| 588 } | 641 } |
| 589 | 642 |
| 590 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) { | 643 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DisplayName) { |
| 591 UploadAndInstallDeviceLocalAccountPolicy(); | 644 UploadAndInstallDeviceLocalAccountPolicy(); |
| 592 AddPublicSessionToDevicePolicy(kAccountId1); | 645 AddPublicSessionToDevicePolicy(kAccountId1); |
| 593 | 646 |
| 594 WaitForPolicy(); | 647 WaitForPolicy(); |
| 648 |
| 649 // Skip to the login screen. |
| 650 chromeos::WizardController* wizard_controller = |
| 651 chromeos::WizardController::default_controller(); |
| 652 ASSERT_TRUE(wizard_controller); |
| 653 wizard_controller->SkipToLoginForTesting(LoginScreenContext()); |
| 654 content::WindowedNotificationObserver( |
| 655 chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, |
| 656 content::NotificationService::AllSources()).Wait(); |
| 657 |
| 658 // Verify that the display name is shown in the UI. |
| 659 content::WebContents* contents = NULL; |
| 660 ASSERT_NO_FATAL_FAILURE(GetWebContents(&contents)); |
| 661 const std::string get_compact_pod_display_name = base::StringPrintf( |
| 662 "domAutomationController.send(document.getElementById('pod-row')" |
| 663 " .getPodWithUsername_('%s').nameElement.textContent);", |
| 664 user_id_1_.c_str()); |
| 665 std::string display_name; |
| 666 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 667 contents, |
| 668 get_compact_pod_display_name, |
| 669 &display_name)); |
| 670 EXPECT_EQ(kDisplayName1, display_name); |
| 671 const std::string get_expanded_pod_display_name = base::StringPrintf( |
| 672 "domAutomationController.send(document.getElementById('pod-row')" |
| 673 " .getPodWithUsername_('%s').querySelector('.expanded-pane-name')" |
| 674 " .textContent);", |
| 675 user_id_1_.c_str()); |
| 676 display_name.clear(); |
| 677 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 678 contents, |
| 679 get_expanded_pod_display_name, |
| 680 &display_name)); |
| 681 EXPECT_EQ(kDisplayName1, display_name); |
| 682 |
| 683 // Click on the pod to expand it. |
| 684 ASSERT_TRUE(content::ExecuteScript( |
| 685 contents, |
| 686 base::StringPrintf( |
| 687 "document.getElementById('pod-row').getPodWithUsername_('%s')" |
| 688 " .click();", |
| 689 user_id_1_.c_str()))); |
| 690 |
| 691 // Change the display name. |
| 692 device_local_account_policy_.payload().mutable_userdisplayname()->set_value( |
| 693 kDisplayName2); |
| 694 UploadAndInstallDeviceLocalAccountPolicy(); |
| 695 policy::BrowserPolicyConnectorChromeOS* connector = |
| 696 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 697 DeviceLocalAccountPolicyBroker* broker = |
| 698 connector->GetDeviceLocalAccountPolicyService()->GetBrokerForUser( |
| 699 user_id_1_); |
| 700 ASSERT_TRUE(broker); |
| 701 broker->core()->store()->Load(); |
| 702 WaitForDisplayName(user_id_1_, kDisplayName2); |
| 703 |
| 704 // Verify that the new display name is shown in the UI. |
| 705 display_name.clear(); |
| 706 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 707 contents, |
| 708 get_compact_pod_display_name, |
| 709 &display_name)); |
| 710 EXPECT_EQ(kDisplayName2, display_name); |
| 711 display_name.clear(); |
| 712 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 713 contents, |
| 714 get_expanded_pod_display_name, |
| 715 &display_name)); |
| 716 EXPECT_EQ(kDisplayName2, display_name); |
| 717 |
| 718 // Verify that the pod is still expanded. This indicates that the UI updated |
| 719 // without reloading and losing state. |
| 720 bool expanded = false; |
| 721 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( |
| 722 contents, |
| 723 base::StringPrintf( |
| 724 "domAutomationController.send(document.getElementById('pod-row')" |
| 725 " .getPodWithUsername_('%s').expanded);", |
| 726 user_id_1_.c_str()), |
| 727 &expanded)); |
| 728 EXPECT_TRUE(expanded); |
| 595 } | 729 } |
| 596 | 730 |
| 597 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyDownload) { | 731 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, PolicyDownload) { |
| 598 UploadDeviceLocalAccountPolicy(); | 732 UploadDeviceLocalAccountPolicy(); |
| 599 AddPublicSessionToDevicePolicy(kAccountId1); | 733 AddPublicSessionToDevicePolicy(kAccountId1); |
| 600 | 734 |
| 601 WaitForPolicy(); | 735 WaitForPolicy(); |
| 602 | 736 |
| 603 // Sanity check: The policy should be present now. | 737 // Sanity check: The policy should be present now. |
| 604 ASSERT_FALSE(session_manager_client()->device_local_account_policy( | 738 ASSERT_FALSE(session_manager_client()->device_local_account_policy( |
| 605 kAccountId1).empty()); | 739 kAccountId1).empty()); |
| 606 } | 740 } |
| 607 | 741 |
| 608 static bool IsNotKnownUser(const std::string& account_id) { | 742 static bool IsNotKnownUser(const std::string& account_id) { |
| 609 return !IsKnownUser(account_id); | 743 return !IsKnownUser(account_id); |
| 610 } | 744 } |
| 611 | 745 |
| 612 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, DevicePolicyChange) { | 746 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, AccountListChange) { |
| 613 AddPublicSessionToDevicePolicy(kAccountId1); | 747 AddPublicSessionToDevicePolicy(kAccountId1); |
| 614 AddPublicSessionToDevicePolicy(kAccountId2); | 748 AddPublicSessionToDevicePolicy(kAccountId2); |
| 615 | 749 |
| 616 // Wait until the login screen is up. | |
| 617 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, | 750 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, |
| 618 base::Bind(&IsKnownUser, user_id_1_)) | 751 base::Bind(&IsKnownUser, user_id_1_)) |
| 619 .Wait(); | 752 .Wait(); |
| 620 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, | 753 EXPECT_TRUE(IsKnownUser(user_id_2_)); |
| 621 base::Bind(&IsKnownUser, user_id_2_)) | |
| 622 .Wait(); | |
| 623 | 754 |
| 624 // Update policy to remove kAccountId2. | 755 // Update policy to remove kAccountId2. |
| 625 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 756 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 626 proto.mutable_device_local_accounts()->clear_account(); | 757 proto.mutable_device_local_accounts()->clear_account(); |
| 627 AddPublicSessionToDevicePolicy(kAccountId1); | 758 AddPublicSessionToDevicePolicy(kAccountId1); |
| 628 | 759 |
| 629 em::ChromeDeviceSettingsProto policy; | 760 em::ChromeDeviceSettingsProto policy; |
| 630 policy.mutable_show_user_names()->set_show_user_names(true); | 761 policy.mutable_show_user_names()->set_show_user_names(true); |
| 631 em::DeviceLocalAccountInfoProto* account1 = | 762 em::DeviceLocalAccountInfoProto* account1 = |
| 632 policy.mutable_device_local_accounts()->add_account(); | 763 policy.mutable_device_local_accounts()->add_account(); |
| 633 account1->set_account_id(kAccountId1); | 764 account1->set_account_id(kAccountId1); |
| 634 account1->set_type( | 765 account1->set_type( |
| 635 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); | 766 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); |
| 636 | 767 |
| 637 test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType, std::string(), | 768 test_server_.UpdatePolicy(dm_protocol::kChromeDevicePolicyType, std::string(), |
| 638 policy.SerializeAsString()); | 769 policy.SerializeAsString()); |
| 639 g_browser_process->policy_service()->RefreshPolicies(base::Closure()); | 770 g_browser_process->policy_service()->RefreshPolicies(base::Closure()); |
| 640 | 771 |
| 641 // Make sure the second device-local account disappears. | 772 // Make sure the second device-local account disappears. |
| 642 content::WindowedNotificationObserver( | 773 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, |
| 643 chrome::NOTIFICATION_USER_LIST_CHANGED, | 774 base::Bind(&IsNotKnownUser, user_id_2_)) |
| 644 base::Bind(&IsNotKnownUser, user_id_2_)).Wait(); | 775 .Wait(); |
| 645 } | 776 } |
| 646 | 777 |
| 647 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) { | 778 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, StartSession) { |
| 648 // Specify startup pages. | 779 // Specify startup pages. |
| 649 device_local_account_policy_.payload().mutable_restoreonstartup()->set_value( | 780 device_local_account_policy_.payload().mutable_restoreonstartup()->set_value( |
| 650 SessionStartupPref::kPrefValueURLs); | 781 SessionStartupPref::kPrefValueURLs); |
| 651 em::StringListPolicyProto* startup_urls_proto = | 782 em::StringListPolicyProto* startup_urls_proto = |
| 652 device_local_account_policy_.payload().mutable_restoreonstartupurls(); | 783 device_local_account_policy_.payload().mutable_restoreonstartupurls(); |
| 653 for (size_t i = 0; i < arraysize(kStartupURLs); ++i) | 784 for (size_t i = 0; i < arraysize(kStartupURLs); ++i) |
| 654 startup_urls_proto->mutable_value()->add_entries(kStartupURLs[i]); | 785 startup_urls_proto->mutable_value()->add_entries(kStartupURLs[i]); |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1442 ASSERT_TRUE(content::ExecuteScript(contents, | 1573 ASSERT_TRUE(content::ExecuteScript(contents, |
| 1443 "$('tos-accept-button').click();")); | 1574 "$('tos-accept-button').click();")); |
| 1444 | 1575 |
| 1445 WaitForSessionStart(); | 1576 WaitForSessionStart(); |
| 1446 } | 1577 } |
| 1447 | 1578 |
| 1448 INSTANTIATE_TEST_CASE_P(TermsOfServiceDownloadTestInstance, | 1579 INSTANTIATE_TEST_CASE_P(TermsOfServiceDownloadTestInstance, |
| 1449 TermsOfServiceDownloadTest, testing::Bool()); | 1580 TermsOfServiceDownloadTest, testing::Bool()); |
| 1450 | 1581 |
| 1451 } // namespace policy | 1582 } // namespace policy |
| OLD | NEW |