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

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: 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
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 // Flush the profile data to disk for all loaded profiles.
358 profile->SetExitType(Profile::EXIT_CRASHED);
359 FlushTaskRunner(profile->GetIOTaskRunner());
360
361 // Make sure that the prefs file was written with the expected key/value.
362 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed");
363
364 // This must not return until the profile data has been written to disk.
365 // If this test flakes, then logoff on Windows has broken again.
366 g_browser_process->EndSession();
367
368 // Make sure that the prefs file was written with the expected key/value.
369 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded");
370 }
371
372 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
373 EndSessionBrokenSynchronizationExperiment) {
374 base::ScopedTempDir temp_dir;
375 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
376
377 // Select into the field trial group.
378 base::FieldTrialList::CreateFieldTrial("WindowsLogoffRace",
379 "BrokenSynchronization");
380
381 ProfileManager* profile_manager = g_browser_process->profile_manager();
382 ASSERT_TRUE(profile_manager);
383 std::vector<Profile*> loaded_profiles = profile_manager->GetLoadedProfiles();
384
385 ASSERT_NE(loaded_profiles.size(), 0UL);
386 Profile* profile = loaded_profiles[0];
387
388 bool mis_wrote = false;
389 // This retry loop reduces flakiness due to the fact that this ultimately
390 // tests whether or not a code path hits a timed wait.
391 for (size_t retries = 0; retries < 3; ++retries) {
357 // Flush the profile data to disk for all loaded profiles. 392 // Flush the profile data to disk for all loaded profiles.
358 profile->SetExitType(Profile::EXIT_CRASHED); 393 profile->SetExitType(Profile::EXIT_CRASHED);
359 FlushTaskRunner(profile->GetIOTaskRunner()); 394 FlushTaskRunner(profile->GetIOTaskRunner());
360 395
361 // Make sure that the prefs file was written with the expected key/value. 396 // Make sure that the prefs file was written with the expected key/value.
362 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed"); 397 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed");
398
399 base::WaitableEvent is_blocked(false, false);
400 base::WaitableEvent* unblock = new base::WaitableEvent(false, false);
401
402 // Block the profile's IO thread.
403 profile->GetIOTaskRunner()->PostTask(FROM_HERE,
404 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
405 // Wait for the IO thread to actually be blocked.
406 is_blocked.Wait();
407
408 // The blocking wait in EndSession has a timeout, so a non-write can only be
409 // concluded if it happens in less time than the timeout.
410 base::Time start = base::Time::Now();
411
412 // This must not return until the profile data has been written to disk.
413 // If this test flakes, then logoff on Windows has broken again.
414 g_browser_process->EndSession();
415
416 base::Time end = base::Time::Now();
417
418 // The EndSession timeout is 10 seconds, we take a 5 second run-through as
419 // sufficient proof that we didn't hit the timed wait.
420 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.
421 // Make sure that the prefs file is unmodified with the expected
422 // key/value.
423 EXPECT_EQ(GetExitTypePreferenceFromDisk(profile), "Crashed");
424 mis_wrote = true;
425 }
426
427 // Release the IO thread thread.
428 unblock->Signal();
363 } 429 }
364 430
365 // This must not return until the profile data has been written to disk. 431 // Reset the field trial registration.
366 // If this test flakes, then logoff on Windows has broken again. 432 // TODO(siggi): is this necessary? Maybe the browser test fixture resets
367 g_browser_process->EndSession(); 433 // the field trial list?
434 base::FieldTrialList::CreateFieldTrial("WindowsLogoffRace",
435 "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.
368 436
369 // Verify that the setting was indeed written. 437 ASSERT_TRUE(mis_wrote);
370 for (size_t i = 0; i < loaded_profiles.size(); ++i) {
371 Profile* profile = loaded_profiles[i];
372 // Make sure that the prefs file was written with the expected key/value.
373 ASSERT_EQ(GetExitTypePreferenceFromDisk(profile), "SessionEnded");
374 }
375 } 438 }
439
376 #endif // defined(USE_X11) || defined(OS_WIN) 440 #endif // defined(USE_X11) || defined(OS_WIN)
OLDNEW
« chrome/browser/browser_process_impl.cc ('K') | « chrome/browser/lifetime/application_lifetime.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698