Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser_command_controller.h" | 5 #include "chrome/browser/ui/browser_command_controller.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 7 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/browser_process.h" | |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 11 #include "chrome/browser/profiles/profile_manager.h" | |
| 12 #include "chrome/browser/profiles/profile_window.h" | |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | |
| 8 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 16 #include "chrome/browser/ui/browser_finder.h" | |
| 17 #include "chrome/browser/ui/browser_list.h" | |
| 18 #include "chrome/browser/ui/browser_window.h" | |
| 19 #include "chrome/browser/ui/startup/startup_browser_creator.h" | |
| 10 #include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h" | 20 #include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h" |
| 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 23 #include "components/search_engines/template_url_service.h" | |
| 24 #include "components/signin/core/common/profile_management_switches.h" | |
| 25 #include "components/signin/core/common/profile_management_switches.h" | |
| 26 #include "content/public/browser/notification_service.h" | |
| 13 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
| 14 | 28 |
| 15 typedef InProcessBrowserTest BrowserCommandControllerBrowserTest; | 29 typedef InProcessBrowserTest BrowserCommandControllerBrowserTest; |
| 16 | 30 |
| 17 // Verify that showing a constrained window disables find. | 31 // Verify that showing a constrained window disables find. |
| 18 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) { | 32 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) { |
| 19 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); | 33 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); |
| 20 | 34 |
| 21 // Showing constrained window should disable find. | 35 // Showing constrained window should disable find. |
| 22 content::WebContents* web_contents = | 36 content::WebContents* web_contents = |
| 23 browser()->tab_strip_model()->GetActiveWebContents(); | 37 browser()->tab_strip_model()->GetActiveWebContents(); |
| 24 MockTabModalConfirmDialogDelegate* delegate = | 38 MockTabModalConfirmDialogDelegate* delegate = |
| 25 new MockTabModalConfirmDialogDelegate(web_contents, NULL); | 39 new MockTabModalConfirmDialogDelegate(web_contents, NULL); |
| 26 TabModalConfirmDialog::Create(delegate, web_contents); | 40 TabModalConfirmDialog::Create(delegate, web_contents); |
| 27 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND)); | 41 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND)); |
| 28 | 42 |
| 29 // Switching to a new (unblocked) tab should reenable it. | 43 // Switching to a new (unblocked) tab should reenable it. |
| 30 AddBlankTabAndShow(browser()); | 44 AddBlankTabAndShow(browser()); |
| 31 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); | 45 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); |
| 32 | 46 |
| 33 // Switching back to the blocked tab should disable it again. | 47 // Switching back to the blocked tab should disable it again. |
| 34 browser()->tab_strip_model()->ActivateTabAt(0, false); | 48 browser()->tab_strip_model()->ActivateTabAt(0, false); |
| 35 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND)); | 49 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND)); |
| 36 | 50 |
| 37 // Closing the constrained window should reenable it. | 51 // Closing the constrained window should reenable it. |
| 38 delegate->Cancel(); | 52 delegate->Cancel(); |
| 39 content::RunAllPendingInMessageLoop(); | 53 content::RunAllPendingInMessageLoop(); |
| 40 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); | 54 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); |
| 41 } | 55 } |
| 56 | |
| 57 // This test also tests the BrowsingDataRemover that fires when all of a guest's | |
|
Peter Kasting
2015/02/12 22:18:40
What about that BrowsingDataRemover does this test
Mike Lerman
2015/02/13 14:07:29
I tried rephrasing my comment here. I'm referencin
| |
| 58 // browsers are closed, in ~Browser(). | |
| 59 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, | |
| 60 NewAvatarMenuEnabledInGuestMode) { | |
| 61 switches::EnableNewAvatarMenuForTesting( | |
| 62 base::CommandLine::ForCurrentProcess()); | |
| 63 | |
| 64 EXPECT_EQ(1U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size()); | |
| 65 | |
| 66 // Create a guest browser nicely. Using CreateProfile() and CreateBrowser() | |
| 67 // does incomplete initialization that would lead to | |
| 68 // SystemUrlRequestContextGetter being leaked. | |
| 69 scoped_ptr<content::WindowedNotificationObserver> browser_creation_observer; | |
|
battre
2015/02/13 08:49:43
opt/nit: you could also create this on the stack.
Mike Lerman
2015/02/13 14:07:29
Done.
| |
| 70 browser_creation_observer.reset(new content::WindowedNotificationObserver( | |
| 71 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | |
|
Peter Kasting
2015/02/12 22:18:40
Nit: Indent 4, not 6
Mike Lerman
2015/02/13 14:07:29
Done.
| |
| 72 content::NotificationService::AllSources())); | |
| 73 profiles::SwitchToGuestProfile(chrome::GetActiveDesktop(), | |
| 74 ProfileManager::CreateCallback()); | |
| 75 | |
| 76 // RunUntilIdle() (racily) isn't sufficient to ensure browser creation, so | |
| 77 // listen for the notification. | |
| 78 base::MessageLoop::current()->RunUntilIdle(); | |
| 79 browser_creation_observer->Wait(); | |
| 80 EXPECT_EQ(2U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size()); | |
| 81 | |
| 82 // Access the browser that was created for the new Guest Profile. | |
| 83 Profile* guest = g_browser_process->profile_manager()->GetProfileByPath( | |
| 84 ProfileManager::GetGuestProfilePath()); | |
| 85 Browser* browser = chrome::FindAnyBrowser( | |
| 86 guest, true, chrome::GetActiveDesktop()); | |
| 87 EXPECT_TRUE(browser); | |
| 88 | |
| 89 // The BrowsingDataRemover needs a loaded TemplateUrlService or else it hangs | |
| 90 // on to a CallbackList::Subscription forever. | |
| 91 TemplateURLServiceFactory::GetForProfile(guest)->set_loaded(true); | |
| 92 | |
| 93 chrome::BrowserCommandController* command_controller = | |
| 94 browser->command_controller(); | |
|
Peter Kasting
2015/02/12 22:18:40
Nit: Just inline this into the next line, pulling
Mike Lerman
2015/02/13 14:07:29
Done.
| |
| 95 const CommandUpdater* command_updater = command_controller->command_updater(); | |
| 96 #if defined(OS_CHROMEOS) | |
| 97 // Chrome OS uses system tray menu to handle multi-profiles. | |
| 98 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | |
| 99 #else | |
| 100 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU)); | |
| 101 #endif | |
| 102 } | |
| OLD | NEW |