12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658 |
- #include "update_engine/payload_state.h"
- #include <base/files/file_path.h>
- #include <base/files/file_util.h>
- #include <base/strings/stringprintf.h>
- #include <gmock/gmock.h>
- #include <gtest/gtest.h>
- #include "update_engine/common/constants.h"
- #include "update_engine/common/fake_clock.h"
- #include "update_engine/common/fake_hardware.h"
- #include "update_engine/common/fake_prefs.h"
- #include "update_engine/common/mock_prefs.h"
- #include "update_engine/common/prefs.h"
- #include "update_engine/common/test_utils.h"
- #include "update_engine/common/utils.h"
- #include "update_engine/fake_system_state.h"
- #include "update_engine/metrics_reporter_interface.h"
- #include "update_engine/omaha_request_action.h"
- using base::Time;
- using base::TimeDelta;
- using std::string;
- using testing::_;
- using testing::AnyNumber;
- using testing::AtLeast;
- using testing::Mock;
- using testing::NiceMock;
- using testing::Return;
- using testing::SetArgPointee;
- namespace chromeos_update_engine {
- const char* kCurrentBytesDownloadedFromHttps =
- "current-bytes-downloaded-from-HttpsServer";
- const char* kTotalBytesDownloadedFromHttps =
- "total-bytes-downloaded-from-HttpsServer";
- const char* kCurrentBytesDownloadedFromHttp =
- "current-bytes-downloaded-from-HttpServer";
- const char* kTotalBytesDownloadedFromHttp =
- "total-bytes-downloaded-from-HttpServer";
- const char* kCurrentBytesDownloadedFromHttpPeer =
- "current-bytes-downloaded-from-HttpPeer";
- const char* kTotalBytesDownloadedFromHttpPeer =
- "total-bytes-downloaded-from-HttpPeer";
- static void SetupPayloadStateWith2Urls(string hash,
- bool http_enabled,
- bool is_delta_payload,
- PayloadState* payload_state,
- OmahaResponse* response) {
- response->packages.clear();
- response->packages.push_back({.payload_urls = {"http://test", "https://test"},
- .size = 523456789,
- .metadata_size = 558123,
- .metadata_signature = "metasign",
- .hash = hash,
- .is_delta = is_delta_payload});
- response->max_failure_count_per_url = 3;
- payload_state->SetResponse(*response);
- string stored_response_sign = payload_state->GetResponseSignature();
- string expected_url_https_only =
- " NumURLs = 1\n"
- " Candidate Url0 = https://test\n";
- string expected_urls_both =
- " NumURLs = 2\n"
- " Candidate Url0 = http://test\n"
- " Candidate Url1 = https://test\n";
- string expected_response_sign = base::StringPrintf(
- "Payload 0:\n"
- " Size = 523456789\n"
- " Sha256 Hash = %s\n"
- " Metadata Size = 558123\n"
- " Metadata Signature = metasign\n"
- " Is Delta = %d\n"
- "%s"
- "Max Failure Count Per Url = %d\n"
- "Disable Payload Backoff = %d\n",
- hash.c_str(),
- response->packages[0].is_delta,
- (http_enabled ? expected_urls_both : expected_url_https_only).c_str(),
- response->max_failure_count_per_url,
- response->disable_payload_backoff);
- EXPECT_EQ(expected_response_sign, stored_response_sign);
- }
- class PayloadStateTest : public ::testing::Test {};
- TEST(PayloadStateTest, SetResponseWorksWithEmptyResponse) {
- OmahaResponse response;
- FakeSystemState fake_system_state;
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsBackoffExpiryTime, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsUpdateTimestampStart, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsUpdateDurationUptime, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttps, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttp, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttpPeer, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsNumReboots, 0)).Times(AtLeast(1));
- PayloadState payload_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- payload_state.SetResponse(response);
- string stored_response_sign = payload_state.GetResponseSignature();
- string expected_response_sign =
- "Max Failure Count Per Url = 0\n"
- "Disable Payload Backoff = 0\n";
- EXPECT_EQ(expected_response_sign, stored_response_sign);
- EXPECT_EQ("", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
- EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
- }
- TEST(PayloadStateTest, SetResponseWorksWithSingleUrl) {
- OmahaResponse response;
- response.packages.push_back({.payload_urls = {"https://single.url.test"},
- .size = 123456789,
- .metadata_size = 58123,
- .metadata_signature = "msign",
- .hash = "hash"});
- FakeSystemState fake_system_state;
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsBackoffExpiryTime, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsUpdateTimestampStart, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsUpdateDurationUptime, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttps, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttp, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttpPeer, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsNumReboots, 0)).Times(AtLeast(1));
- PayloadState payload_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- payload_state.SetResponse(response);
- string stored_response_sign = payload_state.GetResponseSignature();
- string expected_response_sign =
- "Payload 0:\n"
- " Size = 123456789\n"
- " Sha256 Hash = hash\n"
- " Metadata Size = 58123\n"
- " Metadata Signature = msign\n"
- " Is Delta = 0\n"
- " NumURLs = 1\n"
- " Candidate Url0 = https://single.url.test\n"
- "Max Failure Count Per Url = 0\n"
- "Disable Payload Backoff = 0\n";
- EXPECT_EQ(expected_response_sign, stored_response_sign);
- EXPECT_EQ("https://single.url.test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
- EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
- }
- TEST(PayloadStateTest, SetResponseWorksWithMultipleUrls) {
- OmahaResponse response;
- response.packages.push_back({.payload_urls = {"http://multiple.url.test",
- "https://multiple.url.test"},
- .size = 523456789,
- .metadata_size = 558123,
- .metadata_signature = "metasign",
- .hash = "rhash"});
- FakeSystemState fake_system_state;
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsBackoffExpiryTime, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttps, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttp, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttpPeer, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsNumReboots, 0)).Times(AtLeast(1));
- PayloadState payload_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- payload_state.SetResponse(response);
- string stored_response_sign = payload_state.GetResponseSignature();
- string expected_response_sign =
- "Payload 0:\n"
- " Size = 523456789\n"
- " Sha256 Hash = rhash\n"
- " Metadata Size = 558123\n"
- " Metadata Signature = metasign\n"
- " Is Delta = 0\n"
- " NumURLs = 2\n"
- " Candidate Url0 = http://multiple.url.test\n"
- " Candidate Url1 = https://multiple.url.test\n"
- "Max Failure Count Per Url = 0\n"
- "Disable Payload Backoff = 0\n";
- EXPECT_EQ(expected_response_sign, stored_response_sign);
- EXPECT_EQ("http://multiple.url.test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
- EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
- }
- TEST(PayloadStateTest, CanAdvanceUrlIndexCorrectly) {
- OmahaResponse response;
- FakeSystemState fake_system_state;
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- PayloadState payload_state;
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
-
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 1))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 1))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsBackoffExpiryTime, _)).Times(AtLeast(2));
-
- EXPECT_CALL(*prefs, SetInt64(kPrefsNumReboots, _)).Times(AtLeast(1));
-
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 1)).Times(AtLeast(1));
-
-
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 0))
- .Times(AtLeast(4));
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
-
- SetupPayloadStateWith2Urls(
- "Hash1235", true, false, &payload_state, &response);
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
-
- ErrorCode error = ErrorCode::kDownloadMetadataSignatureMismatch;
- payload_state.UpdateFailed(error);
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
-
- payload_state.UpdateFailed(error);
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
-
- payload_state.UpdateFailed(error);
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
-
- EXPECT_EQ(3U, payload_state.GetUrlSwitchCount());
- }
- TEST(PayloadStateTest, NewResponseResetsPayloadState) {
- OmahaResponse response;
- FakeSystemState fake_system_state;
- PayloadState payload_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
- SetupPayloadStateWith2Urls(
- "Hash5823", true, false, &payload_state, &response);
- EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
-
- ErrorCode error = ErrorCode::kDownloadMetadataSignatureMismatch;
- payload_state.UpdateFailed(error);
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
-
- SetupPayloadStateWith2Urls(
- "Hash8225", true, false, &payload_state, &response);
- EXPECT_EQ(2, payload_state.GetNumResponsesSeen());
-
- payload_state.UpdateFailed(error);
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
-
- SetupPayloadStateWith2Urls(
- "Hash9999", true, false, &payload_state, &response);
- EXPECT_EQ(3, payload_state.GetNumResponsesSeen());
-
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
- EXPECT_EQ(0U,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(0U,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(
- 0U, payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpsServer));
- EXPECT_EQ(0U,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpsServer));
- }
- TEST(PayloadStateTest, AllCountersGetUpdatedProperlyOnErrorCodesAndEvents) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- int progress_bytes = 100;
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
- .Times(AtLeast(2));
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 1))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 2))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 0))
- .Times(AtLeast(2));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 1))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 2))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsBackoffExpiryTime, _)).Times(AtLeast(4));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 0)).Times(AtLeast(4));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 1)).Times(AtLeast(2));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 0))
- .Times(AtLeast(7));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 1))
- .Times(AtLeast(2));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 2))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsUpdateTimestampStart, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsUpdateDurationUptime, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttps, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttp, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttpPeer, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kCurrentBytesDownloadedFromHttp, progress_bytes))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kTotalBytesDownloadedFromHttp, progress_bytes))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsNumReboots, 0)).Times(AtLeast(1));
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash5873", true, false, &payload_state, &response);
- EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
-
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
-
- payload_state.UpdateFailed(ErrorCode::kDownloadTransferError);
- EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(1U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
-
- payload_state.UpdateFailed(ErrorCode::kDownloadTransferError);
- EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(2U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
-
-
-
-
- payload_state.UpdateFailed(ErrorCode::kDownloadTransferError);
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(1, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(2U, payload_state.GetUrlSwitchCount());
- EXPECT_TRUE(payload_state.ShouldBackoffDownload());
-
- payload_state.UpdateFailed(ErrorCode::kPayloadHashMismatchError);
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(1, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(3U, payload_state.GetUrlSwitchCount());
- EXPECT_TRUE(payload_state.ShouldBackoffDownload());
-
-
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMissingError);
- EXPECT_EQ(2, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(2, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(4U, payload_state.GetUrlSwitchCount());
- EXPECT_TRUE(payload_state.ShouldBackoffDownload());
-
- payload_state.UpdateFailed(static_cast<ErrorCode>(
- static_cast<int>(ErrorCode::kOmahaRequestHTTPResponseBase) + 404));
- EXPECT_EQ(2, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(2, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(1U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(4U, payload_state.GetUrlSwitchCount());
- EXPECT_TRUE(payload_state.ShouldBackoffDownload());
-
-
- payload_state.DownloadProgress(progress_bytes);
- EXPECT_EQ(2, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(2, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(4U, payload_state.GetUrlSwitchCount());
- EXPECT_TRUE(payload_state.ShouldBackoffDownload());
-
- SetupPayloadStateWith2Urls(
- "Hash8532", true, false, &payload_state, &response);
- EXPECT_EQ(2, payload_state.GetNumResponsesSeen());
-
- EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
- EXPECT_FALSE(payload_state.ShouldBackoffDownload());
- }
- TEST(PayloadStateTest, PayloadAttemptNumberIncreasesOnSuccessfulFullDownload) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 1))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 1))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsBackoffExpiryTime, _)).Times(AtLeast(2));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 0))
- .Times(AtLeast(1));
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash8593", true, false, &payload_state, &response);
-
- EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- payload_state.DownloadComplete();
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(1, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
- }
- TEST(PayloadStateTest, PayloadAttemptNumberIncreasesOnSuccessfulDeltaDownload) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AnyNumber());
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsPayloadAttemptNumber, 1))
- .Times(AtLeast(1));
-
- EXPECT_CALL(*prefs, SetInt64(kPrefsFullPayloadAttemptNumber, 0))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsBackoffExpiryTime, _)).Times(1);
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlIndex, 0)).Times(AtLeast(1));
- EXPECT_CALL(*prefs, SetInt64(kPrefsCurrentUrlFailureCount, 0))
- .Times(AtLeast(1));
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash8593", true, true, &payload_state, &response);
-
- EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- payload_state.DownloadComplete();
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
- }
- TEST(PayloadStateTest, SetResponseResetsInvalidUrlIndex) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash4427", true, false, &payload_state, &response);
-
-
- payload_state.DownloadComplete();
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- payload_state.UpdateFailed(ErrorCode::kDownloadTransferError);
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(1, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(1U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
-
-
-
- FakeSystemState fake_system_state2;
- NiceMock<MockPrefs>* prefs2 = fake_system_state2.mock_prefs();
- EXPECT_CALL(*prefs2, Exists(_)).WillRepeatedly(Return(true));
- EXPECT_CALL(*prefs2, GetInt64(_, _)).Times(AtLeast(1));
- EXPECT_CALL(*prefs2, GetInt64(kPrefsPayloadAttemptNumber, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs2, GetInt64(kPrefsFullPayloadAttemptNumber, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs2, GetInt64(kPrefsCurrentUrlIndex, _))
- .WillRepeatedly(DoAll(SetArgPointee<1>(2), Return(true)));
- EXPECT_CALL(*prefs2, GetInt64(kPrefsCurrentUrlFailureCount, _))
- .Times(AtLeast(1));
- EXPECT_CALL(*prefs2, GetInt64(kPrefsUrlSwitchCount, _)).Times(AtLeast(1));
-
-
-
-
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state2));
- SetupPayloadStateWith2Urls(
- "Hash4427", true, false, &payload_state, &response);
-
-
- EXPECT_EQ(0, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
- }
- TEST(PayloadStateTest, NoBackoffInteractiveChecks) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- OmahaRequestParams params(&fake_system_state);
- params.Init("", "", true);
- fake_system_state.set_request_params(¶ms);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash6437", true, false, &payload_state, &response);
-
-
-
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(1, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_FALSE(payload_state.ShouldBackoffDownload());
- }
- TEST(PayloadStateTest, NoBackoffForP2PUpdates) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- OmahaRequestParams params(&fake_system_state);
- params.Init("", "", false);
- fake_system_state.set_request_params(¶ms);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash6437", true, false, &payload_state, &response);
-
-
-
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(1, payload_state.GetFullPayloadAttemptNumber());
-
- payload_state.SetUsingP2PForDownloading(true);
- payload_state.SetP2PUrl("http://mypeer:52909/path/to/file");
-
- EXPECT_FALSE(payload_state.ShouldBackoffDownload());
- payload_state.SetP2PUrl("");
-
- EXPECT_TRUE(payload_state.ShouldBackoffDownload());
- }
- TEST(PayloadStateTest, NoBackoffForDeltaPayloads) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, true, &payload_state, &response);
-
-
- payload_state.DownloadComplete();
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_FALSE(payload_state.ShouldBackoffDownload());
-
-
-
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(2, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(0, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_FALSE(payload_state.ShouldBackoffDownload());
- }
- static void CheckPayloadBackoffState(PayloadState* payload_state,
- int expected_attempt_number,
- TimeDelta expected_days) {
- payload_state->DownloadComplete();
- EXPECT_EQ(expected_attempt_number,
- payload_state->GetFullPayloadAttemptNumber());
- EXPECT_TRUE(payload_state->ShouldBackoffDownload());
- Time backoff_expiry_time = payload_state->GetBackoffExpiryTime();
-
- TimeDelta max_fuzz_delta = TimeDelta::FromHours(7);
- Time expected_min_time = Time::Now() + expected_days - max_fuzz_delta;
- Time expected_max_time = Time::Now() + expected_days + max_fuzz_delta;
- EXPECT_LT(expected_min_time.ToInternalValue(),
- backoff_expiry_time.ToInternalValue());
- EXPECT_GT(expected_max_time.ToInternalValue(),
- backoff_expiry_time.ToInternalValue());
- }
- TEST(PayloadStateTest, BackoffPeriodsAreInCorrectRange) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash8939", true, false, &payload_state, &response);
- CheckPayloadBackoffState(&payload_state, 1, TimeDelta::FromDays(1));
- CheckPayloadBackoffState(&payload_state, 2, TimeDelta::FromDays(2));
- CheckPayloadBackoffState(&payload_state, 3, TimeDelta::FromDays(4));
- CheckPayloadBackoffState(&payload_state, 4, TimeDelta::FromDays(8));
- CheckPayloadBackoffState(&payload_state, 5, TimeDelta::FromDays(16));
- CheckPayloadBackoffState(&payload_state, 6, TimeDelta::FromDays(16));
- CheckPayloadBackoffState(&payload_state, 7, TimeDelta::FromDays(16));
- CheckPayloadBackoffState(&payload_state, 8, TimeDelta::FromDays(16));
- CheckPayloadBackoffState(&payload_state, 9, TimeDelta::FromDays(16));
- CheckPayloadBackoffState(&payload_state, 10, TimeDelta::FromDays(16));
- }
- TEST(PayloadStateTest, BackoffLogicCanBeDisabled) {
- OmahaResponse response;
- response.disable_payload_backoff = true;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash8939", true, false, &payload_state, &response);
-
-
- payload_state.DownloadComplete();
- EXPECT_EQ(1, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(1, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_FALSE(payload_state.ShouldBackoffDownload());
-
-
-
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- payload_state.UpdateFailed(ErrorCode::kDownloadMetadataSignatureMismatch);
- EXPECT_EQ(2, payload_state.GetPayloadAttemptNumber());
- EXPECT_EQ(2, payload_state.GetFullPayloadAttemptNumber());
- EXPECT_FALSE(payload_state.ShouldBackoffDownload());
- }
- TEST(PayloadStateTest, BytesDownloadedMetricsGetAddedToCorrectSources) {
- OmahaResponse response;
- response.disable_payload_backoff = true;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- uint64_t https_total = 0;
- uint64_t http_total = 0;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash3286", true, false, &payload_state, &response);
- EXPECT_EQ(1, payload_state.GetNumResponsesSeen());
-
-
- uint64_t prev_chunk = 323456789;
- http_total += prev_chunk;
- payload_state.DownloadProgress(prev_chunk);
-
- EXPECT_EQ(prev_chunk,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(http_total,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
-
-
- SetupPayloadStateWith2Urls(
- "Hash9904", true, false, &payload_state, &response);
- EXPECT_EQ(2, payload_state.GetNumResponsesSeen());
-
- uint64_t first_chunk = 5000000;
- http_total += first_chunk;
- payload_state.DownloadProgress(first_chunk);
-
- EXPECT_EQ(first_chunk,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(http_total,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(
- 0U, payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpsServer));
- EXPECT_EQ(https_total,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpsServer));
-
- ErrorCode error = ErrorCode::kDownloadMetadataSignatureMismatch;
- payload_state.UpdateFailed(error);
-
- uint64_t second_chunk = 23456789;
- https_total += second_chunk;
- payload_state.DownloadProgress(second_chunk);
- EXPECT_EQ(first_chunk,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(http_total,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(
- second_chunk,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpsServer));
- EXPECT_EQ(https_total,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpsServer));
-
- payload_state.UpdateFailed(error);
- uint64_t third_chunk = 32345678;
- uint64_t http_chunk = first_chunk + third_chunk;
- http_total += third_chunk;
- payload_state.DownloadProgress(third_chunk);
-
- EXPECT_EQ(http_chunk,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(http_total,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(
- second_chunk,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpsServer));
- EXPECT_EQ(https_total,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpsServer));
-
-
- payload_state.UpdateFailed(error);
- payload_state.SetUsingP2PForDownloading(true);
- uint64_t p2p_total = 42 * 1000 * 1000;
- payload_state.DownloadProgress(p2p_total);
- EXPECT_EQ(p2p_total,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpPeer));
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportSuccessfulUpdateMetrics(
- 1, _, kPayloadTypeFull, _, _, 314, _, _, _, 3));
- payload_state.UpdateSucceeded();
-
- EXPECT_EQ(0U,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(0U,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(
- 0U, payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpsServer));
- EXPECT_EQ(0U,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpsServer));
- EXPECT_EQ(0, payload_state.GetNumResponsesSeen());
- }
- TEST(PayloadStateTest, DownloadSourcesUsedIsCorrect) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash3286", true, false, &payload_state, &response);
-
- uint64_t num_bytes = 42 * 1000 * 1000;
- payload_state.DownloadProgress(num_bytes);
-
- EXPECT_EQ(num_bytes,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(num_bytes,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
-
- int64_t total_bytes[kNumDownloadSources] = {};
- total_bytes[kDownloadSourceHttpServer] = num_bytes;
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportSuccessfulUpdateMetrics(
- _,
- _,
- _,
- _,
- test_utils::DownloadSourceMatcher(total_bytes),
- _,
- _,
- _,
- _,
- _))
- .Times(1);
- payload_state.UpdateSucceeded();
- }
- TEST(PayloadStateTest, RestartingUpdateResetsMetrics) {
- OmahaResponse response;
- FakeSystemState fake_system_state;
- PayloadState payload_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
- SetupPayloadStateWith2Urls(
- "Hash5823", true, false, &payload_state, &response);
- uint64_t num_bytes = 10000;
- payload_state.DownloadProgress(num_bytes);
- EXPECT_EQ(num_bytes,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(num_bytes,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(
- 0U, payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpsServer));
- EXPECT_EQ(0U,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpsServer));
- payload_state.UpdateRestarted();
-
- EXPECT_EQ(0U,
- payload_state.GetCurrentBytesDownloaded(kDownloadSourceHttpServer));
- EXPECT_EQ(num_bytes,
- payload_state.GetTotalBytesDownloaded(kDownloadSourceHttpServer));
- }
- TEST(PayloadStateTest, NumRebootsIncrementsCorrectly) {
- FakeSystemState fake_system_state;
- PayloadState payload_state;
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(AtLeast(0));
- EXPECT_CALL(*prefs, SetInt64(kPrefsNumReboots, 1)).Times(AtLeast(1));
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- payload_state.UpdateRestarted();
- EXPECT_EQ(0U, payload_state.GetNumReboots());
- fake_system_state.set_system_rebooted(true);
- payload_state.UpdateResumed();
-
- EXPECT_EQ(1U, payload_state.GetNumReboots());
- fake_system_state.set_system_rebooted(false);
- payload_state.UpdateResumed();
-
- EXPECT_EQ(1U, payload_state.GetNumReboots());
-
- payload_state.UpdateRestarted();
- EXPECT_EQ(0U, payload_state.GetNumReboots());
- }
- TEST(PayloadStateTest, RollbackHappened) {
- FakeSystemState fake_system_state;
- PayloadState payload_state;
- NiceMock<MockPrefs>* mock_powerwash_safe_prefs =
- fake_system_state.mock_powerwash_safe_prefs();
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
- EXPECT_FALSE(payload_state.GetRollbackHappened());
-
- EXPECT_CALL(*mock_powerwash_safe_prefs,
- SetBoolean(kPrefsRollbackHappened, true));
- payload_state.SetRollbackHappened(true);
- EXPECT_TRUE(payload_state.GetRollbackHappened());
-
- EXPECT_CALL(*mock_powerwash_safe_prefs, Delete(kPrefsRollbackHappened));
- payload_state.SetRollbackHappened(false);
- EXPECT_FALSE(payload_state.GetRollbackHappened());
-
- EXPECT_CALL(*mock_powerwash_safe_prefs, GetBoolean(kPrefsRollbackHappened, _))
- .WillOnce(DoAll(SetArgPointee<1>(true), Return(true)));
- EXPECT_CALL(*mock_powerwash_safe_prefs,
- SetBoolean(kPrefsRollbackHappened, true));
- payload_state.LoadRollbackHappened();
- EXPECT_TRUE(payload_state.GetRollbackHappened());
- }
- TEST(PayloadStateTest, RollbackVersion) {
- FakeSystemState fake_system_state;
- PayloadState payload_state;
- NiceMock<MockPrefs>* mock_powerwash_safe_prefs =
- fake_system_state.mock_powerwash_safe_prefs();
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
- EXPECT_TRUE(payload_state.GetRollbackVersion().empty());
-
- string rollback_version = "2345.0.0";
- OmahaRequestParams params(&fake_system_state);
- params.Init(rollback_version, "", false);
- fake_system_state.set_request_params(¶ms);
- EXPECT_CALL(*mock_powerwash_safe_prefs,
- SetString(kPrefsRollbackVersion, rollback_version));
- payload_state.Rollback();
- EXPECT_EQ(rollback_version, payload_state.GetRollbackVersion());
-
- rollback_version = "2345.0.1";
-
- EXPECT_CALL(*mock_powerwash_safe_prefs, GetString(kPrefsRollbackVersion, _))
- .WillOnce(DoAll(SetArgPointee<1>(rollback_version), Return(true)));
- EXPECT_CALL(*mock_powerwash_safe_prefs,
- SetString(kPrefsRollbackVersion, rollback_version));
- payload_state.LoadRollbackVersion();
- EXPECT_EQ(rollback_version, payload_state.GetRollbackVersion());
-
-
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportRollbackMetrics(metrics::RollbackResult::kSuccess))
- .Times(1);
- payload_state.UpdateSucceeded();
- }
- TEST(PayloadStateTest, DurationsAreCorrect) {
- OmahaResponse response;
- response.packages.resize(1);
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakeClock fake_clock;
- FakePrefs fake_prefs;
-
-
- fake_clock.SetWallclockTime(Time::FromInternalValue(1000000));
- fake_clock.SetMonotonicTime(Time::FromInternalValue(2000000));
- fake_system_state.set_clock(&fake_clock);
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
-
-
- SetupPayloadStateWith2Urls(
- "Hash8593", true, false, &payload_state, &response);
- fake_clock.SetWallclockTime(Time::FromInternalValue(8000000));
- fake_clock.SetMonotonicTime(Time::FromInternalValue(6000000));
- payload_state.UpdateSucceeded();
- EXPECT_EQ(payload_state.GetUpdateDuration().InMicroseconds(), 7000000);
- EXPECT_EQ(payload_state.GetUpdateDurationUptime().InMicroseconds(), 4000000);
-
- SetupPayloadStateWith2Urls(
- "Hash8594", true, false, &payload_state, &response);
- EXPECT_EQ(payload_state.GetUpdateDuration().InMicroseconds(), 0);
- EXPECT_EQ(payload_state.GetUpdateDurationUptime().InMicroseconds(), 0);
-
-
- fake_clock.SetWallclockTime(Time::FromInternalValue(18000000));
- fake_clock.SetMonotonicTime(Time::FromInternalValue(16000000));
- payload_state.DownloadProgress(10);
- EXPECT_EQ(payload_state.GetUpdateDuration().InMicroseconds(), 10000000);
- EXPECT_EQ(payload_state.GetUpdateDurationUptime().InMicroseconds(), 10000000);
-
-
-
- fake_clock.SetMonotonicTime(Time::FromInternalValue(5000));
- PayloadState payload_state2;
- EXPECT_TRUE(payload_state2.Initialize(&fake_system_state));
- payload_state2.SetResponse(response);
- EXPECT_EQ(payload_state2.GetUpdateDuration().InMicroseconds(), 10000000);
- EXPECT_EQ(payload_state2.GetUpdateDurationUptime().InMicroseconds(),
- 10000000);
-
-
- fake_clock.SetWallclockTime(Time::FromInternalValue(25000000));
- fake_clock.SetMonotonicTime(Time::FromInternalValue(6005000));
- payload_state2.UpdateSucceeded();
- EXPECT_EQ(payload_state2.GetUpdateDuration().InMicroseconds(), 17000000);
- EXPECT_EQ(payload_state2.GetUpdateDurationUptime().InMicroseconds(),
- 16000000);
- }
- TEST(PayloadStateTest, RebootAfterSuccessfulUpdateTest) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakeClock fake_clock;
- FakePrefs fake_prefs;
-
- fake_clock.SetMonotonicTime(
- Time::FromInternalValue(30 * Time::kMicrosecondsPerSecond));
- fake_system_state.set_clock(&fake_clock);
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
- SetupPayloadStateWith2Urls(
- "Hash8593", true, false, &payload_state, &response);
- payload_state.UpdateSucceeded();
-
- EXPECT_TRUE(fake_prefs.Exists(kPrefsSystemUpdatedMarker));
-
-
-
-
- fake_clock.SetMonotonicTime(
- Time::FromInternalValue(500 * Time::kMicrosecondsPerSecond));
- PayloadState payload_state2;
- EXPECT_TRUE(payload_state2.Initialize(&fake_system_state));
-
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportTimeToReboot(7));
- fake_system_state.set_system_rebooted(true);
- payload_state2.UpdateEngineStarted();
-
- EXPECT_FALSE(fake_prefs.Exists(kPrefsSystemUpdatedMarker));
- }
- TEST(PayloadStateTest, RestartAfterCrash) {
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- testing::StrictMock<MockMetricsReporter> mock_metrics_reporter;
- fake_system_state.set_metrics_reporter(&mock_metrics_reporter);
- NiceMock<MockPrefs>* prefs = fake_system_state.mock_prefs();
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
- EXPECT_CALL(*prefs, Exists(_)).Times(0);
- EXPECT_CALL(*prefs, SetString(_, _)).Times(0);
- EXPECT_CALL(*prefs, SetInt64(_, _)).Times(0);
- EXPECT_CALL(*prefs, SetBoolean(_, _)).Times(0);
- EXPECT_CALL(*prefs, GetString(_, _)).Times(0);
- EXPECT_CALL(*prefs, GetInt64(_, _)).Times(0);
- EXPECT_CALL(*prefs, GetBoolean(_, _)).Times(0);
- EXPECT_CALL(*prefs, GetBoolean(kPrefsAttemptInProgress, _));
-
- fake_system_state.set_system_rebooted(false);
- payload_state.UpdateEngineStarted();
- }
- TEST(PayloadStateTest, AbnormalTerminationAttemptMetricsNoReporting) {
- PayloadState payload_state;
- FakeSystemState fake_system_state;
-
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportAbnormallyTerminatedUpdateAttemptMetrics())
- .Times(0);
- payload_state.UpdateEngineStarted();
- }
- TEST(PayloadStateTest, AbnormalTerminationAttemptMetricsReported) {
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakePrefs fake_prefs;
-
-
- fake_system_state.set_prefs(&fake_prefs);
- fake_prefs.SetBoolean(kPrefsAttemptInProgress, true);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportAbnormallyTerminatedUpdateAttemptMetrics())
- .Times(1);
- payload_state.UpdateEngineStarted();
- EXPECT_FALSE(fake_prefs.Exists(kPrefsAttemptInProgress));
- }
- TEST(PayloadStateTest, AbnormalTerminationAttemptMetricsClearedOnSucceess) {
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakePrefs fake_prefs;
-
-
-
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- OmahaResponse response;
- response.packages.resize(1);
- payload_state.SetResponse(response);
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportAbnormallyTerminatedUpdateAttemptMetrics())
- .Times(0);
-
- EXPECT_FALSE(fake_prefs.Exists(kPrefsAttemptInProgress));
- payload_state.UpdateRestarted();
-
- EXPECT_TRUE(fake_prefs.Exists(kPrefsAttemptInProgress));
- payload_state.UpdateSucceeded();
-
- EXPECT_FALSE(fake_prefs.Exists(kPrefsAttemptInProgress));
- }
- TEST(PayloadStateTest, CandidateUrlsComputedCorrectly) {
- OmahaResponse response;
- FakeSystemState fake_system_state;
- PayloadState payload_state;
- policy::MockDevicePolicy disable_http_policy;
- fake_system_state.set_device_policy(&disable_http_policy);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
-
- EXPECT_CALL(disable_http_policy, GetHttpDownloadsEnabled(_))
- .WillRepeatedly(Return(false));
-
- SetupPayloadStateWith2Urls(
- "Hash8433", true, false, &payload_state, &response);
-
-
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
-
- EXPECT_CALL(disable_http_policy, GetHttpDownloadsEnabled(_))
- .WillRepeatedly(DoAll(SetArgPointee<0>(false), Return(true)));
-
- SetupPayloadStateWith2Urls(
- "Hash8433", false, false, &payload_state, &response);
-
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
-
- ErrorCode error = ErrorCode::kDownloadMetadataSignatureMismatch;
- payload_state.UpdateFailed(error);
-
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlSwitchCount());
-
- SetupPayloadStateWith2Urls(
- "Hash2399", false, false, &payload_state, &response);
-
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
-
-
- policy::MockDevicePolicy enable_http_policy;
- fake_system_state.set_device_policy(&enable_http_policy);
- EXPECT_CALL(enable_http_policy, GetHttpDownloadsEnabled(_))
- .WillRepeatedly(DoAll(SetArgPointee<0>(true), Return(true)));
-
-
-
-
- SetupPayloadStateWith2Urls(
- "Hash2399", true, false, &payload_state, &response);
-
- EXPECT_EQ("http://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
-
-
- payload_state.UpdateFailed(error);
- EXPECT_EQ("https://test", payload_state.GetCurrentUrl());
- EXPECT_EQ(1U, payload_state.GetUrlSwitchCount());
- EXPECT_EQ(0U, payload_state.GetUrlFailureCount());
- }
- TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsDelta) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, true, &payload_state, &response);
-
- payload_state.DownloadComplete();
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportSuccessfulUpdateMetrics(
- _, _, kPayloadTypeDelta, _, _, _, _, _, _, _));
- payload_state.UpdateSucceeded();
-
-
- OmahaRequestParams params(&fake_system_state);
- params.set_delta_okay(false);
- fake_system_state.set_request_params(¶ms);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls("Hash6437", true, true, &payload_state, &response);
- payload_state.DownloadComplete();
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportSuccessfulUpdateMetrics(
- _, _, kPayloadTypeDelta, _, _, _, _, _, _, _));
- payload_state.UpdateSucceeded();
- }
- TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsForcedFull) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash6437", true, false, &payload_state, &response);
-
- OmahaRequestParams params(&fake_system_state);
- params.set_delta_okay(false);
- fake_system_state.set_request_params(¶ms);
-
- payload_state.DownloadComplete();
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportSuccessfulUpdateMetrics(
- _, _, kPayloadTypeForcedFull, _, _, _, _, _, _, _));
- payload_state.UpdateSucceeded();
- }
- TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsFull) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash6437", true, false, &payload_state, &response);
-
-
- OmahaRequestParams params(&fake_system_state);
- params.set_delta_okay(true);
- fake_system_state.set_request_params(¶ms);
-
- payload_state.DownloadComplete();
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportSuccessfulUpdateMetrics(
- _, _, kPayloadTypeFull, _, _, _, _, _, _, _));
- payload_state.UpdateSucceeded();
- }
- TEST(PayloadStateTest, RebootAfterUpdateFailedMetric) {
- FakeSystemState fake_system_state;
- OmahaResponse response;
- PayloadState payload_state;
- FakePrefs fake_prefs;
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash3141", true, false, &payload_state, &response);
-
- payload_state.DownloadComplete();
- payload_state.UpdateSucceeded();
- payload_state.ExpectRebootInNewVersion("Version:12345678");
-
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportFailedUpdateCount(1));
- payload_state.ReportFailedBootIfNeeded();
- Mock::VerifyAndClearExpectations(fake_system_state.mock_metrics_reporter());
-
-
- payload_state.ExpectRebootInNewVersion("Version:12345678");
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportFailedUpdateCount(2));
- payload_state.ReportFailedBootIfNeeded();
- Mock::VerifyAndClearExpectations(fake_system_state.mock_metrics_reporter());
-
-
- payload_state.ExpectRebootInNewVersion("Version:3141592");
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportFailedUpdateCount(1));
- payload_state.ReportFailedBootIfNeeded();
- Mock::VerifyAndClearExpectations(fake_system_state.mock_metrics_reporter());
- }
- TEST(PayloadStateTest, RebootAfterUpdateSucceed) {
- FakeSystemState fake_system_state;
- OmahaResponse response;
- PayloadState payload_state;
- FakePrefs fake_prefs;
- fake_system_state.set_prefs(&fake_prefs);
- FakeBootControl* fake_boot_control = fake_system_state.fake_boot_control();
- fake_boot_control->SetCurrentSlot(0);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash3141", true, false, &payload_state, &response);
-
- payload_state.DownloadComplete();
- payload_state.UpdateSucceeded();
- payload_state.ExpectRebootInNewVersion("Version:12345678");
-
- fake_boot_control->SetCurrentSlot(1);
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportFailedUpdateCount(_))
- .Times(0);
- payload_state.ReportFailedBootIfNeeded();
-
- payload_state.ReportFailedBootIfNeeded();
- fake_boot_control->SetCurrentSlot(0);
- payload_state.ReportFailedBootIfNeeded();
- }
- TEST(PayloadStateTest, RebootAfterCanceledUpdate) {
- FakeSystemState fake_system_state;
- OmahaResponse response;
- PayloadState payload_state;
- FakePrefs fake_prefs;
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash3141", true, false, &payload_state, &response);
-
- payload_state.DownloadComplete();
- payload_state.UpdateSucceeded();
- payload_state.ExpectRebootInNewVersion("Version:12345678");
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportFailedUpdateCount(_))
- .Times(0);
-
- payload_state.ResetUpdateStatus();
-
- payload_state.ReportFailedBootIfNeeded();
- }
- TEST(PayloadStateTest, UpdateSuccessWithWipedPrefs) {
- FakeSystemState fake_system_state;
- PayloadState payload_state;
- FakePrefs fake_prefs;
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- EXPECT_CALL(*fake_system_state.mock_metrics_reporter(),
- ReportFailedUpdateCount(_))
- .Times(0);
-
- payload_state.ReportFailedBootIfNeeded();
- }
- TEST(PayloadStateTest, DisallowP2PAfterTooManyAttempts) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakePrefs fake_prefs;
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash8593", true, false, &payload_state, &response);
-
- for (int n = 0; n < kMaxP2PAttempts; n++) {
- payload_state.P2PNewAttempt();
- EXPECT_TRUE(payload_state.P2PAttemptAllowed());
- }
-
- payload_state.P2PNewAttempt();
- EXPECT_FALSE(payload_state.P2PAttemptAllowed());
- }
- TEST(PayloadStateTest, DisallowP2PAfterDeadline) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakeClock fake_clock;
- FakePrefs fake_prefs;
- fake_system_state.set_clock(&fake_clock);
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash8593", true, false, &payload_state, &response);
-
- Time epoch = Time::FromInternalValue(1000000);
- fake_clock.SetWallclockTime(epoch);
-
- payload_state.P2PNewAttempt();
-
- EXPECT_EQ(epoch, payload_state.GetP2PFirstAttemptTimestamp());
-
- EXPECT_TRUE(payload_state.P2PAttemptAllowed());
-
- fake_clock.SetWallclockTime(
- epoch + TimeDelta::FromSeconds(kMaxP2PAttemptTimeSeconds) / 2);
- EXPECT_TRUE(payload_state.P2PAttemptAllowed());
-
-
- EXPECT_EQ(epoch, payload_state.GetP2PFirstAttemptTimestamp());
-
- fake_clock.SetWallclockTime(
- epoch + TimeDelta::FromSeconds(kMaxP2PAttemptTimeSeconds - 1));
- EXPECT_TRUE(payload_state.P2PAttemptAllowed());
-
- fake_clock.SetWallclockTime(
- epoch + TimeDelta::FromSeconds(kMaxP2PAttemptTimeSeconds + 1));
- EXPECT_FALSE(payload_state.P2PAttemptAllowed());
- }
- TEST(PayloadStateTest, P2PStateVarsInitialValue) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakePrefs fake_prefs;
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash8593", true, false, &payload_state, &response);
- Time null_time = Time();
- EXPECT_EQ(null_time, payload_state.GetP2PFirstAttemptTimestamp());
- EXPECT_EQ(0, payload_state.GetP2PNumAttempts());
- }
- TEST(PayloadStateTest, P2PStateVarsArePersisted) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakeClock fake_clock;
- FakePrefs fake_prefs;
- fake_system_state.set_clock(&fake_clock);
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash8593", true, false, &payload_state, &response);
-
- Time time = Time::FromInternalValue(12345);
- fake_clock.SetWallclockTime(time);
-
- payload_state.P2PNewAttempt();
- EXPECT_EQ(1, payload_state.GetP2PNumAttempts());
- EXPECT_EQ(time, payload_state.GetP2PFirstAttemptTimestamp());
-
-
- PayloadState payload_state2;
- EXPECT_TRUE(payload_state2.Initialize(&fake_system_state));
- EXPECT_EQ(1, payload_state2.GetP2PNumAttempts());
- EXPECT_EQ(time, payload_state2.GetP2PFirstAttemptTimestamp());
- }
- TEST(PayloadStateTest, P2PStateVarsAreClearedOnNewResponse) {
- OmahaResponse response;
- PayloadState payload_state;
- FakeSystemState fake_system_state;
- FakeClock fake_clock;
- FakePrefs fake_prefs;
- fake_system_state.set_clock(&fake_clock);
- fake_system_state.set_prefs(&fake_prefs);
- EXPECT_TRUE(payload_state.Initialize(&fake_system_state));
- SetupPayloadStateWith2Urls(
- "Hash8593", true, false, &payload_state, &response);
-
- Time time = Time::FromInternalValue(12345);
- fake_clock.SetWallclockTime(time);
-
- payload_state.P2PNewAttempt();
- EXPECT_EQ(1, payload_state.GetP2PNumAttempts());
- EXPECT_EQ(time, payload_state.GetP2PFirstAttemptTimestamp());
-
- SetupPayloadStateWith2Urls(
- "Hash9904", true, false, &payload_state, &response);
-
- Time null_time = Time();
- EXPECT_EQ(0, payload_state.GetP2PNumAttempts());
- EXPECT_EQ(null_time, payload_state.GetP2PFirstAttemptTimestamp());
- }
- }
|