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

Side by Side Diff: chrome/browser/ui/ash/session_controller_client_unittest.cc

Issue 2842693002: cros: Don't send duplicate UserSession mojo messages to ash (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/ui/ash/session_controller_client.h" 5 #include "chrome/browser/ui/ash/session_controller_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 ash::mojom::SessionInfo* last_session_info() { 82 ash::mojom::SessionInfo* last_session_info() {
83 return last_session_info_.get(); 83 return last_session_info_.get();
84 } 84 }
85 85
86 ash::mojom::UserSession* last_user_session() { 86 ash::mojom::UserSession* last_user_session() {
87 return last_user_session_.get(); 87 return last_user_session_.get();
88 } 88 }
89 89
90 int update_user_session_count() { return update_user_session_count_; }
91
90 // ash::mojom::SessionController: 92 // ash::mojom::SessionController:
91 void SetClient(ash::mojom::SessionControllerClientPtr client) override {} 93 void SetClient(ash::mojom::SessionControllerClientPtr client) override {}
92 void SetSessionInfo(ash::mojom::SessionInfoPtr info) override { 94 void SetSessionInfo(ash::mojom::SessionInfoPtr info) override {
93 last_session_info_ = info->Clone(); 95 last_session_info_ = info->Clone();
94 } 96 }
95 void UpdateUserSession(ash::mojom::UserSessionPtr user_session) override { 97 void UpdateUserSession(ash::mojom::UserSessionPtr user_session) override {
96 last_user_session_ = user_session->Clone(); 98 last_user_session_ = user_session->Clone();
99 update_user_session_count_++;
xiyuan 2017/04/25 16:04:53 nit: pre-increment, i.e. ++update_user_session_cou
97 } 100 }
98 void SetUserSessionOrder( 101 void SetUserSessionOrder(
99 const std::vector<uint32_t>& user_session_order) override {} 102 const std::vector<uint32_t>& user_session_order) override {}
100 void StartLock(const StartLockCallback& callback) override {} 103 void StartLock(const StartLockCallback& callback) override {}
101 void NotifyChromeLockAnimationsComplete() override {} 104 void NotifyChromeLockAnimationsComplete() override {}
102 void RunUnlockAnimation(const RunUnlockAnimationCallback& callback) override { 105 void RunUnlockAnimation(const RunUnlockAnimationCallback& callback) override {
103 } 106 }
104 void NotifyChromeTerminating() override {} 107 void NotifyChromeTerminating() override {}
105 108
106 private: 109 private:
107 mojo::Binding<ash::mojom::SessionController> binding_; 110 mojo::Binding<ash::mojom::SessionController> binding_;
108 111
109 ash::mojom::SessionInfoPtr last_session_info_; 112 ash::mojom::SessionInfoPtr last_session_info_;
110 ash::mojom::UserSessionPtr last_user_session_; 113 ash::mojom::UserSessionPtr last_user_session_;
114 int update_user_session_count_ = 0;
111 115
112 DISALLOW_COPY_AND_ASSIGN(TestSessionController); 116 DISALLOW_COPY_AND_ASSIGN(TestSessionController);
113 }; 117 };
114 118
115 } // namespace 119 } // namespace
116 120
117 class SessionControllerClientTest : public testing::Test { 121 class SessionControllerClientTest : public testing::Test {
118 protected: 122 protected:
119 SessionControllerClientTest() {} 123 SessionControllerClientTest() {}
120 ~SessionControllerClientTest() override {} 124 ~SessionControllerClientTest() override {}
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 const AccountId account_id(AccountId::FromUserEmail(kUser)); 358 const AccountId account_id(AccountId::FromUserEmail(kUser));
355 user_manager()->LoginUser(account_id); 359 user_manager()->LoginUser(account_id);
356 user_profile_->GetPrefs()->SetString( 360 user_profile_->GetPrefs()->SetString(
357 prefs::kMultiProfileUserBehavior, 361 prefs::kMultiProfileUserBehavior,
358 chromeos::MultiProfileUserController::kBehaviorNotAllowed); 362 chromeos::MultiProfileUserController::kBehaviorNotAllowed);
359 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b")); 363 user_manager()->AddUser(AccountId::FromUserEmail("bb@b.b"));
360 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER, 364 EXPECT_EQ(ash::AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER,
361 SessionControllerClient::GetAddUserSessionPolicy()); 365 SessionControllerClient::GetAddUserSessionPolicy());
362 } 366 }
363 367
368 TEST_F(SessionControllerClientTest, SendUserSession) {
369 // Create an object to test and connect it to our test interface.
370 SessionControllerClient client;
371 TestSessionController session_controller;
372 client.session_controller_ = session_controller.CreateInterfacePtrAndBind();
373 client.Init();
374 SessionControllerClient::FlushForTesting();
375
376 // No user session sent yet.
377 EXPECT_EQ(0, session_controller.update_user_session_count());
378
379 // Simulate login.
380 const AccountId account_id(AccountId::FromUserEmail("user@test.com"));
381 user_manager()->AddUser(account_id);
382 session_manager_.CreateSession(
383 account_id, chromeos::ProfileHelper::GetUserIdHashByUserIdForTesting(
384 "user@test.com"));
385 SessionControllerClient::FlushForTesting();
386
387 // User session was sent.
388 EXPECT_EQ(1, session_controller.update_user_session_count());
389
390 // Simulate a request for an update where nothing changed.
391 client.SendUserSession(*user_manager()->GetLoggedInUsers()[0]);
392 SessionControllerClient::FlushForTesting();
393
394 // Session was not updated because nothing changed.
395 EXPECT_EQ(1, session_controller.update_user_session_count());
396 }
397
364 TEST_F(SessionControllerClientTest, SupervisedUser) { 398 TEST_F(SessionControllerClientTest, SupervisedUser) {
365 // Create an object to test and connect it to our test interface. 399 // Create an object to test and connect it to our test interface.
366 SessionControllerClient client; 400 SessionControllerClient client;
367 TestSessionController session_controller; 401 TestSessionController session_controller;
368 client.session_controller_ = session_controller.CreateInterfacePtrAndBind(); 402 client.session_controller_ = session_controller.CreateInterfacePtrAndBind();
369 client.Init(); 403 client.Init();
370 SessionControllerClient::FlushForTesting(); 404 SessionControllerClient::FlushForTesting();
371 405
372 // Simulate the login screen. No user session yet. 406 // Simulate the login screen. No user session yet.
373 session_manager_.SetSessionState( 407 session_manager_.SetSessionState(
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 448
415 // Simulate an update to the custodian information. 449 // Simulate an update to the custodian information.
416 prefs->SetString(prefs::kSupervisedUserCustodianEmail, "parent3@test.com"); 450 prefs->SetString(prefs::kSupervisedUserCustodianEmail, "parent3@test.com");
417 client.OnCustodianInfoChanged(); 451 client.OnCustodianInfoChanged();
418 SessionControllerClient::FlushForTesting(); 452 SessionControllerClient::FlushForTesting();
419 453
420 // The updated custodian was sent over the mojo interface. 454 // The updated custodian was sent over the mojo interface.
421 EXPECT_EQ("parent3@test.com", 455 EXPECT_EQ("parent3@test.com",
422 session_controller.last_user_session()->custodian_email); 456 session_controller.last_user_session()->custodian_email);
423 } 457 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698