| 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" |
| 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/policy/browser_policy_connector.h" |
| 11 #include "chrome/browser/profiles/chrome_version_service.h" | 13 #include "chrome/browser/profiles/chrome_version_service.h" |
| 12 #include "chrome/browser/profiles/profile_impl.h" | 14 #include "chrome/browser/profiles/profile_impl.h" |
| 13 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/chrome_version_info.h" | 17 #include "chrome/common/chrome_version_info.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 22 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 43 created_by_version = version_info.Version(); | 45 created_by_version = version_info.Version(); |
| 44 } else { | 46 } else { |
| 45 created_by_version = "1.0.0.0"; | 47 created_by_version = "1.0.0.0"; |
| 46 } | 48 } |
| 47 std::string pref_version = | 49 std::string pref_version = |
| 48 ChromeVersionService::GetVersion(profile->GetPrefs()); | 50 ChromeVersionService::GetVersion(profile->GetPrefs()); |
| 49 // Assert that created_by_version pref gets set to current version. | 51 // Assert that created_by_version pref gets set to current version. |
| 50 EXPECT_EQ(created_by_version, pref_version); | 52 EXPECT_EQ(created_by_version, pref_version); |
| 51 } | 53 } |
| 52 | 54 |
| 55 // Helper function that makes sure all the PrefStores for the profile's |
| 56 // PrefService are initialized. |
| 57 void InitializeAllPrefStores() { |
| 58 #if defined(OS_CHROMEOS) |
| 59 // On enterprise Chrome OS devices, the policy PrefStore only becomes ready |
| 60 // after refreshing the user policy, so that the Profile PrefService sees the |
| 61 // right managed values. On non-enterprise devices this behavior is disabled |
| 62 // after a sign-in; signal that here too, for the test. |
| 63 policy::BrowserPolicyConnector* connector = |
| 64 g_browser_process->browser_policy_connector(); |
| 65 if (connector) |
| 66 connector->InitializeUserPolicy("", false); |
| 67 #endif |
| 68 } |
| 69 |
| 53 } // namespace | 70 } // namespace |
| 54 | 71 |
| 55 typedef InProcessBrowserTest ProfileBrowserTest; | 72 typedef InProcessBrowserTest ProfileBrowserTest; |
| 56 | 73 |
| 57 // Test OnProfileCreate is called with is_new_profile set to true when | 74 // Test OnProfileCreate is called with is_new_profile set to true when |
| 58 // creating a new profile synchronously. | 75 // creating a new profile synchronously. |
| 59 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileSynchronous) { | 76 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateNewProfileSynchronous) { |
| 60 ScopedTempDir temp_dir; | 77 ScopedTempDir temp_dir; |
| 61 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 78 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 62 | 79 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 91 ScopedTempDir temp_dir; | 108 ScopedTempDir temp_dir; |
| 92 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 109 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 93 | 110 |
| 94 MockProfileDelegate delegate; | 111 MockProfileDelegate delegate; |
| 95 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 112 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
| 96 | 113 |
| 97 scoped_ptr<Profile> profile(Profile::CreateProfile( | 114 scoped_ptr<Profile> profile(Profile::CreateProfile( |
| 98 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 115 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
| 99 ASSERT_TRUE(profile.get()); | 116 ASSERT_TRUE(profile.get()); |
| 100 | 117 |
| 118 InitializeAllPrefStores(); |
| 119 |
| 101 // Wait for the profile to be created. | 120 // Wait for the profile to be created. |
| 102 ui_test_utils::WindowedNotificationObserver observer( | 121 ui_test_utils::WindowedNotificationObserver observer( |
| 103 chrome::NOTIFICATION_PROFILE_CREATED, | 122 chrome::NOTIFICATION_PROFILE_CREATED, |
| 104 content::Source<Profile>(profile.get())); | 123 content::Source<Profile>(profile.get())); |
| 105 observer.Wait(); | 124 observer.Wait(); |
| 106 CheckChromeVersion(profile.get(), true); | 125 CheckChromeVersion(profile.get(), true); |
| 107 } | 126 } |
| 108 | 127 |
| 109 // Test OnProfileCreate is called with is_new_profile set to false when | 128 // Test OnProfileCreate is called with is_new_profile set to false when |
| 110 // creating a profile asynchronously with an existing prefs file. | 129 // creating a profile asynchronously with an existing prefs file. |
| 111 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileAsynchronous) { | 130 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, CreateOldProfileAsynchronous) { |
| 112 ScopedTempDir temp_dir; | 131 ScopedTempDir temp_dir; |
| 113 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 132 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 114 CreatePrefsFileInDirectory(temp_dir.path()); | 133 CreatePrefsFileInDirectory(temp_dir.path()); |
| 115 | 134 |
| 116 MockProfileDelegate delegate; | 135 MockProfileDelegate delegate; |
| 117 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); | 136 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); |
| 118 scoped_ptr<Profile> profile(Profile::CreateProfile( | 137 scoped_ptr<Profile> profile(Profile::CreateProfile( |
| 119 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 138 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
| 120 ASSERT_TRUE(profile.get()); | 139 ASSERT_TRUE(profile.get()); |
| 121 | 140 |
| 141 InitializeAllPrefStores(); |
| 142 |
| 122 // Wait for the profile to be created. | 143 // Wait for the profile to be created. |
| 123 ui_test_utils::WindowedNotificationObserver observer( | 144 ui_test_utils::WindowedNotificationObserver observer( |
| 124 chrome::NOTIFICATION_PROFILE_CREATED, | 145 chrome::NOTIFICATION_PROFILE_CREATED, |
| 125 content::Source<Profile>(profile.get())); | 146 content::Source<Profile>(profile.get())); |
| 126 observer.Wait(); | 147 observer.Wait(); |
| 127 CheckChromeVersion(profile.get(), false); | 148 CheckChromeVersion(profile.get(), false); |
| 128 } | 149 } |
| 129 | 150 |
| 130 // Test that a README file is created for profiles that didn't have it. | 151 // Test that a README file is created for profiles that didn't have it. |
| 131 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileReadmeCreated) { | 152 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileReadmeCreated) { |
| 132 ScopedTempDir temp_dir; | 153 ScopedTempDir temp_dir; |
| 133 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 154 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 134 | 155 |
| 135 MockProfileDelegate delegate; | 156 MockProfileDelegate delegate; |
| 136 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 157 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
| 137 | 158 |
| 138 // No delay before README creation. | 159 // No delay before README creation. |
| 139 ProfileImpl::create_readme_delay_ms = 0; | 160 ProfileImpl::create_readme_delay_ms = 0; |
| 140 | 161 |
| 141 scoped_ptr<Profile> profile(Profile::CreateProfile( | 162 scoped_ptr<Profile> profile(Profile::CreateProfile( |
| 142 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 163 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
| 143 ASSERT_TRUE(profile.get()); | 164 ASSERT_TRUE(profile.get()); |
| 144 | 165 |
| 166 InitializeAllPrefStores(); |
| 167 |
| 145 // Wait for the profile to be created. | 168 // Wait for the profile to be created. |
| 146 ui_test_utils::WindowedNotificationObserver observer( | 169 ui_test_utils::WindowedNotificationObserver observer( |
| 147 chrome::NOTIFICATION_PROFILE_CREATED, | 170 chrome::NOTIFICATION_PROFILE_CREATED, |
| 148 content::Source<Profile>(profile.get())); | 171 content::Source<Profile>(profile.get())); |
| 149 observer.Wait(); | 172 observer.Wait(); |
| 150 | 173 |
| 151 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 174 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 152 | 175 |
| 153 // Verify that README exists. | 176 // Verify that README exists. |
| 154 EXPECT_TRUE(file_util::PathExists( | 177 EXPECT_TRUE(file_util::PathExists( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 169 scoped_ptr<Profile> profile(Profile::CreateProfile( | 192 scoped_ptr<Profile> profile(Profile::CreateProfile( |
| 170 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 193 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
| 171 ASSERT_TRUE(profile.get()); | 194 ASSERT_TRUE(profile.get()); |
| 172 | 195 |
| 173 // Delete the Profile instance and run pending tasks (this includes the task | 196 // Delete the Profile instance and run pending tasks (this includes the task |
| 174 // for README creation). | 197 // for README creation). |
| 175 profile.reset(); | 198 profile.reset(); |
| 176 ui_test_utils::RunAllPendingInMessageLoop(); | 199 ui_test_utils::RunAllPendingInMessageLoop(); |
| 177 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 200 ui_test_utils::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
| 178 } | 201 } |
| OLD | NEW |