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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view_browsertest.cc

Issue 1304943006: ProfileChooserVIew heap-use-after-free fix (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: small fix Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/test/histogram_tester.h" 11 #include "base/test/histogram_tester.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/extensions/extension_browsertest.h" 14 #include "chrome/browser/extensions/extension_browsertest.h"
15 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/profiles/profile_metrics.h" 16 #include "chrome/browser/profiles/profile_metrics.h"
17 #include "chrome/browser/profiles/profiles_state.h" 17 #include "chrome/browser/profiles/profiles_state.h"
18 #include "chrome/browser/ui/browser_commands.h"
18 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/user_manager.h" 20 #include "chrome/browser/ui/user_manager.h"
20 #include "chrome/browser/ui/views/frame/browser_view.h" 21 #include "chrome/browser/ui/views/frame/browser_view.h"
21 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" 22 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h"
22 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" 23 #include "chrome/browser/ui/views/profiles/new_avatar_button.h"
23 #include "chrome/browser/ui/views/profiles/user_manager_view.h" 24 #include "chrome/browser/ui/views/profiles/user_manager_view.h"
24 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
27 #include "components/signin/core/common/profile_management_switches.h" 28 #include "components/signin/core/common/profile_management_switches.h"
(...skipping 15 matching lines...) Expand all
43 NOTREACHED() << "Could not create directory at " << path.MaybeAsASCII(); 44 NOTREACHED() << "Could not create directory at " << path.MaybeAsASCII();
44 45
45 Profile* profile = 46 Profile* profile =
46 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS); 47 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
47 profile_manager->RegisterTestingProfile(profile, true, false); 48 profile_manager->RegisterTestingProfile(profile, true, false);
48 EXPECT_EQ(starting_number_of_profiles + 1, 49 EXPECT_EQ(starting_number_of_profiles + 1,
49 profile_manager->GetNumberOfProfiles()); 50 profile_manager->GetNumberOfProfiles());
50 return profile; 51 return profile;
51 } 52 }
52 53
54 Profile* CreateProfileOutsideUserDataDir() {
55 base::FilePath path;
56 if (!base::CreateNewTempDirectory(base::FilePath::StringType(), &path))
57 NOTREACHED() << "Could not create directory at " << path.MaybeAsASCII();
58
59 ProfileManager* profile_manager = g_browser_process->profile_manager();
60 Profile* profile =
61 Profile::CreateProfile(path, NULL, Profile::CREATE_MODE_SYNCHRONOUS);
62 profile_manager->RegisterTestingProfile(profile, true, false);
63 return profile;
64 }
65
66 void CloseBrowser(Browser* browser) {
67 content::WindowedNotificationObserver close_observer(
68 chrome::NOTIFICATION_BROWSER_CLOSED,
69 content::Source<Browser>(browser));
70 chrome::CloseWindow(browser);
71 close_observer.Wait();
72 }
73
53 // Set up the profiles to enable Lock. Takes as parameter a profile that will be 74 // Set up the profiles to enable Lock. Takes as parameter a profile that will be
54 // signed in, and also creates a supervised user (necessary for lock). 75 // signed in, and also creates a supervised user (necessary for lock).
55 void SetupProfilesForLock(Profile* signed_in) { 76 void SetupProfilesForLock(Profile* signed_in) {
56 const char* signed_in_email = "me@google.com"; 77 const char* signed_in_email = "me@google.com";
57 Profile* supervised = CreateTestingProfile("supervised"); 78 Profile* supervised = CreateTestingProfile("supervised");
58 ProfileInfoCache* cache = &g_browser_process->profile_manager()-> 79 ProfileInfoCache* cache = &g_browser_process->profile_manager()->
59 GetProfileInfoCache(); 80 GetProfileInfoCache();
60 cache->SetAuthInfoOfProfileAtIndex(cache->GetIndexOfProfileWithPath( 81 cache->SetAuthInfoOfProfileAtIndex(cache->GetIndexOfProfileWithPath(
61 signed_in->GetPath()), "12345", base::UTF8ToUTF16(signed_in_email)); 82 signed_in->GetPath()), "12345", base::UTF8ToUTF16(signed_in_email));
62 signed_in->GetPrefs()-> 83 signed_in->GetPrefs()->
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 current_profile_bubble()->avatar_menu_.get()); 198 current_profile_bubble()->avatar_menu_.get());
178 base::MessageLoop::current()->RunUntilIdle(); 199 base::MessageLoop::current()->RunUntilIdle();
179 } 200 }
180 201
181 private: 202 private:
182 scoped_ptr<content::WindowedNotificationObserver> window_close_observer_; 203 scoped_ptr<content::WindowedNotificationObserver> window_close_observer_;
183 204
184 DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewExtensionsTest); 205 DISALLOW_COPY_AND_ASSIGN(ProfileChooserViewExtensionsTest);
185 }; 206 };
186 207
208 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest,
209 ProfileChooserOnMultipleBrowsers) {
210 // Test that the profile chooser view should be deleted when the browser is
211 // deleted. Even if the profile is not in user_data_dir.
msw 2015/09/10 23:42:00 Why does the profile's location matter for this te
212 Profile* new_profile = CreateProfileOutsideUserDataDir();
213 Browser* browser = CreateBrowser(new_profile);
214 browser->window()->ShowAvatarBubbleFromAvatarButton(
215 BrowserWindow::AVATAR_BUBBLE_MODE_CONFIRM_SIGNIN,
216 signin::ManageAccountsParams());
217 EXPECT_TRUE(ProfileChooserView::IsShowing());
218 CloseBrowser(browser);
219 ASSERT_FALSE(ProfileChooserView::IsShowing()) << "Bubble was not deleted";
220 }
221
187 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, SigninButtonHasFocus) { 222 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, SigninButtonHasFocus) {
188 ASSERT_TRUE(profiles::IsMultipleProfilesEnabled()); 223 ASSERT_TRUE(profiles::IsMultipleProfilesEnabled());
189 ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView(browser())); 224 ASSERT_NO_FATAL_FAILURE(OpenProfileChooserView(browser()));
190 225
191 EXPECT_TRUE(signin_current_profile_link()->HasFocus()); 226 EXPECT_TRUE(signin_current_profile_link()->HasFocus());
192 } 227 }
193 228
194 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, ContentAreaHasFocus) { 229 IN_PROC_BROWSER_TEST_F(ProfileChooserViewExtensionsTest, ContentAreaHasFocus) {
195 ASSERT_TRUE(profiles::IsMultipleProfilesEnabled()); 230 ASSERT_TRUE(profiles::IsMultipleProfilesEnabled());
196 231
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 EXPECT_EQ(1U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size()); 323 EXPECT_EQ(1U, BrowserList::GetInstance(chrome::GetActiveDesktop())->size());
289 324
290 WaitForUserManager(); 325 WaitForUserManager();
291 // Assert that the first profile's extensions are not blocked. 326 // Assert that the first profile's extensions are not blocked.
292 ASSERT_EQ(total_enabled_extensions, registry->enabled_extensions().size()); 327 ASSERT_EQ(total_enabled_extensions, registry->enabled_extensions().size());
293 ASSERT_EQ(0U, registry->blocked_extensions().size()); 328 ASSERT_EQ(0U, registry->blocked_extensions().size());
294 329
295 // We need to hide the User Manager or else the process can't die. 330 // We need to hide the User Manager or else the process can't die.
296 UserManager::Hide(); 331 UserManager::Hide();
297 } 332 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698