| OLD | NEW |
| 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/launcher/chrome_launcher_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 611 |
| 612 ExtensionService* extension_service_; | 612 ExtensionService* extension_service_; |
| 613 | 613 |
| 614 ash::ShelfItemDelegateManager* item_delegate_manager_; | 614 ash::ShelfItemDelegateManager* item_delegate_manager_; |
| 615 | 615 |
| 616 private: | 616 private: |
| 617 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); | 617 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); |
| 618 }; | 618 }; |
| 619 | 619 |
| 620 #if defined(OS_CHROMEOS) | 620 #if defined(OS_CHROMEOS) |
| 621 // A browser window proxy which is able to associate an aura native window with | |
| 622 // it. | |
| 623 class TestBrowserWindowAura : public TestBrowserWindow { | |
| 624 public: | |
| 625 // |native_window| will still be owned by the caller after the constructor | |
| 626 // was called. | |
| 627 explicit TestBrowserWindowAura(aura::Window* native_window) | |
| 628 : native_window_(native_window) { | |
| 629 } | |
| 630 ~TestBrowserWindowAura() override {} | |
| 631 | |
| 632 gfx::NativeWindow GetNativeWindow() const override { | |
| 633 return native_window_.get(); | |
| 634 } | |
| 635 | |
| 636 Browser* browser() { return browser_.get(); } | |
| 637 | |
| 638 void CreateBrowser(const Browser::CreateParams& params) { | |
| 639 Browser::CreateParams create_params = params; | |
| 640 create_params.window = this; | |
| 641 browser_.reset(new Browser(create_params)); | |
| 642 } | |
| 643 | |
| 644 private: | |
| 645 scoped_ptr<Browser> browser_; | |
| 646 scoped_ptr<aura::Window> native_window_; | |
| 647 | |
| 648 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); | |
| 649 }; | |
| 650 | |
| 651 // Creates a test browser window which has a native window. | |
| 652 scoped_ptr<TestBrowserWindowAura> CreateTestBrowserWindow( | |
| 653 const Browser::CreateParams& params) { | |
| 654 // Create a window. | |
| 655 aura::Window* window = new aura::Window(NULL); | |
| 656 window->set_id(0); | |
| 657 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | |
| 658 window->Init(ui::LAYER_TEXTURED); | |
| 659 window->Show(); | |
| 660 | |
| 661 scoped_ptr<TestBrowserWindowAura> browser_window( | |
| 662 new TestBrowserWindowAura(window)); | |
| 663 browser_window->CreateBrowser(params); | |
| 664 return browser_window.Pass(); | |
| 665 } | |
| 666 | 621 |
| 667 // Watches WebContents and blocks until it is destroyed. This is needed for | 622 // Watches WebContents and blocks until it is destroyed. This is needed for |
| 668 // the destruction of a V2 application. | 623 // the destruction of a V2 application. |
| 669 class WebContentsDestroyedWatcher : public content::WebContentsObserver { | 624 class WebContentsDestroyedWatcher : public content::WebContentsObserver { |
| 670 public: | 625 public: |
| 671 explicit WebContentsDestroyedWatcher(content::WebContents* web_contents) | 626 explicit WebContentsDestroyedWatcher(content::WebContents* web_contents) |
| 672 : content::WebContentsObserver(web_contents), | 627 : content::WebContentsObserver(web_contents), |
| 673 message_loop_runner_(new content::MessageLoopRunner) { | 628 message_loop_runner_(new content::MessageLoopRunner) { |
| 674 EXPECT_TRUE(web_contents != NULL); | 629 EXPECT_TRUE(web_contents != NULL); |
| 675 } | 630 } |
| (...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1475 | 1430 |
| 1476 // Add two users to the window manager. | 1431 // Add two users to the window manager. |
| 1477 std::string user2 = "user2"; | 1432 std::string user2 = "user2"; |
| 1478 TestingProfile* profile2 = CreateMultiUserProfile(user2); | 1433 TestingProfile* profile2 = CreateMultiUserProfile(user2); |
| 1479 manager->AddUser(profile()); | 1434 manager->AddUser(profile()); |
| 1480 manager->AddUser(profile2); | 1435 manager->AddUser(profile2); |
| 1481 const std::string& current_user = | 1436 const std::string& current_user = |
| 1482 multi_user_util::GetUserIDFromProfile(profile()); | 1437 multi_user_util::GetUserIDFromProfile(profile()); |
| 1483 | 1438 |
| 1484 // Create a browser window with a native window for the current user. | 1439 // Create a browser window with a native window for the current user. |
| 1485 scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( | 1440 scoped_ptr<Browser> browser(chrome::CreateBrowserWithAuraTestWindowForParams( |
| 1486 Browser::CreateParams(profile(), chrome::HOST_DESKTOP_TYPE_ASH))); | 1441 Browser::CreateParams(profile(), chrome::HOST_DESKTOP_TYPE_ASH))); |
| 1442 BrowserWindow* browser_window = browser->window(); |
| 1487 aura::Window* window = browser_window->GetNativeWindow(); | 1443 aura::Window* window = browser_window->GetNativeWindow(); |
| 1488 manager->SetWindowOwner(window, current_user); | 1444 manager->SetWindowOwner(window, current_user); |
| 1489 | 1445 |
| 1490 // Check that an activation of the window on its owner's desktop does not | 1446 // Check that an activation of the window on its owner's desktop does not |
| 1491 // change the visibility to another user. | 1447 // change the visibility to another user. |
| 1492 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(), | 1448 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false); |
| 1493 false); | |
| 1494 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); | 1449 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); |
| 1495 | 1450 |
| 1496 // Transfer the window to another user's desktop and check that activating it | 1451 // Transfer the window to another user's desktop and check that activating it |
| 1497 // does pull it back to that user. | 1452 // does pull it back to that user. |
| 1498 manager->ShowWindowForUser(window, | 1453 manager->ShowWindowForUser(window, |
| 1499 multi_user_util::GetUserIDFromProfile(profile2)); | 1454 multi_user_util::GetUserIDFromProfile(profile2)); |
| 1500 EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user)); | 1455 EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user)); |
| 1501 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(), | 1456 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false); |
| 1502 false); | |
| 1503 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); | 1457 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); |
| 1504 } | 1458 } |
| 1505 #endif | 1459 #endif |
| 1506 | 1460 |
| 1507 // Check that lock -> pin -> unlock -> unpin does properly transition. | 1461 // Check that lock -> pin -> unlock -> unpin does properly transition. |
| 1508 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) { | 1462 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) { |
| 1509 InitLauncherController(); | 1463 InitLauncherController(); |
| 1510 // Model should only contain the browser shortcut and app list items. | 1464 // Model should only contain the browser shortcut and app list items. |
| 1511 EXPECT_EQ(2, model_->item_count()); | 1465 EXPECT_EQ(2, model_->item_count()); |
| 1512 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); | 1466 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); |
| (...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2689 | 2643 |
| 2690 EXPECT_EQ(1, app_icon_loader->fetch_count()); | 2644 EXPECT_EQ(1, app_icon_loader->fetch_count()); |
| 2691 ASSERT_EQ(initial_size + 1, model_->items().size()); | 2645 ASSERT_EQ(initial_size + 1, model_->items().size()); |
| 2692 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); | 2646 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); |
| 2693 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); | 2647 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); |
| 2694 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); | 2648 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); |
| 2695 | 2649 |
| 2696 launcher_controller_->UnpinAppWithID("1"); | 2650 launcher_controller_->UnpinAppWithID("1"); |
| 2697 ASSERT_EQ(initial_size, model_->items().size()); | 2651 ASSERT_EQ(initial_size, model_->items().size()); |
| 2698 } | 2652 } |
| OLD | NEW |