Chromium Code Reviews| Index: chrome/browser/profiles/profile_browsertest.cc |
| diff --git a/chrome/browser/profiles/profile_browsertest.cc b/chrome/browser/profiles/profile_browsertest.cc |
| index a4256df5aea49b7ae8414d461ee3f4f7064676d4..a3b7c22136d40980c306afd7e5219aebdda78d8c 100644 |
| --- a/chrome/browser/profiles/profile_browsertest.cc |
| +++ b/chrome/browser/profiles/profile_browsertest.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/file_util.h" |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/json/json_reader.h" |
| +#include "base/metrics/field_trial.h" |
| #include "base/prefs/pref_service.h" |
| #include "base/sequenced_task_runner.h" |
| #include "base/synchronization/waitable_event.h" |
| @@ -351,26 +352,89 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
| std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles(); |
| ASSERT_NE(loaded_profiles.size(), 0UL); |
| - for (size_t i = 0; i < loaded_profiles.size(); ++i) { |
| - Profile* profile = loaded_profiles[i]; |
| + Profile* profile = loaded_profiles[0]; |
| + // Flush the profile data to disk for all loaded profiles. |
| + profile->SetExitType(Profile::EXIT_CRASHED); |
| + FlushTaskRunner(profile->GetIOTaskRunner()); |
| + |
| + // Make sure that the prefs file was written with the expected key/value. |
| + ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); |
| + |
| + // This must not return until the profile data has been written to disk. |
| + // If this test flakes, then logoff on Windows has broken again. |
| + g_browser_process->EndSession(); |
| + |
| + // Make sure that the prefs file was written with the expected key/value. |
| + ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded"); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
| + EndSessionBrokenSynchronizationExperiment) { |
| + base::ScopedTempDir temp_dir; |
| + ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| + |
| + // Select into the field trial group. |
| + base::FieldTrialList::CreateFieldTrial("WindowsLogoffRace", |
| + "BrokenSynchronization"); |
| + |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + ASSERT_TRUE(profile_manager); |
| + std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles(); |
| + |
| + ASSERT_NE(loaded_profiles.size(), 0UL); |
| + Profile* profile = loaded_profiles[0]; |
| + |
| + bool mis_wrote = false; |
| + // This retry loop reduces flakiness due to the fact that this ultimately |
| + // tests whether or not a code path hits a timed wait. |
| + for (size_t retries = 0; retries < 3; ++retries) { |
| // Flush the profile data to disk for all loaded profiles. |
| profile->SetExitType(Profile::EXIT_CRASHED); |
| FlushTaskRunner(profile->GetIOTaskRunner()); |
| // Make sure that the prefs file was written with the expected key/value. |
| ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); |
| - } |
| - // This must not return until the profile data has been written to disk. |
| - // If this test flakes, then logoff on Windows has broken again. |
| - g_browser_process->EndSession(); |
| + base::WaitableEvent is_blocked(false, false); |
| + base::WaitableEvent* unblock = new base::WaitableEvent(false, false); |
| - // Verify that the setting was indeed written. |
| - for (size_t i = 0; i < loaded_profiles.size(); ++i) { |
| - Profile* profile = loaded_profiles[i]; |
| - // Make sure that the prefs file was written with the expected key/value. |
| - ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded"); |
| + // Block the profile's IO thread. |
| + profile->GetIOTaskRunner()->PostTask(FROM_HERE, |
| + base::Bind(&BlockThread, &is_blocked, base::Owned(unblock))); |
|
gab
2014/07/11 17:13:44
Actually base::Owned here makes it such that |unbl
Sigurður Ásgeirsson
2014/07/14 17:04:14
As we discussed, you've read this backwards. The c
|
| + // Wait for the IO thread to actually be blocked. |
| + is_blocked.Wait(); |
| + |
| + // The blocking wait in EndSession has a timeout, so a non-write can only be |
| + // concluded if it happens in less time than the timeout. |
| + base::Time start = base::Time::Now(); |
| + |
| + // This must not return until the profile data has been written to disk. |
| + // If this test flakes, then logoff on Windows has broken again. |
| + g_browser_process->EndSession(); |
| + |
| + base::Time end = base::Time::Now(); |
| + |
| + // The EndSession timeout is 10 seconds, we take a 5 second run-through as |
| + // sufficient proof that we didn't hit the timed wait. |
| + if (end - start < base::TimeDelta::FromSeconds(5)) { |
|
gab
2014/07/11 17:13:44
Since you're adding this here, I think it makes to
Sigurður Ásgeirsson
2014/07/14 17:04:14
Done.
|
| + // Make sure that the prefs file is unmodified with the expected |
| + // key/value. |
| + EXPECT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); |
| + mis_wrote = true; |
| + } |
| + |
| + // Release the IO thread thread. |
| + unblock->Signal(); |
| } |
| + |
| + // Reset the field trial registration. |
| + // TODO(siggi): is this necessary? Maybe the browser test fixture resets |
| + // the field trial list? |
| + base::FieldTrialList::CreateFieldTrial("WindowsLogoffRace", |
| + "BrokenSynchronization"); |
|
gab
2014/07/11 17:13:44
Each field trial should be unique to a given brows
Sigurður Ásgeirsson
2014/07/14 17:04:14
Done.
|
| + |
| + ASSERT_TRUE(mis_wrote); |
| } |
| + |
| #endif // defined(USE_X11) || defined(OS_WIN) |