OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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. | |
4 | |
5 #include "base/run_loop.h" | |
6 #include "chrome/browser/browser_process.h" | |
7 #include "chrome/browser/chrome_notification_types.h" | |
8 #include "chrome/browser/profiles/profile_attributes_storage.h" | |
9 #include "chrome/browser/profiles/profile_manager.h" | |
10 #include "chrome/browser/ui/browser.h" | |
11 #include "chrome/browser/ui/browser_list.h" | |
12 #include "chrome/browser/ui/webui/profile_helper.h" | |
13 #include "chrome/test/base/in_process_browser_test.h" | |
14 #include "content/public/browser/notification_service.h" | |
15 #include "content/public/test/test_utils.h" | |
16 #include "content/public/test/test_web_ui.h" | |
17 | |
18 namespace { | |
19 | |
20 // An observer that returns back to test code after a new profile is | |
21 // initialized. | |
22 void UnblockOnProfileCreation(base::RunLoop* run_loop, | |
23 Profile* profile, | |
24 Profile::CreateStatus status) { | |
25 if (status == Profile::CREATE_STATUS_INITIALIZED) | |
26 run_loop->Quit(); | |
27 } | |
28 | |
29 Profile* CreateProfile() { | |
30 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
31 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); | |
32 base::RunLoop run_loop; | |
33 profile_manager->CreateProfileAsync( | |
34 new_path, base::Bind(&UnblockOnProfileCreation, &run_loop), | |
35 base::string16(), std::string(), std::string()); | |
36 run_loop.Run(); | |
37 return profile_manager->GetProfileByPath(new_path); | |
38 } | |
39 | |
40 } // namespace | |
41 | |
42 using ProfileHelperTest = InProcessBrowserTest; | |
43 | |
44 IN_PROC_BROWSER_TEST_F(ProfileHelperTest, OpenNewWindowForProfile) { | |
45 BrowserList* browser_list = BrowserList::GetInstance(); | |
46 | |
47 Browser* original_browser = browser(); | |
48 Profile* original_profile = original_browser->profile(); | |
49 | |
50 // Sanity checks. | |
51 EXPECT_EQ(1u, browser_list->size()); | |
52 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser)); | |
53 | |
54 // Opening existing browser profile shouldn't open additional browser windows. | |
55 webui::OpenNewWindowForProfile(original_profile); | |
56 EXPECT_EQ(1u, browser_list->size()); | |
57 EXPECT_EQ(original_browser, browser_list->GetLastActive()); | |
58 | |
59 // Open additional browser will add new window and activates it. | |
60 Profile* additional_profile = CreateProfile(); | |
61 webui::OpenNewWindowForProfile(additional_profile); | |
62 EXPECT_EQ(2u, browser_list->size()); | |
63 EXPECT_NE(original_browser, browser_list->GetLastActive()); | |
64 | |
65 // Swith to original browser. Only LastActive should change. | |
66 webui::OpenNewWindowForProfile(original_profile); | |
67 EXPECT_EQ(2u, browser_list->size()); | |
68 EXPECT_EQ(original_browser, browser_list->GetLastActive()); | |
69 } | |
70 | |
71 IN_PROC_BROWSER_TEST_F(ProfileHelperTest, DeleteSoleProfile) { | |
72 content::TestWebUI web_ui; | |
73 Browser* original_browser = browser(); | |
74 | |
75 BrowserList* browser_list = BrowserList::GetInstance(); | |
76 EXPECT_EQ(1u, browser_list->size()); | |
77 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser)); | |
78 | |
79 // Original browser will be closed, and browser with the new profile created. | |
80 content::WindowedNotificationObserver open_observer( | |
81 chrome::NOTIFICATION_BROWSER_OPENED, | |
82 content::NotificationService::AllSources()); | |
83 content::WindowedNotificationObserver close_observer( | |
84 chrome::NOTIFICATION_BROWSER_CLOSED, | |
85 content::Source<Browser>(browser())); | |
86 webui::DeleteProfileAtPath(original_browser->profile()->GetPath(), &web_ui, | |
87 ProfileMetrics::DELETE_PROFILE_SETTINGS); | |
88 open_observer.Wait(); | |
89 close_observer.Wait(); | |
90 | |
91 EXPECT_EQ(1u, browser_list->size()); | |
92 EXPECT_FALSE(base::ContainsValue(*browser_list, original_browser)); | |
93 } | |
94 | |
95 IN_PROC_BROWSER_TEST_F(ProfileHelperTest, DeleteActiveProfile) { | |
96 content::TestWebUI web_ui; | |
97 Browser* original_browser = browser(); | |
98 | |
99 BrowserList* browser_list = BrowserList::GetInstance(); | |
100 EXPECT_EQ(1u, browser_list->size()); | |
101 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser)); | |
102 | |
103 Profile* additional_profile = CreateProfile(); | |
104 | |
105 // Original browser will be closed, and browser with the new profile created. | |
106 content::WindowedNotificationObserver open_observer( | |
107 chrome::NOTIFICATION_BROWSER_OPENED, | |
108 content::NotificationService::AllSources()); | |
109 content::WindowedNotificationObserver close_observer( | |
110 chrome::NOTIFICATION_BROWSER_CLOSED, | |
111 content::Source<Browser>(browser())); | |
112 webui::DeleteProfileAtPath(original_browser->profile()->GetPath(), &web_ui, | |
113 ProfileMetrics::DELETE_PROFILE_SETTINGS); | |
114 open_observer.Wait(); | |
115 close_observer.Wait(); | |
116 | |
117 EXPECT_EQ(1u, browser_list->size()); | |
118 EXPECT_EQ(additional_profile, browser_list->get(0)->profile()); | |
119 } | |
120 | |
121 IN_PROC_BROWSER_TEST_F(ProfileHelperTest, DeleteInctiveProfile) { | |
Bernhard Bauer
2017/03/16 16:31:52
Nit: DeleteInactiveProfile
| |
122 content::TestWebUI web_ui; | |
123 Browser* original_browser = browser(); | |
124 ProfileAttributesStorage& storage = | |
125 g_browser_process->profile_manager()->GetProfileAttributesStorage(); | |
126 | |
127 BrowserList* browser_list = BrowserList::GetInstance(); | |
128 EXPECT_EQ(1u, browser_list->size()); | |
129 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser)); | |
130 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); | |
131 | |
132 Profile* additional_profile = CreateProfile(); | |
133 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); | |
134 | |
135 webui::DeleteProfileAtPath(additional_profile->GetPath(), &web_ui, | |
136 ProfileMetrics::DELETE_PROFILE_SETTINGS); | |
137 | |
138 EXPECT_EQ(1u, browser_list->size()); | |
139 EXPECT_TRUE(base::ContainsValue(*browser_list, original_browser)); | |
140 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); | |
141 } | |
OLD | NEW |