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

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: Address sky@'s comment. 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
« no previous file with comments | « no previous file | chrome/browser/ui/ash/window_positioner_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" 54 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
55 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 55 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
56 #include "chrome/browser/ui/apps/chrome_app_delegate.h" 56 #include "chrome/browser/ui/apps/chrome_app_delegate.h"
57 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h" 57 #include "chrome/browser/ui/ash/launcher/app_window_launcher_controller.h"
58 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h" 58 #include "chrome/browser/ui/ash/launcher/browser_status_monitor.h"
59 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 59 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
60 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 60 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
61 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" 61 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
62 #include "chrome/common/chrome_constants.h" 62 #include "chrome/common/chrome_constants.h"
63 #include "chrome/common/chrome_switches.h" 63 #include "chrome/common/chrome_switches.h"
64 #include "chrome/test/base/test_browser_window_aura.h"
64 #include "chrome/test/base/testing_browser_process.h" 65 #include "chrome/test/base/testing_browser_process.h"
65 #include "chrome/test/base/testing_profile_manager.h" 66 #include "chrome/test/base/testing_profile_manager.h"
66 #include "components/user_manager/fake_user_manager.h" 67 #include "components/user_manager/fake_user_manager.h"
67 #include "content/public/browser/web_contents_observer.h" 68 #include "content/public/browser/web_contents_observer.h"
68 #include "content/public/test/test_utils.h" 69 #include "content/public/test/test_utils.h"
69 #include "extensions/browser/app_window/app_window_contents.h" 70 #include "extensions/browser/app_window/app_window_contents.h"
70 #include "extensions/browser/app_window/app_window_registry.h" 71 #include "extensions/browser/app_window/app_window_registry.h"
71 #include "extensions/browser/app_window/native_app_window.h" 72 #include "extensions/browser/app_window/native_app_window.h"
72 #include "ui/aura/window.h" 73 #include "ui/aura/window.h"
73 #endif 74 #endif
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 612
612 ExtensionService* extension_service_; 613 ExtensionService* extension_service_;
613 614
614 ash::ShelfItemDelegateManager* item_delegate_manager_; 615 ash::ShelfItemDelegateManager* item_delegate_manager_;
615 616
616 private: 617 private:
617 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest); 618 DISALLOW_COPY_AND_ASSIGN(ChromeLauncherControllerTest);
618 }; 619 };
619 620
620 #if defined(OS_CHROMEOS) 621 #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 622
667 // Watches WebContents and blocks until it is destroyed. This is needed for 623 // Watches WebContents and blocks until it is destroyed. This is needed for
668 // the destruction of a V2 application. 624 // the destruction of a V2 application.
669 class WebContentsDestroyedWatcher : public content::WebContentsObserver { 625 class WebContentsDestroyedWatcher : public content::WebContentsObserver {
670 public: 626 public:
671 explicit WebContentsDestroyedWatcher(content::WebContents* web_contents) 627 explicit WebContentsDestroyedWatcher(content::WebContents* web_contents)
672 : content::WebContentsObserver(web_contents), 628 : content::WebContentsObserver(web_contents),
673 message_loop_runner_(new content::MessageLoopRunner) { 629 message_loop_runner_(new content::MessageLoopRunner) {
674 EXPECT_TRUE(web_contents != NULL); 630 EXPECT_TRUE(web_contents != NULL);
675 } 631 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 manager->SetAnimationSpeedForTest( 810 manager->SetAnimationSpeedForTest(
855 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED); 811 chrome::MultiUserWindowManagerChromeOS::ANIMATION_SPEED_DISABLED);
856 manager->ActiveUserChanged(name); 812 manager->ActiveUserChanged(name);
857 launcher_controller_->browser_status_monitor_for_test()-> 813 launcher_controller_->browser_status_monitor_for_test()->
858 ActiveUserChanged(name); 814 ActiveUserChanged(name);
859 launcher_controller_->app_window_controller_for_test()-> 815 launcher_controller_->app_window_controller_for_test()->
860 ActiveUserChanged(name); 816 ActiveUserChanged(name);
861 } 817 }
862 818
863 // Creates a browser with a |profile| and load a tab with a |title| and |url|. 819 // Creates a browser with a |profile| and load a tab with a |title| and |url|.
864 Browser* CreateBrowserAndTabWithProfile(Profile* profile, 820 scoped_ptr<Browser> CreateBrowserAndTabWithProfile(Profile* profile,
865 const std::string& title, 821 const std::string& title,
866 const std::string& url) { 822 const std::string& url) {
867 Browser::CreateParams params(profile, chrome::HOST_DESKTOP_TYPE_ASH); 823 Browser::CreateParams params(profile, chrome::HOST_DESKTOP_TYPE_ASH);
868 Browser* browser = chrome::CreateBrowserWithTestWindowForParams(&params); 824 scoped_ptr<Browser> browser =
869 chrome::NewTab(browser); 825 chrome::CreateBrowserWithTestWindowForParams(&params);
826 chrome::NewTab(browser.get());
870 827
871 BrowserList::SetLastActive(browser); 828 BrowserList::SetLastActive(browser.get());
872 NavigateAndCommitActiveTabWithTitle( 829 NavigateAndCommitActiveTabWithTitle(browser.get(), GURL(url),
873 browser, GURL(url), ASCIIToUTF16(title)); 830 ASCIIToUTF16(title));
874 return browser; 831 return browser.Pass();
875 } 832 }
876 833
877 // Creates a running V1 application. 834 // Creates a running V1 application.
878 // Note that with the use of the app_tab_helper as done below, this is only 835 // Note that with the use of the app_tab_helper as done below, this is only
879 // usable with a single v1 application. 836 // usable with a single v1 application.
880 V1App* CreateRunningV1App(Profile* profile, 837 V1App* CreateRunningV1App(Profile* profile,
881 const std::string& app_name, 838 const std::string& app_name,
882 const std::string& url) { 839 const std::string& url) {
883 V1App* v1_app = new V1App(profile, app_name); 840 V1App* v1_app = new V1App(profile, app_name);
884 // Create a new app tab helper and assign it to the launcher so that this 841 // 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 1432
1476 // Add two users to the window manager. 1433 // Add two users to the window manager.
1477 std::string user2 = "user2"; 1434 std::string user2 = "user2";
1478 TestingProfile* profile2 = CreateMultiUserProfile(user2); 1435 TestingProfile* profile2 = CreateMultiUserProfile(user2);
1479 manager->AddUser(profile()); 1436 manager->AddUser(profile());
1480 manager->AddUser(profile2); 1437 manager->AddUser(profile2);
1481 const std::string& current_user = 1438 const std::string& current_user =
1482 multi_user_util::GetUserIDFromProfile(profile()); 1439 multi_user_util::GetUserIDFromProfile(profile());
1483 1440
1484 // Create a browser window with a native window for the current user. 1441 // Create a browser window with a native window for the current user.
1485 scoped_ptr<BrowserWindow> browser_window(CreateTestBrowserWindow( 1442 Browser::CreateParams params(profile(), chrome::HOST_DESKTOP_TYPE_ASH);
1486 Browser::CreateParams(profile(), chrome::HOST_DESKTOP_TYPE_ASH))); 1443 scoped_ptr<Browser> browser(
1444 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, &params));
1445 BrowserWindow* browser_window = browser->window();
1487 aura::Window* window = browser_window->GetNativeWindow(); 1446 aura::Window* window = browser_window->GetNativeWindow();
1488 manager->SetWindowOwner(window, current_user); 1447 manager->SetWindowOwner(window, current_user);
1489 1448
1490 // Check that an activation of the window on its owner's desktop does not 1449 // Check that an activation of the window on its owner's desktop does not
1491 // change the visibility to another user. 1450 // change the visibility to another user.
1492 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(), 1451 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false);
1493 false);
1494 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1452 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user));
1495 1453
1496 // Transfer the window to another user's desktop and check that activating it 1454 // Transfer the window to another user's desktop and check that activating it
1497 // does pull it back to that user. 1455 // does pull it back to that user.
1498 manager->ShowWindowForUser(window, 1456 manager->ShowWindowForUser(window,
1499 multi_user_util::GetUserIDFromProfile(profile2)); 1457 multi_user_util::GetUserIDFromProfile(profile2));
1500 EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1458 EXPECT_FALSE(manager->IsWindowOnDesktopOfUser(window, current_user));
1501 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window.get(), 1459 launcher_controller_->ActivateWindowOrMinimizeIfActive(browser_window, false);
1502 false);
1503 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user)); 1460 EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(window, current_user));
1504 } 1461 }
1505 #endif 1462 #endif
1506 1463
1507 // Check that lock -> pin -> unlock -> unpin does properly transition. 1464 // Check that lock -> pin -> unlock -> unpin does properly transition.
1508 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) { 1465 TEST_F(ChromeLauncherControllerTest, CheckLockPinUnlockUnpin) {
1509 InitLauncherController(); 1466 InitLauncherController();
1510 // Model should only contain the browser shortcut and app list items. 1467 // Model should only contain the browser shortcut and app list items.
1511 EXPECT_EQ(2, model_->item_count()); 1468 EXPECT_EQ(2, model_->item_count());
1512 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id())); 1469 EXPECT_FALSE(launcher_controller_->IsAppPinned(extension1_->id()));
(...skipping 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 2646
2690 EXPECT_EQ(1, app_icon_loader->fetch_count()); 2647 EXPECT_EQ(1, app_icon_loader->fetch_count());
2691 ASSERT_EQ(initial_size + 1, model_->items().size()); 2648 ASSERT_EQ(initial_size + 1, model_->items().size());
2692 EXPECT_TRUE(launcher_controller_->IsAppPinned("1")); 2649 EXPECT_TRUE(launcher_controller_->IsAppPinned("1"));
2693 EXPECT_FALSE(launcher_controller_->IsAppPinned("0")); 2650 EXPECT_FALSE(launcher_controller_->IsAppPinned("0"));
2694 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type); 2651 EXPECT_EQ(ash::TYPE_APP_SHORTCUT, model_->items()[app_index].type);
2695 2652
2696 launcher_controller_->UnpinAppWithID("1"); 2653 launcher_controller_->UnpinAppWithID("1");
2697 ASSERT_EQ(initial_size, model_->items().size()); 2654 ASSERT_EQ(initial_size, model_->items().size());
2698 } 2655 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/ash/window_positioner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698