Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(640)

Side by Side Diff: omaha_request_action_unittest.cc

Issue 6154003: AU: Reduce instances of signalling the crash reporter. (Closed) Base URL: http://git.chromium.org/git/update_engine.git@master
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include <glib.h> 8 #include <glib.h>
9 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 *out_post_data = fetcher->post_data(); 191 *out_post_data = fetcher->post_data();
192 return collector_action.has_input_object_; 192 return collector_action.has_input_object_;
193 } 193 }
194 194
195 // Tests Event requests -- they should always succeed. |out_post_data| 195 // Tests Event requests -- they should always succeed. |out_post_data|
196 // may be null; if non-null, the post-data received by the mock 196 // may be null; if non-null, the post-data received by the mock
197 // HttpFetcher is returned. 197 // HttpFetcher is returned.
198 void TestEvent(const OmahaRequestParams& params, 198 void TestEvent(const OmahaRequestParams& params,
199 OmahaEvent* event, 199 OmahaEvent* event,
200 const string& http_response, 200 const string& http_response,
201 vector<char>* out_post_data) { 201 vector<char>* out_post_data,
202 int expected_http_response_code) {
202 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); 203 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE);
203 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(), 204 MockHttpFetcher* fetcher = new MockHttpFetcher(http_response.data(),
204 http_response.size(), 205 http_response.size(),
205 NULL); 206 NULL);
206 NiceMock<PrefsMock> prefs; 207 NiceMock<PrefsMock> prefs;
207 OmahaRequestAction action(&prefs, params, event, fetcher); 208 OmahaRequestAction action(&prefs, params, event, fetcher);
208 OmahaRequestActionTestProcessorDelegate delegate; 209 OmahaRequestActionTestProcessorDelegate delegate;
210 if (expected_http_response_code < 200 || expected_http_response_code > 299) {
211 fetcher->FailTransfer(expected_http_response_code);
212 delegate.expected_code_ =
213 static_cast<ActionExitCode>(kActionCodeOmahaRequestHTTPResponseBase +
214 expected_http_response_code);
215 }
209 delegate.loop_ = loop; 216 delegate.loop_ = loop;
210 ActionProcessor processor; 217 ActionProcessor processor;
211 processor.set_delegate(&delegate); 218 processor.set_delegate(&delegate);
212 processor.EnqueueAction(&action); 219 processor.EnqueueAction(&action);
213 220
214 g_timeout_add(0, &StartProcessorInRunLoop, &processor); 221 g_timeout_add(0, &StartProcessorInRunLoop, &processor);
215 g_main_loop_run(loop); 222 g_main_loop_run(loop);
216 g_main_loop_unref(loop); 223 g_main_loop_unref(loop);
217 if (out_post_data) 224 if (out_post_data)
218 *out_post_data = fetcher->post_data(); 225 *out_post_data = fetcher->post_data();
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 OmahaEvent::kTypeUpdateComplete, 576 OmahaEvent::kTypeUpdateComplete,
570 OmahaEvent::kResultSuccessReboot); 577 OmahaEvent::kResultSuccessReboot);
571 EXPECT_NE(post_str.find(prev_version_event), string::npos); 578 EXPECT_NE(post_str.find(prev_version_event), string::npos);
572 } 579 }
573 580
574 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) { 581 TEST(OmahaRequestActionTest, FormatSuccessEventOutputTest) {
575 vector<char> post_data; 582 vector<char> post_data;
576 TestEvent(kDefaultTestParams, 583 TestEvent(kDefaultTestParams,
577 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted), 584 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted),
578 "invalid xml>", 585 "invalid xml>",
579 &post_data); 586 &post_data,
587 200);
580 // convert post_data to string 588 // convert post_data to string
581 string post_str(&post_data[0], post_data.size()); 589 string post_str(&post_data[0], post_data.size());
582 string expected_event = StringPrintf( 590 string expected_event = StringPrintf(
583 " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n", 591 " <o:event eventtype=\"%d\" eventresult=\"%d\"></o:event>\n",
584 OmahaEvent::kTypeUpdateDownloadStarted, 592 OmahaEvent::kTypeUpdateDownloadStarted,
585 OmahaEvent::kResultSuccess); 593 OmahaEvent::kResultSuccess);
586 EXPECT_NE(post_str.find(expected_event), string::npos); 594 EXPECT_NE(post_str.find(expected_event), string::npos);
587 EXPECT_EQ(post_str.find("o:ping"), string::npos); 595 EXPECT_EQ(post_str.find("o:ping"), string::npos);
588 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); 596 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos);
589 } 597 }
590 598
591 TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) { 599 TEST(OmahaRequestActionTest, FormatErrorEventOutputTest) {
592 vector<char> post_data; 600 vector<char> post_data;
593 TestEvent(kDefaultTestParams, 601 TestEvent(kDefaultTestParams,
594 new OmahaEvent(OmahaEvent::kTypeDownloadComplete, 602 new OmahaEvent(OmahaEvent::kTypeDownloadComplete,
595 OmahaEvent::kResultError, 603 OmahaEvent::kResultError,
596 kActionCodeError), 604 kActionCodeError),
597 "invalid xml>", 605 "invalid xml>",
598 &post_data); 606 &post_data,
607 200);
599 // convert post_data to string 608 // convert post_data to string
600 string post_str(&post_data[0], post_data.size()); 609 string post_str(&post_data[0], post_data.size());
601 string expected_event = StringPrintf( 610 string expected_event = StringPrintf(
602 " <o:event eventtype=\"%d\" eventresult=\"%d\" " 611 " <o:event eventtype=\"%d\" eventresult=\"%d\" "
603 "errorcode=\"%d\"></o:event>\n", 612 "errorcode=\"%d\"></o:event>\n",
604 OmahaEvent::kTypeDownloadComplete, 613 OmahaEvent::kTypeDownloadComplete,
605 OmahaEvent::kResultError, 614 OmahaEvent::kResultError,
606 kActionCodeError); 615 kActionCodeError);
607 EXPECT_NE(post_str.find(expected_event), string::npos); 616 EXPECT_NE(post_str.find(expected_event), string::npos);
608 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); 617 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos);
609 } 618 }
610 619
611 TEST(OmahaRequestActionTest, FormatEventOutputTest) { 620 TEST(OmahaRequestActionTest, FormatEventOutputTest) {
612 vector<char> post_data; 621 vector<char> post_data;
613 TestEvent(kDefaultTestParams, 622 TestEvent(kDefaultTestParams,
614 new OmahaEvent(OmahaEvent::kTypeDownloadComplete, 623 new OmahaEvent(OmahaEvent::kTypeDownloadComplete,
615 OmahaEvent::kResultError, 624 OmahaEvent::kResultError,
616 kActionCodeError), 625 kActionCodeError),
617 "invalid xml>", 626 "invalid xml>",
618 &post_data); 627 &post_data,
628 200);
619 // convert post_data to string 629 // convert post_data to string
620 string post_str(&post_data[0], post_data.size()); 630 string post_str(&post_data[0], post_data.size());
621 string expected_event = StringPrintf( 631 string expected_event = StringPrintf(
622 " <o:event eventtype=\"%d\" eventresult=\"%d\" " 632 " <o:event eventtype=\"%d\" eventresult=\"%d\" "
623 "errorcode=\"%d\"></o:event>\n", 633 "errorcode=\"%d\"></o:event>\n",
624 OmahaEvent::kTypeDownloadComplete, 634 OmahaEvent::kTypeDownloadComplete,
625 OmahaEvent::kResultError, 635 OmahaEvent::kResultError,
626 kActionCodeError); 636 kActionCodeError);
627 EXPECT_NE(post_str.find(expected_event), string::npos); 637 EXPECT_NE(post_str.find(expected_event), string::npos);
628 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos); 638 EXPECT_EQ(post_str.find("o:updatecheck"), string::npos);
629 } 639 }
630 640
641 TEST(OmahaRequestActionTest, EventFailureTest) {
642 vector<char> post_data;
643 TestEvent(kDefaultTestParams,
644 new OmahaEvent(OmahaEvent::kTypeUpdateDownloadStarted),
645 "foo",
646 NULL,
647 500);
648 }
649
631 TEST(OmahaRequestActionTest, IsEventTest) { 650 TEST(OmahaRequestActionTest, IsEventTest) {
632 string http_response("doesn't matter"); 651 string http_response("doesn't matter");
633 NiceMock<PrefsMock> prefs; 652 NiceMock<PrefsMock> prefs;
634 OmahaRequestAction update_check_action( 653 OmahaRequestAction update_check_action(
635 &prefs, 654 &prefs,
636 kDefaultTestParams, 655 kDefaultTestParams,
637 NULL, 656 NULL,
638 new MockHttpFetcher(http_response.data(), 657 new MockHttpFetcher(http_response.data(),
639 http_response.size(), 658 http_response.size(),
640 NULL)); 659 NULL));
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 "", 942 "",
924 1500, 943 1500,
925 static_cast<ActionExitCode>( 944 static_cast<ActionExitCode>(
926 kActionCodeOmahaRequestHTTPResponseBase + 999), 945 kActionCodeOmahaRequestHTTPResponseBase + 999),
927 &response, 946 &response,
928 NULL)); 947 NULL));
929 EXPECT_FALSE(response.update_exists); 948 EXPECT_FALSE(response.update_exists);
930 } 949 }
931 950
932 } // namespace chromeos_update_engine 951 } // namespace chromeos_update_engine
OLDNEW
« omaha_request_action.cc ('K') | « omaha_request_action.cc ('k') | update_attempter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698