Commit 8d01fd2f authored by Vitaliy Rebrov's avatar Vitaliy Rebrov Committed by Commit Bot

Fixed first_run test failure because of the global variables

Fixed typical problem with unit tests and global variables.
If unit test modifies global variables then it can affect other tests
which are runned in the same process. Added reseting of the global
variables to avoid this.

Change-Id: I2045700473ac074209f4d48a6cedbd3dad24ccd5
Reviewed-on: https://chromium-review.googlesource.com/952905
Commit-Queue: Alexander Yashkin <a-v-y@yandex-team.ru>
Reviewed-by: default avatarCarlos Pizano <cpu@chromium.org>
Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543345}
parent 1df224b2
...@@ -84,6 +84,10 @@ bool g_should_do_autofill_personal_data_manager_first_run = false; ...@@ -84,6 +84,10 @@ bool g_should_do_autofill_personal_data_manager_first_run = false;
first_run::internal::FirstRunState g_first_run = first_run::internal::FirstRunState g_first_run =
first_run::internal::FIRST_RUN_UNKNOWN; first_run::internal::FIRST_RUN_UNKNOWN;
// Cached first run sentinel creation time.
// Used to avoid excess file operations.
base::Time g_cached_sentinel_creation_time;
// This class acts as an observer for the ImporterProgressObserver::ImportEnded // This class acts as an observer for the ImporterProgressObserver::ImportEnded
// callback. When the import process is started, certain errors may cause // callback. When the import process is started, certain errors may cause
// ImportEnded() to be called synchronously, but the typical case is that // ImportEnded() to be called synchronously, but the typical case is that
...@@ -449,8 +453,14 @@ void CreateSentinelIfNeeded() { ...@@ -449,8 +453,14 @@ void CreateSentinelIfNeeded() {
} }
base::Time GetFirstRunSentinelCreationTime() { base::Time GetFirstRunSentinelCreationTime() {
static const base::Time cached_time = ReadFirstRunSentinelCreationTime(); if (g_cached_sentinel_creation_time.is_null())
return cached_time; g_cached_sentinel_creation_time = ReadFirstRunSentinelCreationTime();
return g_cached_sentinel_creation_time;
}
void ResetCachedSentinelDataForTesting() {
g_cached_sentinel_creation_time = base::Time();
g_first_run = first_run::internal::FIRST_RUN_UNKNOWN;
} }
void SetShouldShowWelcomePage() { void SetShouldShowWelcomePage() {
......
...@@ -104,6 +104,10 @@ void CreateSentinelIfNeeded(); ...@@ -104,6 +104,10 @@ void CreateSentinelIfNeeded();
// permission on the sequence it is first called on. // permission on the sequence it is first called on.
base::Time GetFirstRunSentinelCreationTime(); base::Time GetFirstRunSentinelCreationTime();
// Resets the first run status and cached first run sentinel creation time.
// This is needed for unit tests which are runned in the same process.
void ResetCachedSentinelDataForTesting();
// Sets a flag that will cause ShouldShowWelcomePage to return true // Sets a flag that will cause ShouldShowWelcomePage to return true
// exactly once, so that the browser loads the welcome tab once the // exactly once, so that the browser loads the welcome tab once the
// message loop gets going. // message loop gets going.
......
...@@ -22,6 +22,11 @@ class FirstRunTest : public testing::Test { ...@@ -22,6 +22,11 @@ class FirstRunTest : public testing::Test {
FirstRunTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {} FirstRunTest() : user_data_dir_override_(chrome::DIR_USER_DATA) {}
~FirstRunTest() override {} ~FirstRunTest() override {}
void TearDown() override {
first_run::ResetCachedSentinelDataForTesting();
Test::TearDown();
}
private: private:
base::ScopedPathOverride user_data_dir_override_; base::ScopedPathOverride user_data_dir_override_;
......
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