OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/profiles/profile_window.h" | 5 #include "chrome/browser/profiles/profile_window.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 ~ProfileWindowBrowserTest() override {} | 95 ~ProfileWindowBrowserTest() override {} |
96 | 96 |
97 Browser* OpenGuestBrowser(); | 97 Browser* OpenGuestBrowser(); |
98 void CloseBrowser(Browser* browser); | 98 void CloseBrowser(Browser* browser); |
99 | 99 |
100 private: | 100 private: |
101 DISALLOW_COPY_AND_ASSIGN(ProfileWindowBrowserTest); | 101 DISALLOW_COPY_AND_ASSIGN(ProfileWindowBrowserTest); |
102 }; | 102 }; |
103 | 103 |
104 Browser* ProfileWindowBrowserTest::OpenGuestBrowser() { | 104 Browser* ProfileWindowBrowserTest::OpenGuestBrowser() { |
105 size_t num_browsers = | 105 size_t num_browsers = BrowserList::GetInstance()->size(); |
106 BrowserList::GetInstance(chrome::GetActiveDesktop())->size(); | |
107 | 106 |
108 // Create a guest browser nicely. Using CreateProfile() and CreateBrowser() | 107 // Create a guest browser nicely. Using CreateProfile() and CreateBrowser() |
109 // does incomplete initialization that would lead to | 108 // does incomplete initialization that would lead to |
110 // SystemUrlRequestContextGetter being leaked. | 109 // SystemUrlRequestContextGetter being leaked. |
111 content::WindowedNotificationObserver browser_creation_observer( | 110 content::WindowedNotificationObserver browser_creation_observer( |
112 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 111 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
113 content::NotificationService::AllSources()); | 112 content::NotificationService::AllSources()); |
114 profiles::SwitchToGuestProfile(chrome::GetActiveDesktop(), | 113 profiles::SwitchToGuestProfile(chrome::GetActiveDesktop(), |
115 ProfileManager::CreateCallback()); | 114 ProfileManager::CreateCallback()); |
116 | 115 |
117 browser_creation_observer.Wait(); | 116 browser_creation_observer.Wait(); |
118 DCHECK_NE(static_cast<Profile*>(nullptr), | 117 DCHECK_NE(static_cast<Profile*>(nullptr), |
119 g_browser_process->profile_manager()->GetProfileByPath( | 118 g_browser_process->profile_manager()->GetProfileByPath( |
120 ProfileManager::GetGuestProfilePath())); | 119 ProfileManager::GetGuestProfilePath())); |
121 EXPECT_EQ(num_browsers + 1, | 120 EXPECT_EQ(num_browsers + 1, BrowserList::GetInstance()->size()); |
122 BrowserList::GetInstance(chrome::GetActiveDesktop())->size()); | |
123 | 121 |
124 Profile* guest = g_browser_process->profile_manager()->GetProfileByPath( | 122 Profile* guest = g_browser_process->profile_manager()->GetProfileByPath( |
125 ProfileManager::GetGuestProfilePath()); | 123 ProfileManager::GetGuestProfilePath()); |
126 Browser* browser = chrome::FindAnyBrowser( | 124 Browser* browser = chrome::FindAnyBrowser( |
127 guest, true, chrome::GetActiveDesktop()); | 125 guest, true, chrome::GetActiveDesktop()); |
128 EXPECT_TRUE(browser); | 126 EXPECT_TRUE(browser); |
129 | 127 |
130 // When |browser| closes a BrowsingDataRemover will be created and executed. | 128 // When |browser| closes a BrowsingDataRemover will be created and executed. |
131 // It needs a loaded TemplateUrlService or else it hangs on to a | 129 // It needs a loaded TemplateUrlService or else it hangs on to a |
132 // CallbackList::Subscription forever. | 130 // CallbackList::Subscription forever. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 AppMenuModel model_normal_profile(&accelerator_handler, browser()); | 208 AppMenuModel model_normal_profile(&accelerator_handler, browser()); |
211 EXPECT_NE(-1, model_normal_profile.GetIndexOfCommandId(IDC_BOOKMARKS_MENU)); | 209 EXPECT_NE(-1, model_normal_profile.GetIndexOfCommandId(IDC_BOOKMARKS_MENU)); |
212 | 210 |
213 // Guest browser has no bookmark menu. | 211 // Guest browser has no bookmark menu. |
214 Browser* guest_browser = OpenGuestBrowser(); | 212 Browser* guest_browser = OpenGuestBrowser(); |
215 AppMenuModel model_guest_profile(&accelerator_handler, guest_browser); | 213 AppMenuModel model_guest_profile(&accelerator_handler, guest_browser); |
216 EXPECT_EQ(-1, model_guest_profile.GetIndexOfCommandId(IDC_BOOKMARKS_MENU)); | 214 EXPECT_EQ(-1, model_guest_profile.GetIndexOfCommandId(IDC_BOOKMARKS_MENU)); |
217 } | 215 } |
218 | 216 |
219 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS) | 217 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) && !defined(OS_IOS) |
OLD | NEW |