update_engine: Cleanup omaha_request_action_unittest.cc.
This patch is a cleanup of the omaha_request_action_unittest. First
it moves members common to all test from the global scope to the
OmahaRequestActionTest class, including the global scope
FakeSystemState instance used on all tests. This fake_system_state
is initialized with a default OmahaRequestParams that is used by many
tests not caring about that parameter. It also sets the default prefs
to a FakePrefs instance, removing the need to create a temp directory
and initialize it in every test. Some tests still replace it with a
MockPrefs when they need to test that some prefs are checked by the
code (testing interaction), but most of them just want to provide a
working Prefs class.
With this change, also the test helper functions were moved to the
OmahaRequestActionTest class, removing the need to pass the optional
classes such as PrefsIterface, PayloadStateInterface, P2PManager and
ConnectionManager which in most tests were passed as nullptr meaning
that the default is used. Instead, with this change, tests that
require a different P2PManager instance for example just create it
and replace it on the fake_system_state_.
This change removes a lot of redundant default code that was hard to
maintain. Now a test requiring to manipulate other classes in the
FakeSystemState class, such as mocking out the HardwareInterface, can
just replace that without adding another parameter to the helper
functions.
BUG=chromium:428792
TEST=Unittest still pass.
Change-Id: Ia3306b11af867d2a1a09be8efae66f6b0326f030
Reviewed-on: https://chromium-review.googlesource.com/226715
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index 0248c22..a4d964d 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -12,10 +12,11 @@
#include <base/strings/stringprintf.h>
#include <base/time/time.h>
#include <chromeos/dbus/service_constants.h>
-#include "gtest/gtest.h"
+#include <gtest/gtest.h>
#include "update_engine/action_pipe.h"
#include "update_engine/constants.h"
+#include "update_engine/fake_prefs.h"
#include "update_engine/mock_connection_manager.h"
#include "update_engine/mock_http_fetcher.h"
#include "update_engine/omaha_hash_calculator.h"
@@ -41,31 +42,89 @@
namespace chromeos_update_engine {
-class OmahaRequestActionTest : public ::testing::Test {};
+class OmahaRequestActionTest : public ::testing::Test {
+ protected:
+ void SetUp() {
+ fake_system_state_.set_request_params(&request_params_);
+ fake_system_state_.set_prefs(&fake_prefs_);
+ }
+
+ // Returns true iff an output response was obtained from the
+ // OmahaRequestAction. |prefs| may be null, in which case a local PrefsMock
+ // is used. |payload_state| may be null, in which case a local mock is used.
+ // |p2p_manager| may be null, in which case a local mock is used.
+ // |connection_manager| may be null, in which case a local mock is used.
+ // out_response may be null. If |fail_http_response_code| is non-negative,
+ // the transfer will fail with that code. |ping_only| is passed through to the
+ // OmahaRequestAction constructor. out_post_data may be null; if non-null, the
+ // post-data received by the mock HttpFetcher is returned.
+ //
+ // The |expected_check_result|, |expected_check_reaction| and
+ // |expected_error_code| parameters are for checking expectations
+ // about reporting UpdateEngine.Check.{Result,Reaction,DownloadError}
+ // UMA statistics. Use the appropriate ::kUnset value to specify that
+ // the given metric should not be reported.
+ bool TestUpdateCheck(OmahaRequestParams* request_params,
+ const string& http_response,
+ int fail_http_response_code,
+ bool ping_only,
+ ErrorCode expected_code,
+ metrics::CheckResult expected_check_result,
+ metrics::CheckReaction expected_check_reaction,
+ metrics::DownloadErrorCode expected_download_error_code,
+ OmahaResponse* out_response,
+ vector<char>* out_post_data);
+
+ // Runs and checks a ping test. |ping_only| indicates wheter it should send
+ // only a ping or also an updatecheck.
+ void PingTest(bool ping_only);
+
+ // InstallDate test helper function.
+ bool InstallDateParseHelper(const std::string &elapsed_days,
+ OmahaResponse *response);
+
+ // P2P test helper function.
+ void P2PTest(
+ bool initial_allow_p2p_for_downloading,
+ bool initial_allow_p2p_for_sharing,
+ bool omaha_disable_p2p_for_downloading,
+ bool omaha_disable_p2p_for_sharing,
+ bool payload_state_allow_p2p_attempt,
+ bool expect_p2p_client_lookup,
+ const string& p2p_client_result_url,
+ bool expected_allow_p2p_for_downloading,
+ bool expected_allow_p2p_for_sharing,
+ const string& expected_p2p_url);
+
+ FakeSystemState fake_system_state_;
+
+ // By default, all tests use these objects unless they replace them in the
+ // fake_system_state_.
+ OmahaRequestParams request_params_ = OmahaRequestParams{
+ &fake_system_state_,
+ OmahaRequestParams::kOsPlatform,
+ OmahaRequestParams::kOsVersion,
+ "service_pack",
+ "x86-generic",
+ OmahaRequestParams::kAppId,
+ "0.1.0.0",
+ "en-US",
+ "unittest",
+ "OEM MODEL 09235 7471",
+ "ChromeOSFirmware.1.0",
+ "0X0A1",
+ false, // delta okay
+ false, // interactive
+ "http://url",
+ "", // target_version_prefix
+ false, // use_p2p_for_downloading
+ false}; // use_p2p_for_sharing
+
+ FakePrefs fake_prefs_;
+};
namespace {
-FakeSystemState fake_system_state;
-OmahaRequestParams kDefaultTestParams(
- &fake_system_state,
- OmahaRequestParams::kOsPlatform,
- OmahaRequestParams::kOsVersion,
- "service_pack",
- "x86-generic",
- OmahaRequestParams::kAppId,
- "0.1.0.0",
- "en-US",
- "unittest",
- "OEM MODEL 09235 7471",
- "ChromeOSFirmware.1.0",
- "0X0A1",
- false, // delta okay
- false, // interactive
- "http://url",
- "", // target_version_prefix
- false, // use_p2p_for_downloading
- false); // use_p2p_for_sharing
-
string GetNoUpdateResponse(const string& app_id) {
return string(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
@@ -222,35 +281,17 @@
OmahaResponse omaha_response_;
};
-// Returns true iff an output response was obtained from the
-// OmahaRequestAction. |prefs| may be null, in which case a local PrefsMock
-// is used. |payload_state| may be null, in which case a local mock is used.
-// |p2p_manager| may be null, in which case a local mock is used.
-// |connection_manager| may be null, in which case a local mock is used.
-// out_response may be null. If |fail_http_response_code| is non-negative,
-// the transfer will fail with that code. |ping_only| is passed through to the
-// OmahaRequestAction constructor. out_post_data may be null; if non-null, the
-// post-data received by the mock HttpFetcher is returned.
-//
-// The |expected_check_result|, |expected_check_reaction| and
-// |expected_error_code| parameters are for checking expectations
-// about reporting UpdateEngine.Check.{Result,Reaction,DownloadError}
-// UMA statistics. Use the appropriate ::kUnset value to specify that
-// the given metric should not be reported.
-bool TestUpdateCheck(PrefsInterface* prefs,
- PayloadStateInterface *payload_state,
- P2PManager *p2p_manager,
- ConnectionManager *connection_manager,
- OmahaRequestParams* params,
- const string& http_response,
- int fail_http_response_code,
- bool ping_only,
- ErrorCode expected_code,
- metrics::CheckResult expected_check_result,
- metrics::CheckReaction expected_check_reaction,
- metrics::DownloadErrorCode expected_download_error_code,
- OmahaResponse* out_response,
- vector<char>* out_post_data) {
+bool OmahaRequestActionTest::TestUpdateCheck(
+ OmahaRequestParams* request_params,
+ const string& http_response,
+ int fail_http_response_code,
+ bool ping_only,
+ ErrorCode expected_code,
+ metrics::CheckResult expected_check_result,
+ metrics::CheckReaction expected_check_reaction,
+ metrics::DownloadErrorCode expected_download_error_code,
+ OmahaResponse* out_response,
+ vector<char>* out_post_data) {
GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
http_response.size(),
@@ -258,17 +299,9 @@
if (fail_http_response_code >= 0) {
fetcher->FailTransfer(fail_http_response_code);
}
- FakeSystemState fake_system_state;
- if (prefs)
- fake_system_state.set_prefs(prefs);
- if (payload_state)
- fake_system_state.set_payload_state(payload_state);
- if (p2p_manager)
- fake_system_state.set_p2p_manager(p2p_manager);
- if (connection_manager)
- fake_system_state.set_connection_manager(connection_manager);
- fake_system_state.set_request_params(params);
- OmahaRequestAction action(&fake_system_state,
+ if (request_params)
+ fake_system_state_.set_request_params(request_params);
+ OmahaRequestAction action(&fake_system_state_,
nullptr,
fetcher,
ping_only);
@@ -284,19 +317,19 @@
BondActions(&action, &collector_action);
processor.EnqueueAction(&collector_action);
- EXPECT_CALL(*fake_system_state.mock_metrics_lib(), SendEnumToUMA(_, _, _))
+ EXPECT_CALL(*fake_system_state_.mock_metrics_lib(), SendEnumToUMA(_, _, _))
.Times(AnyNumber());
- EXPECT_CALL(*fake_system_state.mock_metrics_lib(),
+ EXPECT_CALL(*fake_system_state_.mock_metrics_lib(),
SendEnumToUMA(metrics::kMetricCheckResult,
static_cast<int>(expected_check_result),
static_cast<int>(metrics::CheckResult::kNumConstants) - 1))
.Times(expected_check_result == metrics::CheckResult::kUnset ? 0 : 1);
- EXPECT_CALL(*fake_system_state.mock_metrics_lib(),
+ EXPECT_CALL(*fake_system_state_.mock_metrics_lib(),
SendEnumToUMA(metrics::kMetricCheckReaction,
static_cast<int>(expected_check_reaction),
static_cast<int>(metrics::CheckReaction::kNumConstants) - 1))
.Times(expected_check_reaction == metrics::CheckReaction::kUnset ? 0 : 1);
- EXPECT_CALL(*fake_system_state.mock_metrics_lib(),
+ EXPECT_CALL(*fake_system_state_.mock_metrics_lib(),
SendSparseToUMA(metrics::kMetricCheckDownloadErrorCode,
static_cast<int>(expected_download_error_code)))
.Times(expected_download_error_code == metrics::DownloadErrorCode::kUnset
@@ -339,14 +372,10 @@
*out_post_data = fetcher->post_data();
}
-TEST(OmahaRequestActionTest, RejectEntities) {
+TEST_F(OmahaRequestActionTest, RejectEntities) {
OmahaResponse response;
ASSERT_FALSE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetNoUpdateResponseWithEntity(OmahaRequestParams::kAppId),
-1,
false, // ping_only
@@ -359,14 +388,10 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, NoUpdateTest) {
+TEST_F(OmahaRequestActionTest, NoUpdateTest) {
OmahaResponse response;
ASSERT_TRUE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
@@ -379,14 +404,10 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, ValidUpdateTest) {
+TEST_F(OmahaRequestActionTest, ValidUpdateTest) {
OmahaResponse response;
ASSERT_TRUE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetUpdateResponse(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -416,11 +437,13 @@
EXPECT_EQ("20101020", response.deadline);
}
-TEST(OmahaRequestActionTest, ValidUpdateBlockedByConnection) {
+TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByConnection) {
OmahaResponse response;
// Set up a connection manager that doesn't allow a valid update over
// the current ethernet connection.
MockConnectionManager mock_cm(nullptr);
+ fake_system_state_.set_connection_manager(&mock_cm);
+
EXPECT_CALL(mock_cm, GetConnectionProperties(_, _, _))
.WillRepeatedly(DoAll(SetArgumentPointee<1>(kNetEthernet),
SetArgumentPointee<2>(NetworkTethering::kUnknown),
@@ -431,11 +454,7 @@
.WillRepeatedly(Return(shill::kTypeEthernet));
ASSERT_FALSE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- &mock_cm, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetUpdateResponse(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -457,20 +476,18 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, ValidUpdateBlockedByRollback) {
+TEST_F(OmahaRequestActionTest, ValidUpdateBlockedByRollback) {
string rollback_version = "1234.0.0";
OmahaResponse response;
MockPayloadState mock_payload_state;
+ fake_system_state_.set_payload_state(&mock_payload_state);
+
EXPECT_CALL(mock_payload_state, GetRollbackVersion())
.WillRepeatedly(Return(rollback_version));
ASSERT_FALSE(
- TestUpdateCheck(nullptr, // prefs
- &mock_payload_state, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetUpdateResponse(OmahaRequestParams::kAppId,
rollback_version, // version
"http://more/info",
@@ -492,28 +509,15 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, WallClockBasedWaitAloneCausesScattering) {
+TEST_F(OmahaRequestActionTest, WallClockBasedWaitAloneCausesScattering) {
OmahaResponse response;
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_wall_clock_based_wait_enabled(true);
params.set_update_check_count_wait_enabled(false);
params.set_waiting_period(TimeDelta::FromDays(2));
- string prefs_dir;
- EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
- &prefs_dir));
- ScopedDirRemover temp_dir_remover(prefs_dir);
-
- Prefs prefs;
- LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
- << "Failed to initialize preferences.";
-
ASSERT_FALSE(
- TestUpdateCheck(&prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ TestUpdateCheck(¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -541,11 +545,7 @@
// Verify if we are interactive check we don't defer.
params.set_interactive(true);
ASSERT_TRUE(
- TestUpdateCheck(&prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ TestUpdateCheck(¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -571,9 +571,9 @@
EXPECT_TRUE(response.update_exists);
}
-TEST(OmahaRequestActionTest, NoWallClockBasedWaitCausesNoScattering) {
+TEST_F(OmahaRequestActionTest, NoWallClockBasedWaitCausesNoScattering) {
OmahaResponse response;
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_wall_clock_based_wait_enabled(false);
params.set_waiting_period(TimeDelta::FromDays(2));
@@ -581,21 +581,8 @@
params.set_min_update_checks_needed(1);
params.set_max_update_checks_allowed(8);
- string prefs_dir;
- EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
- &prefs_dir));
- ScopedDirRemover temp_dir_remover(prefs_dir);
-
- Prefs prefs;
- LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
- << "Failed to initialize preferences.";
-
ASSERT_TRUE(
- TestUpdateCheck(&prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ TestUpdateCheck(¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -621,9 +608,9 @@
EXPECT_TRUE(response.update_exists);
}
-TEST(OmahaRequestActionTest, ZeroMaxDaysToScatterCausesNoScattering) {
+TEST_F(OmahaRequestActionTest, ZeroMaxDaysToScatterCausesNoScattering) {
OmahaResponse response;
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_wall_clock_based_wait_enabled(true);
params.set_waiting_period(TimeDelta::FromDays(2));
@@ -631,21 +618,8 @@
params.set_min_update_checks_needed(1);
params.set_max_update_checks_allowed(8);
- string prefs_dir;
- EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
- &prefs_dir));
- ScopedDirRemover temp_dir_remover(prefs_dir);
-
- Prefs prefs;
- LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
- << "Failed to initialize preferences.";
-
ASSERT_TRUE(
- TestUpdateCheck(&prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ TestUpdateCheck(¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -672,9 +646,9 @@
}
-TEST(OmahaRequestActionTest, ZeroUpdateCheckCountCausesNoScattering) {
+TEST_F(OmahaRequestActionTest, ZeroUpdateCheckCountCausesNoScattering) {
OmahaResponse response;
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_wall_clock_based_wait_enabled(true);
params.set_waiting_period(TimeDelta());
@@ -682,20 +656,7 @@
params.set_min_update_checks_needed(0);
params.set_max_update_checks_allowed(0);
- string prefs_dir;
- EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
- &prefs_dir));
- ScopedDirRemover temp_dir_remover(prefs_dir);
-
- Prefs prefs;
- LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
- << "Failed to initialize preferences.";
-
ASSERT_TRUE(TestUpdateCheck(
- &prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
@@ -721,14 +682,14 @@
nullptr));
int64_t count;
- ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count));
+ ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
ASSERT_EQ(count, 0);
EXPECT_TRUE(response.update_exists);
}
-TEST(OmahaRequestActionTest, NonZeroUpdateCheckCountCausesScattering) {
+TEST_F(OmahaRequestActionTest, NonZeroUpdateCheckCountCausesScattering) {
OmahaResponse response;
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_wall_clock_based_wait_enabled(true);
params.set_waiting_period(TimeDelta());
@@ -736,20 +697,7 @@
params.set_min_update_checks_needed(1);
params.set_max_update_checks_allowed(8);
- string prefs_dir;
- EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
- &prefs_dir));
- ScopedDirRemover temp_dir_remover(prefs_dir);
-
- Prefs prefs;
- LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
- << "Failed to initialize preferences.";
-
ASSERT_FALSE(TestUpdateCheck(
- &prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
@@ -775,18 +723,14 @@
nullptr));
int64_t count;
- ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count));
+ ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
ASSERT_GT(count, 0);
EXPECT_FALSE(response.update_exists);
// Verify if we are interactive check we don't defer.
params.set_interactive(true);
ASSERT_TRUE(
- TestUpdateCheck(&prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ TestUpdateCheck(¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -812,9 +756,9 @@
EXPECT_TRUE(response.update_exists);
}
-TEST(OmahaRequestActionTest, ExistingUpdateCheckCountCausesScattering) {
+TEST_F(OmahaRequestActionTest, ExistingUpdateCheckCountCausesScattering) {
OmahaResponse response;
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_wall_clock_based_wait_enabled(true);
params.set_waiting_period(TimeDelta());
@@ -822,22 +766,9 @@
params.set_min_update_checks_needed(1);
params.set_max_update_checks_allowed(8);
- string prefs_dir;
- EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
- &prefs_dir));
- ScopedDirRemover temp_dir_remover(prefs_dir);
-
- Prefs prefs;
- LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
- << "Failed to initialize preferences.";
-
- ASSERT_TRUE(prefs.SetInt64(kPrefsUpdateCheckCount, 5));
+ ASSERT_TRUE(fake_prefs_.SetInt64(kPrefsUpdateCheckCount, 5));
ASSERT_FALSE(TestUpdateCheck(
- &prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
@@ -863,7 +794,7 @@
nullptr));
int64_t count;
- ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateCheckCount, &count));
+ ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateCheckCount, &count));
// count remains the same, as the decrementing happens in update_attempter
// which this test doesn't exercise.
ASSERT_EQ(count, 5);
@@ -872,11 +803,7 @@
// Verify if we are interactive check we don't defer.
params.set_interactive(true);
ASSERT_TRUE(
- TestUpdateCheck(&prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ TestUpdateCheck(¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -902,15 +829,14 @@
EXPECT_TRUE(response.update_exists);
}
-TEST(OmahaRequestActionTest, NoOutputPipeTest) {
+TEST_F(OmahaRequestActionTest, NoOutputPipeTest) {
const string http_response(GetNoUpdateResponse(OmahaRequestParams::kAppId));
GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
- FakeSystemState fake_system_state;
- OmahaRequestParams params = kDefaultTestParams;
- fake_system_state.set_request_params(¶ms);
- OmahaRequestAction action(&fake_system_state, nullptr,
+ OmahaRequestParams params = request_params_;
+ fake_system_state_.set_request_params(¶ms);
+ OmahaRequestAction action(&fake_system_state_, nullptr,
new MockHttpFetcher(http_response.data(),
http_response.size(),
nullptr),
@@ -927,14 +853,10 @@
EXPECT_FALSE(processor.IsRunning());
}
-TEST(OmahaRequestActionTest, InvalidXmlTest) {
+TEST_F(OmahaRequestActionTest, InvalidXmlTest) {
OmahaResponse response;
ASSERT_FALSE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
"invalid xml>",
-1,
false, // ping_only
@@ -947,14 +869,10 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, EmptyResponseTest) {
+TEST_F(OmahaRequestActionTest, EmptyResponseTest) {
OmahaResponse response;
ASSERT_FALSE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
"",
-1,
false, // ping_only
@@ -967,14 +885,10 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, MissingStatusTest) {
+TEST_F(OmahaRequestActionTest, MissingStatusTest) {
OmahaResponse response;
ASSERT_FALSE(TestUpdateCheck(
- nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ nullptr, // request_params
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
"<daystart elapsed_seconds=\"100\"/>"
"<app appid=\"foo\" status=\"ok\">"
@@ -991,14 +905,10 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, InvalidStatusTest) {
+TEST_F(OmahaRequestActionTest, InvalidStatusTest) {
OmahaResponse response;
ASSERT_FALSE(TestUpdateCheck(
- nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ nullptr, // request_params
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
"<daystart elapsed_seconds=\"100\"/>"
"<app appid=\"foo\" status=\"ok\">"
@@ -1015,14 +925,10 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, MissingNodesetTest) {
+TEST_F(OmahaRequestActionTest, MissingNodesetTest) {
OmahaResponse response;
ASSERT_FALSE(TestUpdateCheck(
- nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ nullptr, // request_params
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
"<daystart elapsed_seconds=\"100\"/>"
"<app appid=\"foo\" status=\"ok\">"
@@ -1039,7 +945,7 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, MissingFieldTest) {
+TEST_F(OmahaRequestActionTest, MissingFieldTest) {
string input_response =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response protocol=\"3.0\">"
"<daystart elapsed_seconds=\"100\"/>"
@@ -1060,11 +966,7 @@
LOG(INFO) << "Input Response = " << input_response;
OmahaResponse response;
- ASSERT_TRUE(TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ ASSERT_TRUE(TestUpdateCheck(nullptr, // request_params
input_response,
-1,
false, // ping_only
@@ -1103,14 +1005,11 @@
}
} // namespace
-TEST(OmahaRequestActionTest, TerminateTransferTest) {
+TEST_F(OmahaRequestActionTest, TerminateTransferTest) {
string http_response("doesn't matter");
GMainLoop *loop = g_main_loop_new(g_main_context_default(), FALSE);
- FakeSystemState fake_system_state;
- OmahaRequestParams params = kDefaultTestParams;
- fake_system_state.set_request_params(¶ms);
- OmahaRequestAction action(&fake_system_state, nullptr,
+ OmahaRequestAction action(&fake_system_state_, nullptr,
new MockHttpFetcher(http_response.data(),
http_response.size(),
nullptr),
@@ -1126,7 +1025,7 @@
g_main_loop_unref(loop);
}
-TEST(OmahaRequestActionTest, XmlEncodeTest) {
+TEST_F(OmahaRequestActionTest, XmlEncodeTest) {
EXPECT_EQ("ab", XmlEncode("ab"));
EXPECT_EQ("a<b", XmlEncode("a<b"));
EXPECT_EQ("<&>", XmlEncode("<&>"));
@@ -1135,8 +1034,7 @@
vector<char> post_data;
// Make sure XML Encode is being called on the params
- FakeSystemState fake_system_state;
- OmahaRequestParams params(&fake_system_state,
+ OmahaRequestParams params(&fake_system_state_,
OmahaRequestParams::kOsPlatform,
OmahaRequestParams::kOsVersion,
"testtheservice_pack>",
@@ -1156,11 +1054,7 @@
false); // use_p2p_for_sharing
OmahaResponse response;
ASSERT_FALSE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ TestUpdateCheck(¶ms,
"invalid xml>",
-1,
false, // ping_only
@@ -1182,14 +1076,10 @@
EXPECT_EQ(post_str.find("<OEM MODEL>"), string::npos);
}
-TEST(OmahaRequestActionTest, XmlDecodeTest) {
+TEST_F(OmahaRequestActionTest, XmlDecodeTest) {
OmahaResponse response;
ASSERT_TRUE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetUpdateResponse(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"testthe<url", // more info
@@ -1214,14 +1104,10 @@
EXPECT_EQ(response.deadline, "<20110101");
}
-TEST(OmahaRequestActionTest, ParseIntTest) {
+TEST_F(OmahaRequestActionTest, ParseIntTest) {
OmahaResponse response;
ASSERT_TRUE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetUpdateResponse(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"theurl", // more info
@@ -1245,17 +1131,15 @@
EXPECT_EQ(response.size, 123123123123123ll);
}
-TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) {
+TEST_F(OmahaRequestActionTest, FormatUpdateCheckOutputTest) {
vector<char> post_data;
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
+
EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _))
.WillOnce(DoAll(SetArgumentPointee<1>(string("")), Return(true)));
EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(1);
- ASSERT_FALSE(TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ ASSERT_FALSE(TestUpdateCheck(nullptr, // request_params
"invalid xml>",
-1,
false, // ping_only
@@ -1280,9 +1164,9 @@
}
-TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) {
+TEST_F(OmahaRequestActionTest, FormatSuccessEventOutputTest) {
vector<char> post_data;
- TestEvent(kDefaultTestParams,
+ TestEvent(request_params_,
new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted),
"invalid xml>",
&post_data);
@@ -1297,9 +1181,9 @@
EXPECT_EQ(post_str.find("updatecheck"), string::npos);
}
-TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) {
+TEST_F(OmahaRequestActionTest, FormatErrorEventOutputTest) {
vector<char> post_data;
- TestEvent(kDefaultTestParams,
+ TestEvent(request_params_,
new OmahaEvent(OmahaEvent::kTypeDownloadComplete,
OmahaEvent::kResultError,
ErrorCode::kError),
@@ -1317,13 +1201,13 @@
EXPECT_EQ(post_str.find("updatecheck"), string::npos);
}
-TEST(OmahaRequestActionTest, IsEventTest) {
+TEST_F(OmahaRequestActionTest, IsEventTest) {
string http_response("doesn't matter");
- FakeSystemState fake_system_state;
- OmahaRequestParams params = kDefaultTestParams;
- fake_system_state.set_request_params(¶ms);
+ // Create a copy of the OmahaRequestParams to reuse it later.
+ OmahaRequestParams params = request_params_;
+ fake_system_state_.set_request_params(¶ms);
OmahaRequestAction update_check_action(
- &fake_system_state,
+ &fake_system_state_,
nullptr,
new MockHttpFetcher(http_response.data(),
http_response.size(),
@@ -1331,10 +1215,10 @@
false);
EXPECT_FALSE(update_check_action.IsEvent());
- params = kDefaultTestParams;
- fake_system_state.set_request_params(¶ms);
+ params = request_params_;
+ fake_system_state_.set_request_params(¶ms);
OmahaRequestAction event_action(
- &fake_system_state,
+ &fake_system_state_,
new OmahaEvent(OmahaEvent::kTypeUpdateComplete),
new MockHttpFetcher(http_response.data(),
http_response.size(),
@@ -1343,13 +1227,12 @@
EXPECT_TRUE(event_action.IsEvent());
}
-TEST(OmahaRequestActionTest, FormatDeltaOkayOutputTest) {
+TEST_F(OmahaRequestActionTest, FormatDeltaOkayOutputTest) {
for (int i = 0; i < 2; i++) {
bool delta_okay = i == 1;
const char* delta_okay_str = delta_okay ? "true" : "false";
vector<char> post_data;
- FakeSystemState fake_system_state;
- OmahaRequestParams params(&fake_system_state,
+ OmahaRequestParams params(&fake_system_state_,
OmahaRequestParams::kOsPlatform,
OmahaRequestParams::kOsVersion,
"service_pack",
@@ -1367,11 +1250,7 @@
"", // target_version_prefix
false, // use_p2p_for_downloading
false); // use_p2p_for_sharing
- ASSERT_FALSE(TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ ASSERT_FALSE(TestUpdateCheck(¶ms,
"invalid xml>",
-1,
false, // ping_only
@@ -1390,13 +1269,13 @@
}
}
-TEST(OmahaRequestActionTest, FormatInteractiveOutputTest) {
+TEST_F(OmahaRequestActionTest, FormatInteractiveOutputTest) {
for (int i = 0; i < 2; i++) {
bool interactive = i == 1;
const char* interactive_str = interactive ? "ondemandupdate" : "scheduler";
vector<char> post_data;
FakeSystemState fake_system_state;
- OmahaRequestParams params(&fake_system_state,
+ OmahaRequestParams params(&fake_system_state_,
OmahaRequestParams::kOsPlatform,
OmahaRequestParams::kOsVersion,
"service_pack",
@@ -1414,11 +1293,7 @@
"", // target_version_prefix
false, // use_p2p_for_downloading
false); // use_p2p_for_sharing
- ASSERT_FALSE(TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ ASSERT_FALSE(TestUpdateCheck(¶ms,
"invalid xml>",
-1,
false, // ping_only
@@ -1437,7 +1312,7 @@
}
}
-TEST(OmahaRequestActionTest, OmahaEventTest) {
+TEST_F(OmahaRequestActionTest, OmahaEventTest) {
OmahaEvent default_event;
EXPECT_EQ(OmahaEvent::kTypeUnknown, default_event.type);
EXPECT_EQ(OmahaEvent::kResultError, default_event.result);
@@ -1456,54 +1331,58 @@
EXPECT_EQ(ErrorCode::kError, error_event.error_code);
}
-TEST(OmahaRequestActionTest, PingTest) {
- for (int ping_only = 0; ping_only < 2; ping_only++) {
- NiceMock<PrefsMock> prefs;
- EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
- .Times(AnyNumber());
- EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
- // Add a few hours to the day difference to test no rounding, etc.
- int64_t five_days_ago =
- (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue();
- int64_t six_days_ago =
- (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue();
- EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
- .WillOnce(DoAll(SetArgumentPointee<1>(0), Return(true)));
- EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
- .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true)));
- EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
- .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true)));
- vector<char> post_data;
- ASSERT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
- GetNoUpdateResponse(OmahaRequestParams::kAppId),
- -1,
- ping_only,
- ErrorCode::kSuccess,
- metrics::CheckResult::kUnset,
- metrics::CheckReaction::kUnset,
- metrics::DownloadErrorCode::kUnset,
- nullptr,
- &post_data));
- string post_str(&post_data[0], post_data.size());
- EXPECT_NE(post_str.find("<ping active=\"1\" a=\"6\" r=\"5\"></ping>"),
- string::npos);
- if (ping_only) {
- EXPECT_EQ(post_str.find("updatecheck"), string::npos);
- EXPECT_EQ(post_str.find("previousversion"), string::npos);
- } else {
- EXPECT_NE(post_str.find("updatecheck"), string::npos);
- EXPECT_NE(post_str.find("previousversion"), string::npos);
- }
+void OmahaRequestActionTest::PingTest(bool ping_only) {
+ NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
+ EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
+ .Times(AnyNumber());
+ EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
+ // Add a few hours to the day difference to test no rounding, etc.
+ int64_t five_days_ago =
+ (Time::Now() - TimeDelta::FromHours(5 * 24 + 13)).ToInternalValue();
+ int64_t six_days_ago =
+ (Time::Now() - TimeDelta::FromHours(6 * 24 + 11)).ToInternalValue();
+ EXPECT_CALL(prefs, GetInt64(kPrefsInstallDateDays, _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(0), Return(true)));
+ EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(six_days_ago), Return(true)));
+ EXPECT_CALL(prefs, GetInt64(kPrefsLastRollCallPingDay, _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(five_days_ago), Return(true)));
+ vector<char> post_data;
+ ASSERT_TRUE(
+ TestUpdateCheck(nullptr, // request_params
+ GetNoUpdateResponse(OmahaRequestParams::kAppId),
+ -1,
+ ping_only,
+ ErrorCode::kSuccess,
+ metrics::CheckResult::kUnset,
+ metrics::CheckReaction::kUnset,
+ metrics::DownloadErrorCode::kUnset,
+ nullptr,
+ &post_data));
+ string post_str(&post_data[0], post_data.size());
+ EXPECT_NE(post_str.find("<ping active=\"1\" a=\"6\" r=\"5\"></ping>"),
+ string::npos);
+ if (ping_only) {
+ EXPECT_EQ(post_str.find("updatecheck"), string::npos);
+ EXPECT_EQ(post_str.find("previousversion"), string::npos);
+ } else {
+ EXPECT_NE(post_str.find("updatecheck"), string::npos);
+ EXPECT_NE(post_str.find("previousversion"), string::npos);
}
}
-TEST(OmahaRequestActionTest, ActivePingTest) {
+TEST_F(OmahaRequestActionTest, PingTestSendOnlyAPing) {
+ PingTest(true /* ping_only */);
+}
+
+TEST_F(OmahaRequestActionTest, PingTestSendAlsoAnUpdateCheck) {
+ PingTest(false /* ping_only */);
+}
+
+TEST_F(OmahaRequestActionTest, ActivePingTest) {
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
.Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
@@ -1518,11 +1397,7 @@
.WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
vector<char> post_data;
ASSERT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
@@ -1537,8 +1412,9 @@
string::npos);
}
-TEST(OmahaRequestActionTest, RollCallPingTest) {
+TEST_F(OmahaRequestActionTest, RollCallPingTest) {
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
.Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
@@ -1553,11 +1429,7 @@
.WillOnce(DoAll(SetArgumentPointee<1>(four_days_ago), Return(true)));
vector<char> post_data;
ASSERT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
@@ -1572,8 +1444,9 @@
string::npos);
}
-TEST(OmahaRequestActionTest, NoPingTest) {
+TEST_F(OmahaRequestActionTest, NoPingTest) {
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
.Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
@@ -1589,11 +1462,7 @@
EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
vector<char> post_data;
ASSERT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
false, // ping_only
@@ -1607,9 +1476,10 @@
EXPECT_EQ(post_str.find("ping"), string::npos);
}
-TEST(OmahaRequestActionTest, IgnoreEmptyPingTest) {
+TEST_F(OmahaRequestActionTest, IgnoreEmptyPingTest) {
// This test ensures that we ignore empty ping only requests.
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
int64_t now = Time::Now().ToInternalValue();
EXPECT_CALL(prefs, GetInt64(kPrefsLastActivePingDay, _))
.WillOnce(DoAll(SetArgumentPointee<1>(now), Return(true)));
@@ -1619,11 +1489,7 @@
EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
vector<char> post_data;
EXPECT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetNoUpdateResponse(OmahaRequestParams::kAppId),
-1,
true, // ping_only
@@ -1636,8 +1502,9 @@
EXPECT_EQ(post_data.size(), 0);
}
-TEST(OmahaRequestActionTest, BackInTimePingTest) {
+TEST_F(OmahaRequestActionTest, BackInTimePingTest) {
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
EXPECT_CALL(prefs, GetInt64(kPrefsMetricsCheckLastReportingTime, _))
.Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
@@ -1655,11 +1522,7 @@
.WillOnce(Return(true));
vector<char> post_data;
ASSERT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
"protocol=\"3.0\"><daystart elapsed_seconds=\"100\"/>"
"<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
@@ -1676,7 +1539,7 @@
EXPECT_EQ(post_str.find("ping"), string::npos);
}
-TEST(OmahaRequestActionTest, LastPingDayUpdateTest) {
+TEST_F(OmahaRequestActionTest, LastPingDayUpdateTest) {
// This test checks that the action updates the last ping day to now
// minus 200 seconds with a slack of 5 seconds. Therefore, the test
// may fail if it runs for longer than 5 seconds. It shouldn't run
@@ -1686,6 +1549,7 @@
int64_t midnight_slack =
(Time::Now() - TimeDelta::FromSeconds(195)).ToInternalValue();
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay,
@@ -1695,11 +1559,7 @@
AllOf(Ge(midnight), Le(midnight_slack))))
.WillOnce(Return(true));
ASSERT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
"protocol=\"3.0\"><daystart elapsed_seconds=\"200\"/>"
"<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
@@ -1714,18 +1574,15 @@
nullptr));
}
-TEST(OmahaRequestActionTest, NoElapsedSecondsTest) {
+TEST_F(OmahaRequestActionTest, NoElapsedSecondsTest) {
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
ASSERT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
"protocol=\"3.0\"><daystart blah=\"200\"/>"
"<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
@@ -1740,18 +1597,15 @@
nullptr));
}
-TEST(OmahaRequestActionTest, BadElapsedSecondsTest) {
+TEST_F(OmahaRequestActionTest, BadElapsedSecondsTest) {
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
EXPECT_CALL(prefs, GetInt64(_, _)).Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(_, _)).Times(AnyNumber());
EXPECT_CALL(prefs, SetInt64(kPrefsLastActivePingDay, _)).Times(0);
EXPECT_CALL(prefs, SetInt64(kPrefsLastRollCallPingDay, _)).Times(0);
ASSERT_TRUE(
- TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><response "
"protocol=\"3.0\"><daystart elapsed_seconds=\"x\"/>"
"<app appid=\"foo\" status=\"ok\"><ping status=\"ok\"/>"
@@ -1766,13 +1620,9 @@
nullptr));
}
-TEST(OmahaRequestActionTest, NoUniqueIDTest) {
+TEST_F(OmahaRequestActionTest, NoUniqueIDTest) {
vector<char> post_data;
- ASSERT_FALSE(TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ ASSERT_FALSE(TestUpdateCheck(nullptr, // request_params
"invalid xml>",
-1,
false, // ping_only
@@ -1788,16 +1638,12 @@
EXPECT_EQ(post_str.find("userid="), string::npos);
}
-TEST(OmahaRequestActionTest, NetworkFailureTest) {
+TEST_F(OmahaRequestActionTest, NetworkFailureTest) {
OmahaResponse response;
const int http_error_code =
static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 501;
ASSERT_FALSE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
"",
501,
false, // ping_only
@@ -1810,16 +1656,12 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) {
+TEST_F(OmahaRequestActionTest, NetworkFailureBadHTTPCodeTest) {
OmahaResponse response;
const int http_error_code =
static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 999;
ASSERT_FALSE(
- TestUpdateCheck(nullptr, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
"",
1500,
false, // ping_only
@@ -1832,27 +1674,14 @@
EXPECT_FALSE(response.update_exists);
}
-TEST(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsPersistedFirstTime) {
+TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsPersistedFirstTime) {
OmahaResponse response;
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_wall_clock_based_wait_enabled(true);
params.set_waiting_period(TimeDelta().FromDays(1));
params.set_update_check_count_wait_enabled(false);
- string prefs_dir;
- EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
- &prefs_dir));
- ScopedDirRemover temp_dir_remover(prefs_dir);
-
- Prefs prefs;
- LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
- << "Failed to initialize preferences.";
-
ASSERT_FALSE(TestUpdateCheck(
- &prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
@@ -1878,18 +1707,14 @@
nullptr));
int64_t timestamp = 0;
- ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp));
+ ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp));
ASSERT_GT(timestamp, 0);
EXPECT_FALSE(response.update_exists);
// Verify if we are interactive check we don't defer.
params.set_interactive(true);
ASSERT_TRUE(
- TestUpdateCheck(&prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ TestUpdateCheck(¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -1915,32 +1740,20 @@
EXPECT_TRUE(response.update_exists);
}
-TEST(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsUsedIfAlreadyPresent) {
+TEST_F(OmahaRequestActionTest, TestUpdateFirstSeenAtGetsUsedIfAlreadyPresent) {
OmahaResponse response;
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_wall_clock_based_wait_enabled(true);
params.set_waiting_period(TimeDelta().FromDays(1));
params.set_update_check_count_wait_enabled(false);
- string prefs_dir;
- EXPECT_TRUE(utils::MakeTempDirectory("ue_ut_prefs.XXXXXX",
- &prefs_dir));
- ScopedDirRemover temp_dir_remover(prefs_dir);
-
- Prefs prefs;
- LOG_IF(ERROR, !prefs.Init(base::FilePath(prefs_dir)))
- << "Failed to initialize preferences.";
-
// Set the timestamp to a very old value such that it exceeds the
// waiting period set above.
Time t1;
Time::FromString("1/1/2012", &t1);
- ASSERT_TRUE(prefs.SetInt64(kPrefsUpdateFirstSeenAt, t1.ToInternalValue()));
+ ASSERT_TRUE(fake_prefs_.SetInt64(
+ kPrefsUpdateFirstSeenAt, t1.ToInternalValue()));
ASSERT_TRUE(TestUpdateCheck(
- &prefs, // prefs
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
¶ms,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
@@ -1969,11 +1782,11 @@
// Make sure the timestamp t1 is unchanged showing that it was reused.
int64_t timestamp = 0;
- ASSERT_TRUE(prefs.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp));
+ ASSERT_TRUE(fake_prefs_.GetInt64(kPrefsUpdateFirstSeenAt, ×tamp));
ASSERT_TRUE(timestamp == t1.ToInternalValue());
}
-TEST(OmahaRequestActionTest, TestChangingToMoreStableChannel) {
+TEST_F(OmahaRequestActionTest, TestChangingToMoreStableChannel) {
// Create a uniquely named test directory.
string test_dir;
ASSERT_TRUE(utils::MakeTempDirectory(
@@ -1984,6 +1797,7 @@
kStatefulPartition + "/etc"));
vector<char> post_data;
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
ASSERT_TRUE(WriteFileString(
test_dir + "/etc/lsb-release",
"CHROMEOS_RELEASE_APPID={11111111-1111-1111-1111-111111111111}\n"
@@ -1993,7 +1807,7 @@
test_dir + kStatefulPartition + "/etc/lsb-release",
"CHROMEOS_IS_POWERWASH_ALLOWED=true\n"
"CHROMEOS_RELEASE_TRACK=stable-channel\n"));
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_root(test_dir);
params.SetLockDown(false);
params.Init("1.2.3.4", "", 0);
@@ -2001,11 +1815,7 @@
EXPECT_EQ("stable-channel", params.target_channel());
EXPECT_TRUE(params.to_more_stable_channel());
EXPECT_TRUE(params.is_powerwash_allowed());
- ASSERT_FALSE(TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ ASSERT_FALSE(TestUpdateCheck(¶ms,
"invalid xml>",
-1,
false, // ping_only
@@ -2025,7 +1835,7 @@
ASSERT_TRUE(utils::RecursiveUnlinkDir(test_dir));
}
-TEST(OmahaRequestActionTest, TestChangingToLessStableChannel) {
+TEST_F(OmahaRequestActionTest, TestChangingToLessStableChannel) {
// Create a uniquely named test directory.
string test_dir;
ASSERT_TRUE(utils::MakeTempDirectory(
@@ -2036,6 +1846,7 @@
kStatefulPartition + "/etc"));
vector<char> post_data;
NiceMock<PrefsMock> prefs;
+ fake_system_state_.set_prefs(&prefs);
ASSERT_TRUE(WriteFileString(
test_dir + "/etc/lsb-release",
"CHROMEOS_RELEASE_APPID={11111111-1111-1111-1111-111111111111}\n"
@@ -2044,7 +1855,7 @@
ASSERT_TRUE(WriteFileString(
test_dir + kStatefulPartition + "/etc/lsb-release",
"CHROMEOS_RELEASE_TRACK=canary-channel\n"));
- OmahaRequestParams params = kDefaultTestParams;
+ OmahaRequestParams params = request_params_;
params.set_root(test_dir);
params.SetLockDown(false);
params.Init("5.6.7.8", "", 0);
@@ -2052,11 +1863,7 @@
EXPECT_EQ("canary-channel", params.target_channel());
EXPECT_FALSE(params.to_more_stable_channel());
EXPECT_FALSE(params.is_powerwash_allowed());
- ASSERT_FALSE(TestUpdateCheck(&prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- ¶ms,
+ ASSERT_FALSE(TestUpdateCheck(¶ms,
"invalid xml>",
-1,
false, // ping_only
@@ -2073,29 +1880,30 @@
"version=\"5.6.7.8\" "
"track=\"canary-channel\" from_track=\"stable-channel\""));
EXPECT_EQ(string::npos, post_str.find("from_version"));
-
- ASSERT_TRUE(utils::RecursiveUnlinkDir(test_dir));
}
-void P2PTest(bool initial_allow_p2p_for_downloading,
- bool initial_allow_p2p_for_sharing,
- bool omaha_disable_p2p_for_downloading,
- bool omaha_disable_p2p_for_sharing,
- bool payload_state_allow_p2p_attempt,
- bool expect_p2p_client_lookup,
- const string& p2p_client_result_url,
- bool expected_allow_p2p_for_downloading,
- bool expected_allow_p2p_for_sharing,
- const string& expected_p2p_url) {
+void OmahaRequestActionTest::P2PTest(
+ bool initial_allow_p2p_for_downloading,
+ bool initial_allow_p2p_for_sharing,
+ bool omaha_disable_p2p_for_downloading,
+ bool omaha_disable_p2p_for_sharing,
+ bool payload_state_allow_p2p_attempt,
+ bool expect_p2p_client_lookup,
+ const string& p2p_client_result_url,
+ bool expected_allow_p2p_for_downloading,
+ bool expected_allow_p2p_for_sharing,
+ const string& expected_p2p_url) {
OmahaResponse response;
- OmahaRequestParams request_params = kDefaultTestParams;
+ OmahaRequestParams request_params = request_params_;
request_params.set_use_p2p_for_downloading(initial_allow_p2p_for_downloading);
request_params.set_use_p2p_for_sharing(initial_allow_p2p_for_sharing);
MockPayloadState mock_payload_state;
+ fake_system_state_.set_payload_state(&mock_payload_state);
EXPECT_CALL(mock_payload_state, P2PAttemptAllowed())
.WillRepeatedly(Return(payload_state_allow_p2p_attempt));
MockP2PManager mock_p2p_manager;
+ fake_system_state_.set_p2p_manager(&mock_p2p_manager);
mock_p2p_manager.fake().SetLookupUrlForFileResult(p2p_client_result_url);
TimeDelta timeout = TimeDelta::FromSeconds(kMaxP2PNetworkWaitTimeSeconds);
@@ -2103,11 +1911,7 @@
.Times(expect_p2p_client_lookup ? 1 : 0);
ASSERT_TRUE(
- TestUpdateCheck(nullptr, // prefs
- &mock_payload_state,
- &mock_p2p_manager,
- nullptr, // connection_manager
- &request_params,
+ TestUpdateCheck(&request_params,
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -2146,7 +1950,7 @@
EXPECT_EQ(request_params.p2p_url(), expected_p2p_url);
}
-TEST(OmahaRequestActionTest, P2PWithPeer) {
+TEST_F(OmahaRequestActionTest, P2PWithPeer) {
P2PTest(true, // initial_allow_p2p_for_downloading
true, // initial_allow_p2p_for_sharing
false, // omaha_disable_p2p_for_downloading
@@ -2159,7 +1963,7 @@
"http://1.3.5.7/p2p"); // expected_p2p_url
}
-TEST(OmahaRequestActionTest, P2PWithoutPeer) {
+TEST_F(OmahaRequestActionTest, P2PWithoutPeer) {
P2PTest(true, // initial_allow_p2p_for_downloading
true, // initial_allow_p2p_for_sharing
false, // omaha_disable_p2p_for_downloading
@@ -2172,7 +1976,7 @@
""); // expected_p2p_url
}
-TEST(OmahaRequestActionTest, P2PDownloadNotAllowed) {
+TEST_F(OmahaRequestActionTest, P2PDownloadNotAllowed) {
P2PTest(false, // initial_allow_p2p_for_downloading
true, // initial_allow_p2p_for_sharing
false, // omaha_disable_p2p_for_downloading
@@ -2185,7 +1989,7 @@
""); // expected_p2p_url
}
-TEST(OmahaRequestActionTest, P2PWithPeerDownloadDisabledByOmaha) {
+TEST_F(OmahaRequestActionTest, P2PWithPeerDownloadDisabledByOmaha) {
P2PTest(true, // initial_allow_p2p_for_downloading
true, // initial_allow_p2p_for_sharing
true, // omaha_disable_p2p_for_downloading
@@ -2198,7 +2002,7 @@
""); // expected_p2p_url
}
-TEST(OmahaRequestActionTest, P2PWithPeerSharingDisabledByOmaha) {
+TEST_F(OmahaRequestActionTest, P2PWithPeerSharingDisabledByOmaha) {
P2PTest(true, // initial_allow_p2p_for_downloading
true, // initial_allow_p2p_for_sharing
false, // omaha_disable_p2p_for_downloading
@@ -2211,7 +2015,7 @@
"http://1.3.5.7/p2p"); // expected_p2p_url
}
-TEST(OmahaRequestActionTest, P2PWithPeerBothDisabledByOmaha) {
+TEST_F(OmahaRequestActionTest, P2PWithPeerBothDisabledByOmaha) {
P2PTest(true, // initial_allow_p2p_for_downloading
true, // initial_allow_p2p_for_sharing
true, // omaha_disable_p2p_for_downloading
@@ -2224,15 +2028,11 @@
""); // expected_p2p_url
}
-bool InstallDateParseHelper(const std::string &elapsed_days,
- PrefsInterface* prefs,
- OmahaResponse *response) {
+bool OmahaRequestActionTest::InstallDateParseHelper(
+ const std::string &elapsed_days,
+ OmahaResponse *response) {
return
- TestUpdateCheck(prefs,
- nullptr, // payload_state
- nullptr, // p2p_manager
- nullptr, // connection_manager
- &kDefaultTestParams,
+ TestUpdateCheck(nullptr, // request_params
GetUpdateResponse2(OmahaRequestParams::kAppId,
"1.2.3.4", // version
"http://more/info",
@@ -2257,120 +2057,95 @@
nullptr);
}
-TEST(OmahaRequestActionTest, ParseInstallDateFromResponse) {
+TEST_F(OmahaRequestActionTest, ParseInstallDateFromResponse) {
OmahaResponse response;
- string temp_dir;
- Prefs prefs;
- EXPECT_TRUE(utils::MakeTempDirectory("ParseInstallDateFromResponse.XXXXXX",
- &temp_dir));
- prefs.Init(base::FilePath(temp_dir));
// Check that we parse elapsed_days in the Omaha Response correctly.
// and that the kPrefsInstallDateDays value is written to.
- EXPECT_FALSE(prefs.Exists(kPrefsInstallDateDays));
- EXPECT_TRUE(InstallDateParseHelper("42", &prefs, &response));
+ EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
+ EXPECT_TRUE(InstallDateParseHelper("42", &response));
EXPECT_TRUE(response.update_exists);
EXPECT_EQ(42, response.install_date_days);
- EXPECT_TRUE(prefs.Exists(kPrefsInstallDateDays));
+ EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays));
int64_t prefs_days;
- EXPECT_TRUE(prefs.GetInt64(kPrefsInstallDateDays, &prefs_days));
+ EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
EXPECT_EQ(prefs_days, 42);
// If there already is a value set, we shouldn't do anything.
- EXPECT_TRUE(InstallDateParseHelper("7", &prefs, &response));
+ EXPECT_TRUE(InstallDateParseHelper("7", &response));
EXPECT_TRUE(response.update_exists);
EXPECT_EQ(7, response.install_date_days);
- EXPECT_TRUE(prefs.GetInt64(kPrefsInstallDateDays, &prefs_days));
+ EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
EXPECT_EQ(prefs_days, 42);
// Note that elapsed_days is not necessarily divisible by 7 so check
// that we round down correctly when populating kPrefsInstallDateDays.
- EXPECT_TRUE(prefs.Delete(kPrefsInstallDateDays));
- EXPECT_TRUE(InstallDateParseHelper("23", &prefs, &response));
+ EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays));
+ EXPECT_TRUE(InstallDateParseHelper("23", &response));
EXPECT_TRUE(response.update_exists);
EXPECT_EQ(23, response.install_date_days);
- EXPECT_TRUE(prefs.GetInt64(kPrefsInstallDateDays, &prefs_days));
+ EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
EXPECT_EQ(prefs_days, 21);
// Check that we correctly handle elapsed_days not being included in
// the Omaha Response.
- EXPECT_TRUE(InstallDateParseHelper("", &prefs, &response));
+ EXPECT_TRUE(InstallDateParseHelper("", &response));
EXPECT_TRUE(response.update_exists);
EXPECT_EQ(-1, response.install_date_days);
-
- EXPECT_TRUE(utils::RecursiveUnlinkDir(temp_dir));
}
-TEST(OmahaRequestActionTest, GetInstallDate) {
- string temp_dir;
- Prefs prefs;
- EXPECT_TRUE(utils::MakeTempDirectory("GetInstallDate.XXXXXX",
- &temp_dir));
- prefs.Init(base::FilePath(temp_dir));
+// If there is no prefs and OOBE is not complete, we should not
+// report anything to Omaha.
+TEST_F(OmahaRequestActionTest, GetInstallDateWhenNoPrefsNorOOBE) {
+ EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), -1);
+ EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
+}
- // If there is no prefs and OOBE is not complete, we should not
- // report anything to Omaha.
- {
- FakeSystemState system_state;
- system_state.set_prefs(&prefs);
- EXPECT_EQ(OmahaRequestAction::GetInstallDate(&system_state), -1);
- EXPECT_FALSE(prefs.Exists(kPrefsInstallDateDays));
- }
+// If OOBE is complete and happened on a valid date (e.g. after Jan
+// 1 2007 0:00 PST), that date should be used and written to
+// prefs. However, first try with an invalid date and check we do
+// nothing.
+TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithInvalidDate) {
+ Time oobe_date = Time::FromTimeT(42); // Dec 31, 1969 16:00:42 PST.
+ fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date);
+ EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), -1);
+ EXPECT_FALSE(fake_prefs_.Exists(kPrefsInstallDateDays));
+}
- // If OOBE is complete and happened on a valid date (e.g. after Jan
- // 1 2007 0:00 PST), that date should be used and written to
- // prefs. However, first try with an invalid date and check we do
- // nothing.
- {
- FakeSystemState fake_system_state;
- fake_system_state.set_prefs(&prefs);
+// Then check with a valid date. The date Jan 20, 2007 0:00 PST
+// should yield an InstallDate of 14.
+TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedWithValidDate) {
+ Time oobe_date = Time::FromTimeT(1169280000); // Jan 20, 2007 0:00 PST.
+ fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date);
+ EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 14);
+ EXPECT_TRUE(fake_prefs_.Exists(kPrefsInstallDateDays));
- Time oobe_date = Time::FromTimeT(42); // Dec 31, 1969 16:00:42 PST.
- fake_system_state.fake_hardware()->SetIsOOBEComplete(oobe_date);
- EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state), -1);
- EXPECT_FALSE(prefs.Exists(kPrefsInstallDateDays));
- }
+ int64_t prefs_days;
+ EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+ EXPECT_EQ(prefs_days, 14);
+}
- // Then check with a valid date. The date Jan 20, 2007 0:00 PST
- // should yield an InstallDate of 14.
- {
- FakeSystemState fake_system_state;
- fake_system_state.set_prefs(&prefs);
+// Now that we have a valid date in prefs, check that we keep using
+// that even if OOBE date reports something else. The date Jan 30,
+// 2007 0:00 PST should yield an InstallDate of 28... but since
+// there's a prefs file, we should still get 14.
+TEST_F(OmahaRequestActionTest, GetInstallDateWhenOOBECompletedDateChanges) {
+ // Set a valid date in the prefs first.
+ EXPECT_TRUE(fake_prefs_.SetInt64(kPrefsInstallDateDays, 14));
- Time oobe_date = Time::FromTimeT(1169280000); // Jan 20, 2007 0:00 PST.
- fake_system_state.fake_hardware()->SetIsOOBEComplete(oobe_date);
- EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state), 14);
- EXPECT_TRUE(prefs.Exists(kPrefsInstallDateDays));
+ Time oobe_date = Time::FromTimeT(1170144000); // Jan 30, 2007 0:00 PST.
+ fake_system_state_.fake_hardware()->SetIsOOBEComplete(oobe_date);
+ EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 14);
- int64_t prefs_days;
- EXPECT_TRUE(prefs.GetInt64(kPrefsInstallDateDays, &prefs_days));
- EXPECT_EQ(prefs_days, 14);
- }
+ int64_t prefs_days;
+ EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+ EXPECT_EQ(prefs_days, 14);
- // Now that we have a valid date in prefs, check that we keep using
- // that even if OOBE date reports something else. The date Jan 30,
- // 2007 0:00 PST should yield an InstallDate of 28... but since
- // there's a prefs file, we should still get 14.
- {
- FakeSystemState fake_system_state;
- fake_system_state.set_prefs(&prefs);
-
- Time oobe_date = Time::FromTimeT(1170144000); // Jan 30, 2007 0:00 PST.
- fake_system_state.fake_hardware()->SetIsOOBEComplete(oobe_date);
- EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state), 14);
-
- int64_t prefs_days;
- EXPECT_TRUE(prefs.GetInt64(kPrefsInstallDateDays, &prefs_days));
- EXPECT_EQ(prefs_days, 14);
-
- // If we delete the prefs file, we should get 28 days.
- EXPECT_TRUE(prefs.Delete(kPrefsInstallDateDays));
- EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state), 28);
- EXPECT_TRUE(prefs.GetInt64(kPrefsInstallDateDays, &prefs_days));
- EXPECT_EQ(prefs_days, 28);
- }
-
- EXPECT_TRUE(utils::RecursiveUnlinkDir(temp_dir));
+ // If we delete the prefs file, we should get 28 days.
+ EXPECT_TRUE(fake_prefs_.Delete(kPrefsInstallDateDays));
+ EXPECT_EQ(OmahaRequestAction::GetInstallDate(&fake_system_state_), 28);
+ EXPECT_TRUE(fake_prefs_.GetInt64(kPrefsInstallDateDays, &prefs_days));
+ EXPECT_EQ(prefs_days, 28);
}
} // namespace chromeos_update_engine