Commit 8d5362a0 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Fix flaky UpgradeDetectorImplTest.TestPeriodChanges failures.

The test harness drives an UpgradeDetectorImpl by calling its
UpgradeDetected method. In a normal instance, this method is called by
tasks scheduled on detect_upgrade_timer_, which is only started after
the instance has determined whether or not updates are enabled. Since
the test harness was not waiting for this determination to complete, it
was racing with this task. The fix is to disable the update enablement
check in the test so that there's no race.

BUG=832057

Change-Id: Ie8b69a59e7de29aa7da37fe1edba5d324dbed450
Reviewed-on: https://chromium-review.googlesource.com/1012041
Commit-Queue: Greg Thompson <grt@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550734}
parent a6885b53
......@@ -11,10 +11,12 @@
#include "base/macros.h"
#include "base/test/scoped_task_environment.h"
#include "base/time/tick_clock.h"
#include "base/values.h"
#include "chrome/browser/upgrade_observer.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/scoped_testing_local_state.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -102,7 +104,13 @@ class UpgradeDetectorImplTest : public ::testing::Test {
UpgradeDetectorImplTest()
: scoped_task_environment_(
base::test::ScopedTaskEnvironment::MainThreadType::MOCK_TIME),
scoped_local_state_(TestingBrowserProcess::GetGlobal()) {}
scoped_local_state_(TestingBrowserProcess::GetGlobal()) {
// Disable the detector's check to see if autoupdates are inabled.
// Without this, tests put the detector into an invalid state by detecting
// upgrades before the detection task completes.
scoped_local_state_.Get()->SetUserPref(prefs::kAttemptedToEnableAutoupdate,
std::make_unique<base::Value>(true));
}
const base::TickClock* GetMockTickClock() {
return scoped_task_environment_.GetMockTickClock();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment