AU: Send a previous version event after reboot following an update.
The previous version event is sent along with the first update check. This is
best effort -- if the update check doesn't reach the server, the event is lost.
BUG=9198
TEST=unit tests, tested on device
Change-Id: I5ceb7c8e99ae54eb331f6ac58b8977d2a111461c
Review URL: http://codereview.chromium.org/5993007
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index 8fe2482..4ac2b74 100755
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -521,7 +521,11 @@
TEST(OmahaRequestActionTest, FormatUpdateCheckOutputTest) {
vector<char> post_data;
- ASSERT_FALSE(TestUpdateCheck(NULL, // prefs
+ NiceMock<PrefsMock> prefs;
+ EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(string("")), Return(true)));
+ EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, _)).Times(0);
+ ASSERT_FALSE(TestUpdateCheck(&prefs,
kDefaultTestParams,
"invalid xml>",
-1,
@@ -538,6 +542,35 @@
EXPECT_EQ(post_str.find("o:event"), string::npos);
}
+TEST(OmahaRequestActionTest, FormatUpdateCheckPrevVersionOutputTest) {
+ vector<char> post_data;
+ NiceMock<PrefsMock> prefs;
+ EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _))
+ .WillOnce(DoAll(SetArgumentPointee<1>(string("1.2.3.4")), Return(true)));
+ EXPECT_CALL(prefs, SetString(kPrefsPreviousVersion, ""))
+ .WillOnce(Return(true));
+ ASSERT_FALSE(TestUpdateCheck(&prefs,
+ kDefaultTestParams,
+ "invalid xml>",
+ -1,
+ kActionCodeOmahaRequestXMLParseError,
+ NULL, // response
+ &post_data));
+ // convert post_data to string
+ string post_str(&post_data[0], post_data.size());
+ EXPECT_NE(post_str.find(" <o:ping a=\"-1\" r=\"-1\"></o:ping>\n"
+ " <o:updatecheck></o:updatecheck>\n"),
+ string::npos);
+ EXPECT_NE(post_str.find("hardware_class=\"OEM MODEL 09235 7471\""),
+ string::npos);
+ string prev_version_event = StringPrintf(
+ " <o:event eventtype=\"%d\" eventresult=\"%d\" "
+ "previousversion=\"1.2.3.4\"></o:event>\n",
+ OmahaEvent::kTypeUpdateComplete,
+ OmahaEvent::kResultSuccessReboot);
+ EXPECT_NE(post_str.find(prev_version_event), string::npos);
+}
+
TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) {
vector<char> post_data;
TestEvent(kDefaultTestParams,