[Extensions] Make extension message bubble factory platform-abstract
[chromium-blink-merge.git] / chrome / browser / ui / browser_command_controller_browsertest.cc
blob8a43633a2fd56c436b134cc75837a3d8d64236fc
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 on Linux: http://crbug.com/471953
79 #if defined(OS_LINUX)
80 #define MAYBE_NewAvatarMenuEnabledInGuestMode \
81 DISABLED_NewAvatarMenuEnabledInGuestMode
82 #else
83 #define MAYBE_NewAvatarMenuEnabledInGuestMode NewAvatarMenuEnabledInGuestMode
84 #endif
85 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest,
86 MAYBE_NewAvatarMenuEnabledInGuestMode) {
87 switches::EnableNewAvatarMenuForTesting(
88 base::CommandLine::ForCurrentProcess());
90 EXPECT_EQ(1U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size());
92 // Create a guest browser nicely. Using CreateProfile() and CreateBrowser()
93 // does incomplete initialization that would lead to
94 // SystemUrlRequestContextGetter being leaked.
95 content::WindowedNotificationObserver browser_creation_observer(
96 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
97 content::NotificationService::AllSources());
98 profiles::SwitchToGuestProfile(chrome::GetActiveDesktop(),
99 ProfileManager::CreateCallback());
101 // RunUntilIdle() (racily) isn't sufficient to ensure browser creation, so
102 // listen for the notification.
103 base::MessageLoop::current()->RunUntilIdle();
104 browser_creation_observer.Wait();
105 EXPECT_EQ(2U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size());
107 // Access the browser that was created for the new Guest Profile.
108 Profile* guest = g_browser_process->profile_manager()->GetProfileByPath(
109 ProfileManager::GetGuestProfilePath());
110 Browser* browser = chrome::FindAnyBrowser(
111 guest, true, chrome::GetActiveDesktop());
112 EXPECT_TRUE(browser);
114 // The BrowsingDataRemover needs a loaded TemplateUrlService or else it hangs
115 // on to a CallbackList::Subscription forever.
116 TemplateURLServiceFactory::GetForProfile(guest)->set_loaded(true);
118 const CommandUpdater* command_updater =
119 browser->command_controller()->command_updater();
120 #if defined(OS_CHROMEOS)
121 // Chrome OS uses system tray menu to handle multi-profiles.
122 EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
123 #else
124 EXPECT_TRUE(command_updater->IsCommandEnabled(IDC_SHOW_AVATAR_MENU));
125 #endif