| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/run_loop.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/values.h" |
| 13 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 14 #include "chrome/app/chrome_command_ids.h" | 16 #include "chrome/app/chrome_command_ids.h" |
| 15 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 18 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/history/history_service_factory.h" | 19 #include "chrome/browser/history/history_service_factory.h" |
| 20 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 18 #include "chrome/browser/profiles/profile_manager.h" | 21 #include "chrome/browser/profiles/profile_manager.h" |
| 19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 20 #include "chrome/browser/signin/signin_manager_factory.h" | 23 #include "chrome/browser/signin/signin_manager_factory.h" |
| 21 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 24 #include "chrome/browser/ui/toolbar/app_menu_model.h" | 27 #include "chrome/browser/ui/toolbar/app_menu_model.h" |
| 25 #include "chrome/test/base/in_process_browser_test.h" | 28 #include "chrome/test/base/in_process_browser_test.h" |
| 26 #include "chrome/test/base/search_test_utils.h" | 29 #include "chrome/test/base/search_test_utils.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" | 30 #include "chrome/test/base/ui_test_utils.h" |
| 31 #include "chrome/test/base/web_ui_browser_test.h" |
| 28 #include "components/history/core/browser/history_db_task.h" | 32 #include "components/history/core/browser/history_db_task.h" |
| 29 #include "components/history/core/browser/history_service.h" | 33 #include "components/history/core/browser/history_service.h" |
| 30 #include "components/search_engines/template_url_service.h" | 34 #include "components/search_engines/template_url_service.h" |
| 31 #include "components/signin/core/common/profile_management_switches.h" | 35 #include "components/signin/core/common/profile_management_switches.h" |
| 32 #include "content/public/browser/notification_service.h" | 36 #include "content/public/browser/notification_service.h" |
| 33 #include "content/public/test/browser_test_utils.h" | 37 #include "content/public/test/browser_test_utils.h" |
| 34 #include "content/public/test/test_utils.h" | 38 #include "content/public/test/test_utils.h" |
| 35 #include "net/test/embedded_test_server/embedded_test_server.h" | 39 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 40 #include "url/gurl.h" |
| 36 | 41 |
| 37 // This test verifies the Desktop implementation of Guest only. | 42 // This test verifies the Desktop implementation of Guest only. |
| 38 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 43 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| 39 | 44 |
| 40 namespace { | 45 namespace { |
| 41 | 46 |
| 42 // Code related to history borrowed from: | 47 // Code related to history borrowed from: |
| 43 // chrome/browser/history/history_browsertest.cc | 48 // chrome/browser/history/history_browsertest.cc |
| 44 | 49 |
| 45 // Note: WaitableEvent is not used for synchronization between the main thread | 50 // Note: WaitableEvent is not used for synchronization between the main thread |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 85 |
| 81 class EmptyAcceleratorHandler : public ui::AcceleratorProvider { | 86 class EmptyAcceleratorHandler : public ui::AcceleratorProvider { |
| 82 public: | 87 public: |
| 83 // Don't handle accelerators. | 88 // Don't handle accelerators. |
| 84 bool GetAcceleratorForCommandId(int command_id, | 89 bool GetAcceleratorForCommandId(int command_id, |
| 85 ui::Accelerator* accelerator) override { | 90 ui::Accelerator* accelerator) override { |
| 86 return false; | 91 return false; |
| 87 } | 92 } |
| 88 }; | 93 }; |
| 89 | 94 |
| 95 base::FilePath CreateTestingProfile(const std::string& name, |
| 96 const std::string& relative_path) { |
| 97 ProfileManager* manager = g_browser_process->profile_manager(); |
| 98 ProfileAttributesStorage& storage = manager->GetProfileAttributesStorage(); |
| 99 size_t starting_number_of_profiles = storage.GetNumberOfProfiles(); |
| 100 |
| 101 base::FilePath profile_path = |
| 102 manager->user_data_dir().AppendASCII(relative_path); |
| 103 storage.AddProfile(profile_path, base::ASCIIToUTF16(name), std::string(), |
| 104 base::string16(), 0u, std::string()); |
| 105 |
| 106 EXPECT_EQ(starting_number_of_profiles + 1u, storage.GetNumberOfProfiles()); |
| 107 return profile_path; |
| 108 } |
| 109 |
| 90 } // namespace | 110 } // namespace |
| 91 | 111 |
| 92 class ProfileWindowBrowserTest : public InProcessBrowserTest { | 112 class ProfileWindowBrowserTest : public InProcessBrowserTest { |
| 93 public: | 113 public: |
| 94 ProfileWindowBrowserTest() {} | 114 ProfileWindowBrowserTest() {} |
| 95 ~ProfileWindowBrowserTest() override {} | 115 ~ProfileWindowBrowserTest() override {} |
| 96 | 116 |
| 97 Browser* OpenGuestBrowser(); | 117 Browser* OpenGuestBrowser(); |
| 98 void CloseBrowser(Browser* browser); | 118 void CloseBrowser(Browser* browser); |
| 99 | 119 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // Verify the normal browser has a bookmark menu. | 225 // Verify the normal browser has a bookmark menu. |
| 206 AppMenuModel model_normal_profile(&accelerator_handler, browser()); | 226 AppMenuModel model_normal_profile(&accelerator_handler, browser()); |
| 207 EXPECT_NE(-1, model_normal_profile.GetIndexOfCommandId(IDC_BOOKMARKS_MENU)); | 227 EXPECT_NE(-1, model_normal_profile.GetIndexOfCommandId(IDC_BOOKMARKS_MENU)); |
| 208 | 228 |
| 209 // Guest browser has no bookmark menu. | 229 // Guest browser has no bookmark menu. |
| 210 Browser* guest_browser = OpenGuestBrowser(); | 230 Browser* guest_browser = OpenGuestBrowser(); |
| 211 AppMenuModel model_guest_profile(&accelerator_handler, guest_browser); | 231 AppMenuModel model_guest_profile(&accelerator_handler, guest_browser); |
| 212 EXPECT_EQ(-1, model_guest_profile.GetIndexOfCommandId(IDC_BOOKMARKS_MENU)); | 232 EXPECT_EQ(-1, model_guest_profile.GetIndexOfCommandId(IDC_BOOKMARKS_MENU)); |
| 213 } | 233 } |
| 214 | 234 |
| 235 class ProfileWindowWebUIBrowserTest : public WebUIBrowserTest { |
| 236 public: |
| 237 void OnSystemProfileCreated(std::string* url_to_test, |
| 238 const base::Closure& quit_loop, |
| 239 Profile* profile, |
| 240 const std::string& url) { |
| 241 *url_to_test = url; |
| 242 quit_loop.Run(); |
| 243 } |
| 244 |
| 245 private: |
| 246 void SetUpOnMainThread() override { |
| 247 WebUIBrowserTest::SetUpOnMainThread(); |
| 248 AddLibrary(base::FilePath( |
| 249 FILE_PATH_LITERAL("profile_window_browsertest.js"))); |
| 250 } |
| 251 }; |
| 252 |
| 253 IN_PROC_BROWSER_TEST_F(ProfileWindowWebUIBrowserTest, |
| 254 UserManagerFocusSingleProfile) { |
| 255 std::string url_to_test; |
| 256 base::RunLoop run_loop; |
| 257 profiles::CreateSystemProfileForUserManager( |
| 258 browser()->profile()->GetPath(), |
| 259 profiles::USER_MANAGER_NO_TUTORIAL, |
| 260 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION, |
| 261 base::Bind(&ProfileWindowWebUIBrowserTest::OnSystemProfileCreated, |
| 262 base::Unretained(this), |
| 263 &url_to_test, |
| 264 run_loop.QuitClosure())); |
| 265 run_loop.Run(); |
| 266 |
| 267 ui_test_utils::NavigateToURL(browser(), GURL(url_to_test)); |
| 268 EXPECT_TRUE(RunJavascriptTest("testNoPodFocused")); |
| 269 } |
| 270 |
| 271 IN_PROC_BROWSER_TEST_F(ProfileWindowWebUIBrowserTest, |
| 272 UserManagerFocusMultipleProfiles) { |
| 273 // The profile names are meant to sort differently by ICU collation and by |
| 274 // naive sorting. See crbug/596280. |
| 275 base::FilePath expected_path = CreateTestingProfile("#abc", "Profile 1"); |
| 276 CreateTestingProfile("?abc", "Profile 2"); |
| 277 |
| 278 std::string url_to_test; |
| 279 base::RunLoop run_loop; |
| 280 profiles::CreateSystemProfileForUserManager( |
| 281 expected_path, |
| 282 profiles::USER_MANAGER_NO_TUTORIAL, |
| 283 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION, |
| 284 base::Bind(&ProfileWindowWebUIBrowserTest::OnSystemProfileCreated, |
| 285 base::Unretained(this), |
| 286 &url_to_test, |
| 287 run_loop.QuitClosure())); |
| 288 run_loop.Run(); |
| 289 |
| 290 ui_test_utils::NavigateToURL(browser(), GURL(url_to_test)); |
| 291 EXPECT_TRUE(RunJavascriptTest( |
| 292 "testPodFocused", new base::StringValue(expected_path.AsUTF8Unsafe()))); |
| 293 } |
| 294 |
| 215 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) | 295 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
| OLD | NEW |