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

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller_browsertest.cc

Issue 23494053: Remove NOTIFICATION_SYSTEM_SETTING_CHANGED, switch CrosSettings to base::CallbackRegistry. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: trailing space Created 7 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/memory/ref_counted.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/chromeos/login/authenticator.h" 15 #include "chrome/browser/chromeos/login/authenticator.h"
15 #include "chrome/browser/chromeos/login/existing_user_controller.h" 16 #include "chrome/browser/chromeos/login/existing_user_controller.h"
16 #include "chrome/browser/chromeos/login/helper.h" 17 #include "chrome/browser/chromeos/login/helper.h"
17 #include "chrome/browser/chromeos/login/mock_authenticator.h" 18 #include "chrome/browser/chromeos/login/mock_authenticator.h"
18 #include "chrome/browser/chromeos/login/mock_login_display.h" 19 #include "chrome/browser/chromeos/login/mock_login_display.h"
19 #include "chrome/browser/chromeos/login/mock_login_display_host.h" 20 #include "chrome/browser/chromeos/login/mock_login_display_host.h"
20 #include "chrome/browser/chromeos/login/mock_login_utils.h" 21 #include "chrome/browser/chromeos/login/mock_login_utils.h"
21 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" 22 #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) 446 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
446 .Times(1); 447 .Times(1);
447 EXPECT_CALL(*mock_login_display_, OnFadeOut()) 448 EXPECT_CALL(*mock_login_display_, OnFadeOut())
448 .Times(1); 449 .Times(1);
449 EXPECT_CALL(*mock_login_display_host_, 450 EXPECT_CALL(*mock_login_display_host_,
450 StartWizardPtr(WizardController::kTermsOfServiceScreenName, 451 StartWizardPtr(WizardController::kTermsOfServiceScreenName,
451 NULL)) 452 NULL))
452 .Times(0); 453 .Times(0);
453 } 454 }
454 455
455 scoped_ptr<base::RunLoop> CreateSettingsObserverRunLoop(
456 content::MockNotificationObserver& observer, const char* setting) {
457 base::RunLoop* loop = new base::RunLoop;
458 EXPECT_CALL(observer, Observe(chrome::NOTIFICATION_SYSTEM_SETTING_CHANGED,
459 _, HasDetails(setting)))
460 .Times(1)
461 .WillOnce(InvokeWithoutArgs(loop, &base::RunLoop::Quit));
462 CrosSettings::Get()->AddSettingsObserver(setting, &observer);
463 return make_scoped_ptr(loop);
464 }
465
466 void SetAutoLoginPolicy(const std::string& username, int delay) { 456 void SetAutoLoginPolicy(const std::string& username, int delay) {
467 // Wait until ExistingUserController has finished auto-login 457 // Wait until ExistingUserController has finished auto-login
468 // configuration by observing the same settings that trigger 458 // configuration by observing the same settings that trigger
469 // ConfigurePublicSessionAutoLogin. 459 // ConfigurePublicSessionAutoLogin.
470 content::MockNotificationObserver observer;
471 460
472 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); 461 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
473 462
474 // If both settings have changed we need to wait for both to 463 // If both settings have changed we need to wait for both to
475 // propagate, so check the new values against the old ones. 464 // propagate, so check the new values against the old ones.
476 scoped_ptr<base::RunLoop> runner1; 465 scoped_refptr<content::MessageLoopRunner> runner1;
466 scoped_ptr<CrosSettings::ObserverSubscription> subscription1;
477 if (!proto.has_device_local_accounts() || 467 if (!proto.has_device_local_accounts() ||
478 !proto.device_local_accounts().has_auto_login_id() || 468 !proto.device_local_accounts().has_auto_login_id() ||
479 proto.device_local_accounts().auto_login_id() != username) { 469 proto.device_local_accounts().auto_login_id() != username) {
480 runner1 = CreateSettingsObserverRunLoop( 470 runner1 = new content::MessageLoopRunner;
481 observer, kAccountsPrefDeviceLocalAccountAutoLoginId); 471 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver(
472 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId,
473 runner1->QuitClosure());
482 } 474 }
483 scoped_ptr<base::RunLoop> runner2; 475 scoped_refptr<content::MessageLoopRunner> runner2;
476 scoped_ptr<CrosSettings::ObserverSubscription> subscription2;
484 if (!proto.has_device_local_accounts() || 477 if (!proto.has_device_local_accounts() ||
485 !proto.device_local_accounts().has_auto_login_delay() || 478 !proto.device_local_accounts().has_auto_login_delay() ||
486 proto.device_local_accounts().auto_login_delay() != delay) { 479 proto.device_local_accounts().auto_login_delay() != delay) {
487 runner2 = CreateSettingsObserverRunLoop( 480 runner1 = new content::MessageLoopRunner;
488 observer, kAccountsPrefDeviceLocalAccountAutoLoginDelay); 481 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver(
482 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay,
483 runner1->QuitClosure());
489 } 484 }
490 485
491 // Update the policy. 486 // Update the policy.
492 proto.mutable_device_local_accounts()->set_auto_login_id(username); 487 proto.mutable_device_local_accounts()->set_auto_login_id(username);
493 proto.mutable_device_local_accounts()->set_auto_login_delay(delay); 488 proto.mutable_device_local_accounts()->set_auto_login_delay(delay);
494 RefreshDevicePolicy(); 489 RefreshDevicePolicy();
495 490
496 // Wait for ExistingUserController to read the updated settings. 491 // Wait for ExistingUserController to read the updated settings.
497 if (runner1) 492 if (runner1.get())
498 runner1->Run(); 493 runner1->Run();
499 if (runner2) 494 if (runner2.get())
500 runner2->Run(); 495 runner2->Run();
501
502 // Clean up.
503 CrosSettings::Get()->RemoveSettingsObserver(
504 kAccountsPrefDeviceLocalAccountAutoLoginId,
505 &observer);
506 CrosSettings::Get()->RemoveSettingsObserver(
507 kAccountsPrefDeviceLocalAccountAutoLoginDelay,
508 &observer);
509 } 496 }
510 497
511 void ConfigureAutoLogin() { 498 void ConfigureAutoLogin() {
512 existing_user_controller()->ConfigurePublicSessionAutoLogin(); 499 existing_user_controller()->ConfigurePublicSessionAutoLogin();
513 } 500 }
514 501
515 void FireAutoLogin() { 502 void FireAutoLogin() {
516 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); 503 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
517 } 504 }
518 505
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 665
679 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation, 666 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation,
680 ExistingUserControllerTest, 667 ExistingUserControllerTest,
681 testing::Bool()); 668 testing::Bool());
682 669
683 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation, 670 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation,
684 ExistingUserControllerPublicSessionTest, 671 ExistingUserControllerPublicSessionTest,
685 testing::Bool()); 672 testing::Bool());
686 673
687 } // namespace chromeos 674 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698