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

Side by Side Diff: chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos_unittest.cc

Issue 2895713002: [mus+ash] Removes WmWindow from ash/wm/mru_window_tracker and overview mode (Closed)
Patch Set: Address nits, unit_tests target compiles Created 3 years, 6 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "ash/content/shell_content_state.h" 7 #include "ash/content/shell_content_state.h"
8 #include "ash/public/cpp/shell_window_ids.h" 8 #include "ash/public/cpp/shell_window_ids.h"
9 #include "ash/shelf/shelf_widget.h" 9 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shelf/wm_shelf.h" 10 #include "ash/shelf/wm_shelf.h"
(...skipping 30 matching lines...) Expand all
41 #include "chrome/browser/ui/browser.h" 41 #include "chrome/browser/ui/browser.h"
42 #include "chrome/browser/ui/browser_list.h" 42 #include "chrome/browser/ui/browser_list.h"
43 #include "chrome/test/base/test_browser_window_aura.h" 43 #include "chrome/test/base/test_browser_window_aura.h"
44 #include "chrome/test/base/testing_browser_process.h" 44 #include "chrome/test/base/testing_browser_process.h"
45 #include "chrome/test/base/testing_profile.h" 45 #include "chrome/test/base/testing_profile.h"
46 #include "chrome/test/base/testing_profile_manager.h" 46 #include "chrome/test/base/testing_profile_manager.h"
47 #include "components/signin/core/account_id/account_id.h" 47 #include "components/signin/core/account_id/account_id.h"
48 #include "components/user_manager/user_info.h" 48 #include "components/user_manager/user_info.h"
49 #include "components/user_manager/user_manager.h" 49 #include "components/user_manager/user_manager.h"
50 #include "ui/aura/client/aura_constants.h" 50 #include "ui/aura/client/aura_constants.h"
51 #include "ui/aura/window.h"
51 #include "ui/aura/window_event_dispatcher.h" 52 #include "ui/aura/window_event_dispatcher.h"
52 #include "ui/base/ui_base_types.h" 53 #include "ui/base/ui_base_types.h"
53 #include "ui/wm/core/window_modality_controller.h" 54 #include "ui/wm/core/window_modality_controller.h"
54 #include "ui/wm/core/window_util.h" 55 #include "ui/wm/core/window_util.h"
55 #include "ui/wm/public/activation_client.h" 56 #include "ui/wm/public/activation_client.h"
56 57
57 namespace { 58 namespace {
58 59
59 const char kAAccountIdString[] = 60 const char kAAccountIdString[] =
60 "{\"account_type\":\"unknown\",\"email\":\"A\"}"; 61 "{\"account_type\":\"unknown\",\"email\":\"A\"}";
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 base::TimeTicks now = base::TimeTicks::Now(); 165 base::TimeTicks now = base::TimeTicks::Now();
165 while (multi_user_window_manager_->IsAnimationRunningForTest()) { 166 while (multi_user_window_manager_->IsAnimationRunningForTest()) {
166 // This should never take longer then a second. 167 // This should never take longer then a second.
167 ASSERT_GE(1000, (base::TimeTicks::Now() - now).InMilliseconds()); 168 ASSERT_GE(1000, (base::TimeTicks::Now() - now).InMilliseconds());
168 base::RunLoop().RunUntilIdle(); 169 base::RunLoop().RunUntilIdle();
169 } 170 }
170 } 171 }
171 172
172 // Return the window with the given index. 173 // Return the window with the given index.
173 aura::Window* window(size_t index) { 174 aura::Window* window(size_t index) {
174 DCHECK(index < window_.size()); 175 DCHECK(index < windows_.size());
175 return window_[index]; 176 return windows_[index];
176 } 177 }
177 178
178 // Delete the window at the given index, and set the referefence to NULL. 179 // Delete the window at the given index, and set the referefence to NULL.
179 void delete_window_at(size_t index) { 180 void delete_window_at(size_t index) {
180 delete window_[index]; 181 delete windows_[index];
181 window_[index] = NULL; 182 windows_[index] = NULL;
182 } 183 }
183 184
184 // The accessor to the MultiWindowManager. 185 // The accessor to the MultiWindowManager.
185 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager() { 186 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager() {
186 return multi_user_window_manager_; 187 return multi_user_window_manager_;
187 } 188 }
188 189
189 chromeos::FakeChromeUserManager* user_manager() { return fake_user_manager_; } 190 chromeos::FakeChromeUserManager* user_manager() { return fake_user_manager_; }
190 191
191 TestingProfileManager* profile_manager() { return profile_manager_.get(); } 192 TestingProfileManager* profile_manager() { return profile_manager_.get(); }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 } 279 }
279 280
280 MaximizeModeWindowManager* maximize_mode_window_manager() { 281 MaximizeModeWindowManager* maximize_mode_window_manager() {
281 return Shell::Get() 282 return Shell::Get()
282 ->maximize_mode_controller() 283 ->maximize_mode_controller()
283 ->maximize_mode_window_manager_.get(); 284 ->maximize_mode_window_manager_.get();
284 } 285 }
285 286
286 private: 287 private:
287 // These get created for each session. 288 // These get created for each session.
288 std::vector<aura::Window*> window_; 289 aura::Window::Windows windows_;
289 290
290 // The instance of the MultiUserWindowManager. 291 // The instance of the MultiUserWindowManager.
291 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; 292 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
292 293
293 // Owned by |user_manager_enabler_|. 294 // Owned by |user_manager_enabler_|.
294 chromeos::FakeChromeUserManager* fake_user_manager_ = nullptr; 295 chromeos::FakeChromeUserManager* fake_user_manager_ = nullptr;
295 296
296 std::unique_ptr<TestingProfileManager> profile_manager_; 297 std::unique_ptr<TestingProfileManager> profile_manager_;
297 298
298 chromeos::ScopedUserManagerEnabler user_manager_enabler_; 299 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
(...skipping 13 matching lines...) Expand all
312 AshTestBase::SetUp(); 313 AshTestBase::SetUp();
313 profile_manager_.reset( 314 profile_manager_.reset(
314 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); 315 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
315 ASSERT_TRUE(profile_manager_.get()->SetUp()); 316 ASSERT_TRUE(profile_manager_.get()->SetUp());
316 EnsureTestUser(AccountId::FromUserEmail("a")); 317 EnsureTestUser(AccountId::FromUserEmail("a"));
317 EnsureTestUser(AccountId::FromUserEmail("b")); 318 EnsureTestUser(AccountId::FromUserEmail("b"));
318 EnsureTestUser(AccountId::FromUserEmail("c")); 319 EnsureTestUser(AccountId::FromUserEmail("c"));
319 } 320 }
320 321
321 void MultiUserWindowManagerChromeOSTest::SetUpForThisManyWindows(int windows) { 322 void MultiUserWindowManagerChromeOSTest::SetUpForThisManyWindows(int windows) {
322 DCHECK(window_.empty()); 323 DCHECK(windows_.empty());
323 for (int i = 0; i < windows; i++) { 324 for (int i = 0; i < windows; i++) {
324 window_.push_back(CreateTestWindowInShellWithId(i)); 325 windows_.push_back(CreateTestWindowInShellWithId(i));
325 window_[i]->Show(); 326 windows_[i]->Show();
326 } 327 }
327 multi_user_window_manager_ = 328 multi_user_window_manager_ =
328 new chrome::MultiUserWindowManagerChromeOS(AccountId::FromUserEmail("A")); 329 new chrome::MultiUserWindowManagerChromeOS(AccountId::FromUserEmail("A"));
329 multi_user_window_manager_->Init(); 330 multi_user_window_manager_->Init();
330 multi_user_window_manager_->SetAnimationSpeedForTest( 331 multi_user_window_manager_->SetAnimationSpeedForTest(
331 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); 332 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED);
332 chrome::MultiUserWindowManager::SetInstanceForTest(multi_user_window_manager_, 333 chrome::MultiUserWindowManager::SetInstanceForTest(multi_user_window_manager_,
333 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED); 334 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
334 EXPECT_TRUE(multi_user_window_manager_); 335 EXPECT_TRUE(multi_user_window_manager_);
335 chromeos::WallpaperManager::Initialize(); 336 chromeos::WallpaperManager::Initialize();
336 } 337 }
337 338
338 void MultiUserWindowManagerChromeOSTest::TearDown() { 339 void MultiUserWindowManagerChromeOSTest::TearDown() {
339 // Since the AuraTestBase is needed to create our assets, we have to 340 // Since the AuraTestBase is needed to create our assets, we have to
340 // also delete them before we tear it down. 341 // also delete them before we tear it down.
341 while (!window_.empty()) { 342 while (!windows_.empty()) {
342 delete *(window_.begin()); 343 delete *(windows_.begin());
343 window_.erase(window_.begin()); 344 windows_.erase(windows_.begin());
344 } 345 }
345 346
346 chrome::MultiUserWindowManager::DeleteInstance(); 347 chrome::MultiUserWindowManager::DeleteInstance();
347 AshTestBase::TearDown(); 348 AshTestBase::TearDown();
348 chromeos::WallpaperManager::Shutdown(); 349 chromeos::WallpaperManager::Shutdown();
349 profile_manager_.reset(); 350 profile_manager_.reset();
350 } 351 }
351 352
352 std::string MultiUserWindowManagerChromeOSTest::GetStatus() { 353 std::string MultiUserWindowManagerChromeOSTest::GetStatus() {
353 std::string s; 354 std::string s;
354 for (size_t i = 0; i < window_.size(); i++) { 355 for (size_t i = 0; i < windows_.size(); i++) {
355 if (i) 356 if (i)
356 s += ", "; 357 s += ", ";
357 if (!window(i)) { 358 if (!window(i)) {
358 s += "D"; 359 s += "D";
359 continue; 360 continue;
360 } 361 }
361 s += window(i)->IsVisible() ? "S[" : "H["; 362 s += window(i)->IsVisible() ? "S[" : "H[";
362 const AccountId& owner = 363 const AccountId& owner =
363 multi_user_window_manager_->GetWindowOwner(window(i)); 364 multi_user_window_manager_->GetWindowOwner(window(i));
364 s += owner.GetUserEmail(); 365 s += owner.GetUserEmail();
(...skipping 1148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 multi_user_window_manager()->SetWindowOwner(window(1), account_id_A); 1514 multi_user_window_manager()->SetWindowOwner(window(1), account_id_A);
1514 multi_user_window_manager()->SetWindowOwner(window(2), account_id_A); 1515 multi_user_window_manager()->SetWindowOwner(window(2), account_id_A);
1515 EXPECT_EQ("S[A], S[A], S[A]", GetStatus()); 1516 EXPECT_EQ("S[A], S[A], S[A]", GetStatus());
1516 1517
1517 // Activate the windows one by one. 1518 // Activate the windows one by one.
1518 activation_client->ActivateWindow(window(2)); 1519 activation_client->ActivateWindow(window(2));
1519 activation_client->ActivateWindow(window(1)); 1520 activation_client->ActivateWindow(window(1));
1520 activation_client->ActivateWindow(window(0)); 1521 activation_client->ActivateWindow(window(0));
1521 EXPECT_EQ(wm::GetActiveWindow(), window(0)); 1522 EXPECT_EQ(wm::GetActiveWindow(), window(0));
1522 1523
1523 aura::Window::Windows mru_list = WmWindow::ToAuraWindows( 1524 aura::Window::Windows mru_list =
1524 Shell::Get()->mru_window_tracker()->BuildMruWindowList()); 1525 Shell::Get()->mru_window_tracker()->BuildMruWindowList();
1525 EXPECT_EQ(mru_list[0], window(0)); 1526 EXPECT_EQ(mru_list[0], window(0));
1526 EXPECT_EQ(mru_list[1], window(1)); 1527 EXPECT_EQ(mru_list[1], window(1));
1527 EXPECT_EQ(mru_list[2], window(2)); 1528 EXPECT_EQ(mru_list[2], window(2));
1528 1529
1529 user_manager()->SwitchActiveUser(account_id_B); 1530 user_manager()->SwitchActiveUser(account_id_B);
1530 multi_user_window_manager()->ActiveUserChanged( 1531 multi_user_window_manager()->ActiveUserChanged(
1531 user_manager()->FindUser(account_id_B)); 1532 user_manager()->FindUser(account_id_B));
1532 EXPECT_EQ("H[A], H[A], H[A]", GetStatus()); 1533 EXPECT_EQ("H[A], H[A], H[A]", GetStatus());
1533 EXPECT_EQ(wm::GetActiveWindow(), nullptr); 1534 EXPECT_EQ(wm::GetActiveWindow(), nullptr);
1534 1535
1535 user_manager()->SwitchActiveUser(account_id_A); 1536 user_manager()->SwitchActiveUser(account_id_A);
1536 multi_user_window_manager()->ActiveUserChanged( 1537 multi_user_window_manager()->ActiveUserChanged(
1537 user_manager()->FindUser(account_id_A)); 1538 user_manager()->FindUser(account_id_A));
1538 EXPECT_EQ("S[A], S[A], S[A]", GetStatus()); 1539 EXPECT_EQ("S[A], S[A], S[A]", GetStatus());
1539 EXPECT_EQ(wm::GetActiveWindow(), window(0)); 1540 EXPECT_EQ(wm::GetActiveWindow(), window(0));
1540 1541
1541 mru_list = WmWindow::ToAuraWindows( 1542 mru_list = Shell::Get()->mru_window_tracker()->BuildMruWindowList();
1542 Shell::Get()->mru_window_tracker()->BuildMruWindowList());
1543 EXPECT_EQ(mru_list[0], window(0)); 1543 EXPECT_EQ(mru_list[0], window(0));
1544 EXPECT_EQ(mru_list[1], window(1)); 1544 EXPECT_EQ(mru_list[1], window(1));
1545 EXPECT_EQ(mru_list[2], window(2)); 1545 EXPECT_EQ(mru_list[2], window(2));
1546 } 1546 }
1547 1547
1548 // Tests that ChromeNewWindowClient::GetActiveBrowser works properly in 1548 // Tests that ChromeNewWindowClient::GetActiveBrowser works properly in
1549 // multi-user scenario, that is it should return the browser with active window 1549 // multi-user scenario, that is it should return the browser with active window
1550 // associated with it (crbug.com/675265). 1550 // associated with it (crbug.com/675265).
1551 TEST_F(MultiUserWindowManagerChromeOSTest, GetActiveBrowserTest) { 1551 TEST_F(MultiUserWindowManagerChromeOSTest, GetActiveBrowserTest) {
1552 SetUpForThisManyWindows(1); 1552 SetUpForThisManyWindows(1);
(...skipping 25 matching lines...) Expand all
1578 user_manager()->SwitchActiveUser(account_id_B); 1578 user_manager()->SwitchActiveUser(account_id_B);
1579 multi_user_window_manager()->ActiveUserChanged( 1579 multi_user_window_manager()->ActiveUserChanged(
1580 user_manager()->FindUser(account_id_B)); 1580 user_manager()->FindUser(account_id_B));
1581 EXPECT_EQ(browser.get(), BrowserList::GetInstance()->GetLastActive()); 1581 EXPECT_EQ(browser.get(), BrowserList::GetInstance()->GetLastActive());
1582 EXPECT_EQ(nullptr, wm::GetActiveWindow()); 1582 EXPECT_EQ(nullptr, wm::GetActiveWindow());
1583 EXPECT_EQ(nullptr, ChromeNewWindowClient::GetActiveBrowser()); 1583 EXPECT_EQ(nullptr, ChromeNewWindowClient::GetActiveBrowser());
1584 } 1584 }
1585 1585
1586 } // namespace test 1586 } // namespace test
1587 } // namespace ash 1587 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698