| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" | 22 #include "chrome/browser/profiles/startup_task_runner_service_factory.h" |
| 23 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 24 #include "chrome/common/chrome_version_info.h" | 24 #include "chrome/common/chrome_version_info.h" |
| 25 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 26 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
| 27 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 32 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 32 #include "chromeos/chromeos_switches.h" | 33 #include "chromeos/chromeos_switches.h" |
| 33 #endif | 34 #endif |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 class MockProfileDelegate : public Profile::Delegate { | 38 class MockProfileDelegate : public Profile::Delegate { |
| 38 public: | 39 public: |
| 39 MOCK_METHOD1(OnPrefsLoaded, void(Profile*)); | 40 MOCK_METHOD1(OnPrefsLoaded, void(Profile*)); |
| 40 MOCK_METHOD3(OnProfileCreated, void(Profile*, bool, bool)); | 41 MOCK_METHOD3(OnProfileCreated, void(Profile*, bool, bool)); |
| 41 }; | 42 }; |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 base::ScopedTempDir temp_dir; | 353 base::ScopedTempDir temp_dir; |
| 353 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 354 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 354 | 355 |
| 355 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 356 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 356 ASSERT_TRUE(profile_manager); | 357 ASSERT_TRUE(profile_manager); |
| 357 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles(); | 358 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles(); |
| 358 | 359 |
| 359 ASSERT_NE(loaded_profiles.size(), 0UL); | 360 ASSERT_NE(loaded_profiles.size(), 0UL); |
| 360 Profile* profile = loaded_profiles[0]; | 361 Profile* profile = loaded_profiles[0]; |
| 361 | 362 |
| 363 #if defined(OS_CHROMEOS) |
| 364 for (const auto& loaded_profile : loaded_profiles) { |
| 365 if (!chromeos::ProfileHelper::IsSigninProfile(loaded_profile)) { |
| 366 profile = loaded_profile; |
| 367 break; |
| 368 } |
| 369 } |
| 370 #endif |
| 371 |
| 362 // This retry loop reduces flakiness due to the fact that this ultimately | 372 // This retry loop reduces flakiness due to the fact that this ultimately |
| 363 // tests whether or not a code path hits a timed wait. | 373 // tests whether or not a code path hits a timed wait. |
| 364 bool succeeded = false; | 374 bool succeeded = false; |
| 365 for (size_t retries = 0; !succeeded && retries < 3; ++retries) { | 375 for (size_t retries = 0; !succeeded && retries < 3; ++retries) { |
| 366 // Flush the profile data to disk for all loaded profiles. | 376 // Flush the profile data to disk for all loaded profiles. |
| 367 profile->SetExitType(Profile::EXIT_CRASHED); | 377 profile->SetExitType(Profile::EXIT_CRASHED); |
| 368 FlushTaskRunner(profile->GetIOTaskRunner().get()); | 378 FlushTaskRunner(profile->GetIOTaskRunner().get()); |
| 369 | 379 |
| 370 // Make sure that the prefs file was written with the expected key/value. | 380 // Make sure that the prefs file was written with the expected key/value. |
| 371 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); | 381 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 391 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded"); | 401 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded"); |
| 392 | 402 |
| 393 // Mark the success. | 403 // Mark the success. |
| 394 succeeded = true; | 404 succeeded = true; |
| 395 } | 405 } |
| 396 | 406 |
| 397 ASSERT_TRUE(succeeded) << "profile->EndSession() timed out too often."; | 407 ASSERT_TRUE(succeeded) << "profile->EndSession() timed out too often."; |
| 398 } | 408 } |
| 399 | 409 |
| 400 #endif // defined(USE_X11) || defined(OS_WIN) | 410 #endif // defined(USE_X11) || defined(OS_WIN) |
| OLD | NEW |