AccessibilityManager must be deleted after ash Shell, but before InputMethodManager.
[chromium-blink-merge.git] / chrome / browser / ui / browser_command_controller_browsertest.cc
blobfeb5af256f712b8a1d9f5b6528dd06f3aa55cc81
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/browser_command_controller.h"
7 #include "base/command_line.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"
14 #include "chrome/browser/ui/browser.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"
20 #include "chrome/browser/ui/tab_modal_confirm_dialog_browsertest.h"
21 #include "chrome/browser/ui/tabs/tab_strip_model.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 "content/public/browser/notification_service.h"
26 #include "content/public/test/test_utils.h"
28 #if defined(OS_CHROMEOS)
29 #include "chromeos/chromeos_switches.h"
30 #endif
32 class BrowserCommandControllerBrowserTest: public InProcessBrowserTest {
33 public:
34 BrowserCommandControllerBrowserTest() {}
35 ~BrowserCommandControllerBrowserTest() override {}
37 void SetUpCommandLine(base::CommandLine* command_line) override {
38 InProcessBrowserTest::SetUpCommandLine(command_line);
40 #if defined(OS_CHROMEOS)
41 command_line->AppendSwitch(
42 chromeos::switches::kIgnoreUserProfileMappingForTests);
43 #endif
46 private:
47 DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerBrowserTest);
50 // Verify that showing a constrained window disables find.
51 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) {
52 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
54 // Showing constrained window should disable find.
55 content::WebContents* web_contents =
56 browser()->tab_strip_model()->GetActiveWebContents();
57 MockTabModalConfirmDialogDelegate* delegate =
58 new MockTabModalConfirmDialogDelegate(web_contents, NULL);
59 TabModalConfirmDialog::Create(delegate, web_contents);
60 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
62 // Switching to a new (unblocked) tab should reenable it.
63 AddBlankTabAndShow(browser());
64 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
66 // Switching back to the blocked tab should disable it again.
67 browser()->tab_strip_model()->ActivateTabAt(0, false);
68 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
70 // Closing the constrained window should reenable it.
71 delegate->Cancel();
72 content::RunAllPendingInMessageLoop();
73 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
76 // Note that a Browser's destructor, when the browser's profile is guest, will
77 // create and execute a BrowsingDataRemover.
78 // Flakes http://crbug.com/471953
79 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest,
80 DISABLED_NewAvatarMenuEnabledInGuestMode) {
81 switches::EnableNewAvatarMenuForTesting(
82 base::CommandLine::ForCurrentProcess());
84 EXPECT_EQ(1U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size());
86 // Create a guest browser nicely. Using CreateProfile() and CreateBrowser()
87 // does incomplete initialization that would lead to
88 // SystemUrlRequestContextGetter being leaked.
89 content::WindowedNotificationObserver browser_creation_observer(
90 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
91 content::NotificationService::AllSources());
92 profiles::SwitchToGuestProfile(chrome::GetActiveDesktop(),
93 ProfileManager::CreateCallback());
95 // RunUntilIdle() (racily) isn't sufficient to ensure browser creation, so
96 // listen for the notification.
97 base::MessageLoop::current()->RunUntilIdle();
98 browser_creation_observer.Wait();
99 EXPECT_EQ(2U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size());
101 // Access the browser that was created for the new Guest Profile.
102 Profile* guest = g_browser_process->profile_manager()->GetProfileByPath(
103 ProfileManager::GetGuestProfilePath());
104 Browser* browser = chrome::FindAnyBrowser(
105 guest, true, chrome::GetActiveDesktop());
106 EXPECT_TRUE(browser);
108 // The BrowsingDataRemover needs a loaded TemplateUrlService or else it hangs
109 // on to a CallbackList::Subscription forever.
110 TemplateURLServiceFactory::GetForProfile(guest)->set_loaded(true);
112 const CommandUpdater* command_updater =
113 browser->command_controller()->command_updater();
114 #if defined(OS_CHROMEOS)
115 // Chrome OS uses system tray menu to handle multi-profiles.
116 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
117 #else
118 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
119 #endif