Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/profiles/profile_browsertest.cc

Issue 385123004: Implement the WindowsLogoffRace finch experiment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert chrome_browser_field_trials change. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/lifetime/application_lifetime.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/file_util.h" 8 #include "base/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"
11 #include "base/metrics/field_trial.h"
11 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
12 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
13 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
14 #include "base/values.h" 15 #include "base/values.h"
15 #include "base/version.h" 16 #include "base/version.h"
16 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h" 18 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/profiles/chrome_version_service.h" 19 #include "chrome/browser/profiles/chrome_version_service.h"
19 #include "chrome/browser/profiles/profile_impl.h" 20 #include "chrome/browser/profiles/profile_impl.h"
20 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, 345 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
345 WritesProfilesSynchronouslyOnEndSession) { 346 WritesProfilesSynchronouslyOnEndSession) {
346 base::ScopedTempDir temp_dir; 347 base::ScopedTempDir temp_dir;
347 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 348 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
348 349
349 ProfileManager* profile_manager = g_browser_process->profile_manager(); 350 ProfileManager* profile_manager = g_browser_process->profile_manager();
350 ASSERT_TRUE(profile_manager); 351 ASSERT_TRUE(profile_manager);
351 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles(); 352 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles();
352 353
353 ASSERT_NE(loaded_profiles.size(), 0UL); 354 ASSERT_NE(loaded_profiles.size(), 0UL);
354 for (size_t i = 0; i < loaded_profiles.size(); ++i) { 355 Profile* profile = loaded_profiles[0];
355 Profile* profile = loaded_profiles[i];
356 356
357 // This retry loop reduces flakiness due to the fact that this ultimately
358 // tests whether or not a code path hits a timed wait.
359 bool succeeded = false;
360 for (size_t retries = 0; !succeeded && retries < 3; ++retries) {
357 // Flush the profile data to disk for all loaded profiles. 361 // Flush the profile data to disk for all loaded profiles.
358 profile->SetExitType(Profile::EXIT_CRASHED); 362 profile->SetExitType(Profile::EXIT_CRASHED);
359 FlushTaskRunner(profile->GetIOTaskRunner()); 363 FlushTaskRunner(profile->GetIOTaskRunner());
360 364
361 // Make sure that the prefs file was written with the expected key/value. 365 // Make sure that the prefs file was written with the expected key/value.
362 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); 366 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed");
367
368 // The blocking wait in EndSession has a timeout.
369 base::Time start = base::Time::Now();
370
371 // This must not return until the profile data has been written to disk.
372 // If this test flakes, then logoff on Windows has broken again.
373 g_browser_process->EndSession();
374
375 base::Time end = base::Time::Now();
376
377 // The EndSession timeout is 10 seconds. If we take more than half that,
378 // go around again, as we may have timed out on the wait.
379 // This helps against flakes, and also ensures that if the IO thread starts
380 // blocking systemically for that length of time (e.g. deadlocking or such),
381 // we'll get a consistent test failure.
382 if (end - start > base::TimeDelta::FromSeconds(5))
383 continue;
384
385 // Make sure that the prefs file was written with the expected key/value.
386 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded");
387
388 // Mark the success.
389 succeeded = true;
363 } 390 }
364 391
365 // This must not return until the profile data has been written to disk. 392 ASSERT_TRUE(succeeded) << "profile->EndSession() timed out too often.";
366 // If this test flakes, then logoff on Windows has broken again. 393 }
367 g_browser_process->EndSession();
368 394
369 // Verify that the setting was indeed written. 395 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
370 for (size_t i = 0; i < loaded_profiles.size(); ++i) { 396 EndSessionBrokenSynchronizationExperiment) {
371 Profile* profile = loaded_profiles[i]; 397 base::ScopedTempDir temp_dir;
398 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
399
400 // Select into the field trial group.
401 base::FieldTrialList::CreateFieldTrial("WindowsLogoffRace",
402 "BrokenSynchronization");
403
404 ProfileManager* profile_manager = g_browser_process->profile_manager();
405 ASSERT_TRUE(profile_manager);
406 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles();
407
408 ASSERT_NE(loaded_profiles.size(), 0UL);
409 Profile* profile = loaded_profiles[0];
410
411 bool mis_wrote = false;
412 // This retry loop reduces flakiness due to the fact that this ultimately
413 // tests whether or not a code path hits a timed wait.
414 for (size_t retries = 0; retries < 3; ++retries) {
415 // Flush the profile data to disk for all loaded profiles.
416 profile->SetExitType(Profile::EXIT_CRASHED);
417 FlushTaskRunner(profile->GetIOTaskRunner());
418
372 // Make sure that the prefs file was written with the expected key/value. 419 // Make sure that the prefs file was written with the expected key/value.
373 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded"); 420 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed");
421
422 base::WaitableEvent is_blocked(false, false);
423 base::WaitableEvent* unblock = new base::WaitableEvent(false, false);
424
425 // Block the profile's IO thread.
426 profile->GetIOTaskRunner()->PostTask(FROM_HERE,
427 base::Bind(&BlockThread, &is_blocked, base::Owned(unblock)));
428 // Wait for the IO thread to actually be blocked.
429 is_blocked.Wait();
430
431 // The blocking wait in EndSession has a timeout, so a non-write can only be
432 // concluded if it happens in less time than the timeout.
433 base::Time start = base::Time::Now();
434
435 // With the broken synchronization this is expected to return without
436 // blocking for the Profile's IO thread.
437 g_browser_process->EndSession();
438
439 base::Time end = base::Time::Now();
440
441 // The EndSession timeout is 10 seconds, we take a 5 second run-through as
442 // sufficient proof that we didn't hit the timed wait.
443 if (end - start < base::TimeDelta::FromSeconds(5)) {
444 // Make sure that the prefs file is unmodified with the expected
445 // key/value.
446 EXPECT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed");
447 mis_wrote = true;
448 }
449
450 // Release the IO thread thread.
451 unblock->Signal();
374 } 452 }
453
454 ASSERT_TRUE(mis_wrote);
375 } 455 }
456
376 #endif // defined(USE_X11) || defined(OS_WIN) 457 #endif // defined(USE_X11) || defined(OS_WIN)
OLDNEW
« no previous file with comments | « chrome/browser/lifetime/application_lifetime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698