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

Side by Side Diff: chrome/browser/ui/browser_command_controller_browsertest.cc

Issue 888843005: Closing a guest session clears all browsing history. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CrOS passes Created 5 years, 10 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 | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/browser_command_controller_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 (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 #if defined(OS_CHROMEOS)
30 #include "chromeos/chromeos_switches.h"
31 #endif
32
33 class BrowserCommandControllerBrowserTest: public InProcessBrowserTest {
34 public:
35 BrowserCommandControllerBrowserTest() {}
36 ~BrowserCommandControllerBrowserTest() override {}
37
38 void SetUpCommandLine(base::CommandLine* command_line) override {
39 InProcessBrowserTest::SetUpCommandLine(command_line);
40
41 #if defined(OS_CHROMEOS)
42 command_line->AppendSwitch(
43 chromeos::switches::kIgnoreUserProfileMappingForTests);
44 #endif
45 }
46
47 private:
48 DISALLOW_COPY_AND_ASSIGN(BrowserCommandControllerBrowserTest);
49 };
16 50
17 // Verify that showing a constrained window disables find. 51 // Verify that showing a constrained window disables find.
18 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) { 52 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest, DisableFind) {
19 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); 53 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
20 54
21 // Showing constrained window should disable find. 55 // Showing constrained window should disable find.
22 content::WebContents* web_contents = 56 content::WebContents* web_contents =
23 browser()->tab_strip_model()->GetActiveWebContents(); 57 browser()->tab_strip_model()->GetActiveWebContents();
24 MockTabModalConfirmDialogDelegate* delegate = 58 MockTabModalConfirmDialogDelegate* delegate =
25 new MockTabModalConfirmDialogDelegate(web_contents, NULL); 59 new MockTabModalConfirmDialogDelegate(web_contents, NULL);
26 TabModalConfirmDialog::Create(delegate, web_contents); 60 TabModalConfirmDialog::Create(delegate, web_contents);
27 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND)); 61 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
28 62
29 // Switching to a new (unblocked) tab should reenable it. 63 // Switching to a new (unblocked) tab should reenable it.
30 AddBlankTabAndShow(browser()); 64 AddBlankTabAndShow(browser());
31 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); 65 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
32 66
33 // Switching back to the blocked tab should disable it again. 67 // Switching back to the blocked tab should disable it again.
34 browser()->tab_strip_model()->ActivateTabAt(0, false); 68 browser()->tab_strip_model()->ActivateTabAt(0, false);
35 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND)); 69 EXPECT_FALSE(chrome::IsCommandEnabled(browser(), IDC_FIND));
36 70
37 // Closing the constrained window should reenable it. 71 // Closing the constrained window should reenable it.
38 delegate->Cancel(); 72 delegate->Cancel();
39 content::RunAllPendingInMessageLoop(); 73 content::RunAllPendingInMessageLoop();
40 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND)); 74 EXPECT_TRUE(chrome::IsCommandEnabled(browser(), IDC_FIND));
41 } 75 }
76
77 // Note that a Browser's destructor, when the browser's profile is guest, will
78 // create and execute a BrowsingDataRemover.
79 IN_PROC_BROWSER_TEST_F(BrowserCommandControllerBrowserTest,
80 NewAvatarMenuEnabledInGuestMode) {
81 switches::EnableNewAvatarMenuForTesting(
82 base::CommandLine::ForCurrentProcess());
83
84 EXPECT_EQ(1U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size());
85
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());
94
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());
100
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);
107
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);
111
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
120 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/browser_command_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698