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

Side by Side Diff: chrome/browser/ui/ash/launcher/chrome_launcher_controller_unittest.cc

Issue 1198313003: Fix the browser match rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use scoped_ptr<Browser> instead. Created 5 years, 5 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/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
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 manager->SetAnimationSpeedForTest( 809 manager->SetAnimationSpeedForTest(
855 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); 810 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED);
856 manager->ActiveUserChanged(name); 811 manager->ActiveUserChanged(name);
857 launcher_controller_->browser_status_monitor_for_test()-> 812 launcher_controller_->browser_status_monitor_for_test()->
858 ActiveUserChanged(name); 813 ActiveUserChanged(name);
859 launcher_controller_->app_window_controller_for_test()-> 814 launcher_controller_->app_window_controller_for_test()->
860 ActiveUserChanged(name); 815 ActiveUserChanged(name);
861 } 816 }
862 817
863 // Creates a browser with a |profile| and load a tab with a |title| and |url|. 818 // Creates a browser with a |profile| and load a tab with a |title| and |url|.
864 Browser* CreateBrowserAndTabWithProfile(Profile* profile, 819 scoped_ptr<Browser> CreateBrowserAndTabWithProfile(Profile* profile,
865 const std::string& title, 820 const std::string& title,
866 const std::string& url) { 821 const std::string& url) {
867 Browser::CreateParams params(profile, chrome::HOST_DESKTOP_TYPE_ASH); 822 Browser::CreateParams params(profile, chrome::HOST_DESKTOP_TYPE_ASH);
868 Browser* browser = chrome::CreateBrowserWithTestWindowForParams(&params); 823 scoped_ptr<Browser> browser =
869 chrome::NewTab(browser); 824 chrome::CreateBrowserWithTestWindowForParams(&params);
825 chrome::NewTab(browser.get());
870 826
871 BrowserList::SetLastActive(browser); 827 BrowserList::SetLastActive(browser.get());
872 NavigateAndCommitActiveTabWithTitle( 828 NavigateAndCommitActiveTabWithTitle(browser.get(), GURL(url),
873 browser, GURL(url), ASCIIToUTF16(title)); 829 ASCIIToUTF16(title));
874 return browser; 830 return browser.Pass();
875 } 831 }
876 832
877 // Creates a running V1 application. 833 // Creates a running V1 application.
878 // Note that with the use of the app_tab_helper as done below, this is only 834 // Note that with the use of the app_tab_helper as done below, this is only
879 // usable with a single v1 application. 835 // usable with a single v1 application.
880 V1App* CreateRunningV1App(Profile* profile, 836 V1App* CreateRunningV1App(Profile* profile,
881 const std::string& app_name, 837 const std::string& app_name,
882 const std::string& url) { 838 const std::string& url) {
883 V1App* v1_app = new V1App(profile, app_name); 839 V1App* v1_app = new V1App(profile, app_name);
884 // Create a new app tab helper and assign it to the launcher so that this 840 // Create a new app tab helper and assign it to the launcher so that this
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 1431
1476 // Add two users to the window manager. 1432 // Add two users to the window manager.
1477 std::string user2 = "user2"; 1433 std::string user2 = "user2";
1478 TestingProfile* profile2 = CreateMultiUserProfile(user2); 1434 TestingProfile* profile2 = CreateMultiUserProfile(user2);
1479 manager->AddUser(profile()); 1435 manager->AddUser(profile());
1480 manager->AddUser(profile2); 1436 manager->AddUser(profile2);
1481 const std::string& current_user = 1437 const std::string& current_user =
1482 multi_user_util::GetUserIDFromProfile(profile()); 1438 multi_user_util::GetUserIDFromProfile(profile());
1483 1439
1484 // Create a browser window with a native window for the current user. 1440 // Create a browser window with a native window for the current user.
1485 scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 1441 Browser::CreateParams params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
1486 Browser::CreateParams(profile(), chrome::HOST_DESKTOP_TYPE_ASH))); 1442 scoped_ptr<Browser> browser =
1443 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, &params);
1444 BrowserWindow* browser_window = browser->window();
1487 aura::Window* window = browser_window->GetNativeWindow(); 1445 aura::Window* window = browser_window->GetNativeWindow();
1488 manager->SetWindowOwner(window, current_user); 1446 manager->SetWindowOwner(window, current_user);
1489 1447
1490 // Check that an activation of the window on its owner's desktop does not 1448 // Check that an activation of the window on its owner's desktop does not
1491 // change the visibility to another user. 1449 // change the visibility to another user.
1492 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(), 1450 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false);
1493 false);
1494 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1451 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user));
1495 1452
1496 // Transfer the window to another user's desktop and check that activating it 1453 // Transfer the window to another user's desktop and check that activating it
1497 // does pull it back to that user. 1454 // does pull it back to that user.
1498 manager->ShowWindowForUser(window, 1455 manager->ShowWindowForUser(window,
1499 multi_user_util::GetUserIDFromProfile(profile2)); 1456 multi_user_util::GetUserIDFromProfile(profile2));
1500 EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1457 EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user));
1501 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(), 1458 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false);
1502 false);
1503 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1459 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user));
1504 } 1460 }
1505 #endif 1461 #endif
1506 1462
1507 // Check that lock -> pin -> unlock -> unpin does properly transition. 1463 // Check that lock -> pin -> unlock -> unpin does properly transition.
1508 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) { 1464 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) {
1509 InitLauncherController(); 1465 InitLauncherController();
1510 // Model should only contain the browser shortcut and app list items. 1466 // Model should only contain the browser shortcut and app list items.
1511 EXPECT_EQ(2, model_->item_count()); 1467 EXPECT_EQ(2, model_->item_count());
1512 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1468 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
2008 base::string16 title1 = ASCIIToUTF16("Test1"); 1964 base::string16 title1 = ASCIIToUTF16("Test1");
2009 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1); 1965 NavigateAndCommitActiveTabWithTitle(browser(), GURL("http://test1"), title1);
2010 base::string16 one_menu_item1[] = { title1 }; 1966 base::string16 one_menu_item1[] = { title1 };
2011 EXPECT_TRUE(CheckMenuCreation( 1967 EXPECT_TRUE(CheckMenuCreation(
2012 launcher_controller_.get(), item_browser, 1, one_menu_item1, true)); 1968 launcher_controller_.get(), item_browser, 1, one_menu_item1, true));
2013 1969
2014 // Create a browser for another user and check that it is not included in the 1970 // Create a browser for another user and check that it is not included in the
2015 // users running browser list. 1971 // users running browser list.
2016 std::string user2 = "user2"; 1972 std::string user2 = "user2";
2017 TestingProfile* profile2 = CreateMultiUserProfile(user2); 1973 TestingProfile* profile2 = CreateMultiUserProfile(user2);
2018 scoped_ptr<Browser> browser2( 1974 scoped_ptr<Browser> browser2 =
2019 CreateBrowserAndTabWithProfile(profile2, user2, "http://test2")); 1975 CreateBrowserAndTabWithProfile(profile2, user2, "http://test2");
2020 base::string16 one_menu_item2[] = { ASCIIToUTF16(user2) }; 1976 base::string16 one_menu_item2[] = { ASCIIToUTF16(user2) };
2021 EXPECT_TRUE(CheckMenuCreation( 1977 EXPECT_TRUE(CheckMenuCreation(
2022 launcher_controller_.get(), item_browser, 1, one_menu_item1, true)); 1978 launcher_controller_.get(), item_browser, 1, one_menu_item1, true));
2023 1979
2024 // Switch to the other user and make sure that only that browser window gets 1980 // Switch to the other user and make sure that only that browser window gets
2025 // shown. 1981 // shown.
2026 SwitchActiveUser(profile2->GetProfileUserName()); 1982 SwitchActiveUser(profile2->GetProfileUserName());
2027 EXPECT_TRUE(CheckMenuCreation( 1983 EXPECT_TRUE(CheckMenuCreation(
2028 launcher_controller_.get(), item_browser, 1, one_menu_item2, true)); 1984 launcher_controller_.get(), item_browser, 1, one_menu_item2, true));
2029 1985
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 2645
2690 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2646 EXPECT_EQ(1, app_icon_loader->fetch_count());
2691 ASSERT_EQ(initial_size + 1, model_->items().size()); 2647 ASSERT_EQ(initial_size + 1, model_->items().size());
2692 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 2648 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
2693 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 2649 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
2694 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 2650 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
2695 2651
2696 launcher_controller_->UnpinAppWithID("1"); 2652 launcher_controller_->UnpinAppWithID("1");
2697 ASSERT_EQ(initial_size, model_->items().size()); 2653 ASSERT_EQ(initial_size, model_->items().size());
2698 } 2654 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698