| OLD | NEW |
| 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/profiles/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/platform_file.h" | 8 #include "base/platform_file.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/version.h" | 10 #include "base/version.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 92 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 93 | 93 |
| 94 MockProfileDelegate delegate; | 94 MockProfileDelegate delegate; |
| 95 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 95 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
| 96 | 96 |
| 97 scoped_ptr<Profile> profile(Profile::CreateProfile( | 97 scoped_ptr<Profile> profile(Profile::CreateProfile( |
| 98 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 98 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
| 99 ASSERT_TRUE(profile.get()); | 99 ASSERT_TRUE(profile.get()); |
| 100 | 100 |
| 101 // Wait for the profile to be created. | 101 // Wait for the profile to be created. |
| 102 ui_test_utils::WindowedNotificationObserver observer( | 102 content::WindowedNotificationObserver observer( |
| 103 chrome::NOTIFICATION_PROFILE_CREATED, | 103 chrome::NOTIFICATION_PROFILE_CREATED, |
| 104 content::Source<Profile>(profile.get())); | 104 content::Source<Profile>(profile.get())); |
| 105 observer.Wait(); | 105 observer.Wait(); |
| 106 CheckChromeVersion(profile.get(), true); | 106 CheckChromeVersion(profile.get(), true); |
| 107 } | 107 } |
| 108 | 108 |
| 109 // Test OnProfileCreate is called with is_new_profile set to false when | 109 // Test OnProfileCreate is called with is_new_profile set to false when |
| 110 // creating a profile asynchronously with an existing prefs file. | 110 // creating a profile asynchronously with an existing prefs file. |
| 111 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileAsynchronous) { | 111 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileAsynchronous) { |
| 112 ScopedTempDir temp_dir; | 112 ScopedTempDir temp_dir; |
| 113 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 113 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 114 CreatePrefsFileInDirectory(temp_dir.path()); | 114 CreatePrefsFileInDirectory(temp_dir.path()); |
| 115 | 115 |
| 116 MockProfileDelegate delegate; | 116 MockProfileDelegate delegate; |
| 117 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); | 117 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); |
| 118 scoped_ptr<Profile> profile(Profile::CreateProfile( | 118 scoped_ptr<Profile> profile(Profile::CreateProfile( |
| 119 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 119 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
| 120 ASSERT_TRUE(profile.get()); | 120 ASSERT_TRUE(profile.get()); |
| 121 | 121 |
| 122 // Wait for the profile to be created. | 122 // Wait for the profile to be created. |
| 123 ui_test_utils::WindowedNotificationObserver observer( | 123 content::WindowedNotificationObserver observer( |
| 124 chrome::NOTIFICATION_PROFILE_CREATED, | 124 chrome::NOTIFICATION_PROFILE_CREATED, |
| 125 content::Source<Profile>(profile.get())); | 125 content::Source<Profile>(profile.get())); |
| 126 observer.Wait(); | 126 observer.Wait(); |
| 127 CheckChromeVersion(profile.get(), false); | 127 CheckChromeVersion(profile.get(), false); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Test that a README file is created for profiles that didn't have it. | 130 // Test that a README file is created for profiles that didn't have it. |
| 131 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileReadmeCreated) { | 131 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileReadmeCreated) { |
| 132 ScopedTempDir temp_dir; | 132 ScopedTempDir temp_dir; |
| 133 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 133 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 134 | 134 |
| 135 MockProfileDelegate delegate; | 135 MockProfileDelegate delegate; |
| 136 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 136 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
| 137 | 137 |
| 138 // No delay before README creation. | 138 // No delay before README creation. |
| 139 ProfileImpl::create_readme_delay_ms = 0; | 139 ProfileImpl::create_readme_delay_ms = 0; |
| 140 | 140 |
| 141 scoped_ptr<Profile> profile(Profile::CreateProfile( | 141 scoped_ptr<Profile> profile(Profile::CreateProfile( |
| 142 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 142 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
| 143 ASSERT_TRUE(profile.get()); | 143 ASSERT_TRUE(profile.get()); |
| 144 | 144 |
| 145 // Wait for the profile to be created. | 145 // Wait for the profile to be created. |
| 146 ui_test_utils::WindowedNotificationObserver observer( | 146 content::WindowedNotificationObserver observer( |
| 147 chrome::NOTIFICATION_PROFILE_CREATED, | 147 chrome::NOTIFICATION_PROFILE_CREATED, |
| 148 content::Source<Profile>(profile.get())); | 148 content::Source<Profile>(profile.get())); |
| 149 observer.Wait(); | 149 observer.Wait(); |
| 150 | 150 |
| 151 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 151 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 152 | 152 |
| 153 // Verify that README exists. | 153 // Verify that README exists. |
| 154 EXPECT_TRUE(file_util::PathExists( | 154 EXPECT_TRUE(file_util::PathExists( |
| 155 temp_dir.path().Append(chrome::kReadmeFilename))); | 155 temp_dir.path().Append(chrome::kReadmeFilename))); |
| 156 } | 156 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 169 scoped_ptr<Profile> profile(Profile::CreateProfile( | 169 scoped_ptr<Profile> profile(Profile::CreateProfile( |
| 170 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 170 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
| 171 ASSERT_TRUE(profile.get()); | 171 ASSERT_TRUE(profile.get()); |
| 172 | 172 |
| 173 // Delete the Profile instance and run pending tasks (this includes the task | 173 // Delete the Profile instance and run pending tasks (this includes the task |
| 174 // for README creation). | 174 // for README creation). |
| 175 profile.reset(); | 175 profile.reset(); |
| 176 ui_test_utils::RunAllPendingInMessageLoop(); | 176 ui_test_utils::RunAllPendingInMessageLoop(); |
| 177 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 177 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 178 } | 178 } |
| OLD | NEW |