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

Side by Side Diff: chrome/browser/feedback/feedback_uploader_unittest.cc

Issue 141433011: Cache feedback reports to disk in case of send failure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium 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 "chrome/browser/feedback/feedback_uploader.h" 5 #include "chrome/browser/feedback/feedback_uploader.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/threading/platform_thread.h"
10 #include "chrome/browser/feedback/feedback_uploader_factory.h" 11 #include "chrome/browser/feedback/feedback_uploader_factory.h"
11 #include "chrome/test/base/testing_profile.h" 12 #include "chrome/test/base/testing_profile.h"
12 #include "content/public/test/test_browser_thread.h" 13 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 15
15 namespace { 16 namespace {
16 17
17 const char kReportOne[] = "one"; 18 const char kReportOne[] = "one";
18 const char kReportTwo[] = "two"; 19 const char kReportTwo[] = "two";
19 const char kReportThree[] = "three"; 20 const char kReportThree[] = "three";
(...skipping 27 matching lines...) Expand all
47 base::Unretained(this)), 48 base::Unretained(this)),
48 kRetryDelayForTest); 49 kRetryDelayForTest);
49 } 50 }
50 51
51 virtual ~FeedbackUploaderTest() { 52 virtual ~FeedbackUploaderTest() {
52 FeedbackUploaderFactory::GetInstance()->SetTestingFactory( 53 FeedbackUploaderFactory::GetInstance()->SetTestingFactory(
53 profile_.get(), NULL); 54 profile_.get(), NULL);
54 } 55 }
55 56
56 void QueueReport(const std::string& data) { 57 void QueueReport(const std::string& data) {
57 uploader_->QueueReport(make_scoped_ptr(new std::string(data))); 58 uploader_->QueueReport(data);
59 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
Lei Zhang 2014/02/01 01:13:45 No, Please don't do this. See ToTT episode 303.
Lei Zhang 2014/02/01 01:37:22 If you explain what you are waiting for, I might b
rkc 2014/02/03 22:13:11 This was to ensure that the timestamps of each rep
rkc 2014/02/03 22:13:11 This wasn't for 'timing' anything, it was to ensur
Lei Zhang 2014/02/03 22:29:41 Ok, if you really need to do it, please add a comm
rkc 2014/02/03 22:41:26 Don't need to do it anymore since I changed the ch
58 } 60 }
59 61
60 void ReportFailure(const std::string& data) { 62 void ReportFailure(const std::string& data) {
61 uploader_->RetryReport(make_scoped_ptr(new std::string(data))); 63 uploader_->RetryReport(data);
64 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
62 } 65 }
63 66
64 void MockDispatchReport(scoped_ptr<std::string> report_data) { 67 void MockDispatchReport(const std::string& report_data) {
65 dispatched_reports_.push_back(*report_data.get()); 68 dispatched_reports_.push_back(report_data);
66 69
67 // Dispatch will always update the timer, whether successful or not, 70 // Dispatch will always update the timer, whether successful or not,
68 // simulate the same behavior. 71 // simulate the same behavior.
69 uploader_->UpdateUploadTimer(); 72 uploader_->UpdateUploadTimer();
70 73
71 if (dispatched_reports_.size() >= expected_reports_) { 74 if (dispatched_reports_.size() >= expected_reports_) {
72 if (run_loop_.get()) 75 if (run_loop_.get())
73 run_loop_->Quit(); 76 run_loop_->Quit();
74 } 77 }
75 } 78 }
76 79
77 void RunMessageLoop() { 80 void RunMessageLoop() {
78 run_loop_.reset(new base::RunLoop()); 81 run_loop_.reset(new base::RunLoop());
79 run_loop_->Run(); 82 run_loop_->Run();
80 } 83 }
81 84
82 base::MessageLoop message_loop_; 85 base::MessageLoop message_loop_;
83 scoped_ptr<base::RunLoop> run_loop_; 86 scoped_ptr<base::RunLoop> run_loop_;
84 content::TestBrowserThread ui_thread_; 87 content::TestBrowserThread ui_thread_;
85 scoped_ptr<TestingProfile> profile_; 88 scoped_ptr<TestingProfile> profile_;
86 89
87 FeedbackUploader* uploader_; 90 FeedbackUploader* uploader_;
88 91
89 std::vector<std::string> dispatched_reports_; 92 std::vector<std::string> dispatched_reports_;
90 size_t expected_reports_; 93 size_t expected_reports_;
91 }; 94 };
92 95
93 TEST_F(FeedbackUploaderTest, QueueMultiple) { 96 #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
97 #define MAYBE_QueueMultiple QueueMultiple
98 #else
99 // crbug.com/330547
100 #define MAYBE_QueueMultiple DISABLED_QueueMultiple
101 #endif
102 TEST_F(FeedbackUploaderTest, MAYBE_QueueMultiple) {
94 dispatched_reports_.clear(); 103 dispatched_reports_.clear();
95 QueueReport(kReportOne); 104 QueueReport(kReportOne);
96 QueueReport(kReportTwo); 105 QueueReport(kReportTwo);
97 QueueReport(kReportThree); 106 QueueReport(kReportThree);
98 QueueReport(kReportFour); 107 QueueReport(kReportFour);
99 108
100 EXPECT_EQ(dispatched_reports_.size(), 4u); 109 EXPECT_EQ(dispatched_reports_.size(), 4u);
101 EXPECT_EQ(dispatched_reports_[0], kReportOne); 110 EXPECT_EQ(dispatched_reports_[0], kReportOne);
102 EXPECT_EQ(dispatched_reports_[1], kReportTwo); 111 EXPECT_EQ(dispatched_reports_[1], kReportTwo);
103 EXPECT_EQ(dispatched_reports_[2], kReportThree); 112 EXPECT_EQ(dispatched_reports_[2], kReportThree);
104 EXPECT_EQ(dispatched_reports_[3], kReportFour); 113 EXPECT_EQ(dispatched_reports_[3], kReportFour);
105 } 114 }
106 115
107 #if defined(OS_WIN) 116 #if defined(OS_LINUX) || defined(OS_CHROMEOS) || defined(OS_MACOSX)
117 #define MAYBE_QueueMultipleWithFailures QueueMultipleWithFailures
118 #else
108 // crbug.com/330547 119 // crbug.com/330547
109 #define MAYBE_QueueMultipleWithFailures DISABLED_QueueMultipleWithFailures 120 #define MAYBE_QueueMultipleWithFailures DISABLED_QueueMultipleWithFailures
110 #else
111 #define MAYBE_QueueMultipleWithFailures QueueMultipleWithFailures
112 #endif 121 #endif
113 TEST_F(FeedbackUploaderTest, MAYBE_QueueMultipleWithFailures) { 122 TEST_F(FeedbackUploaderTest, MAYBE_QueueMultipleWithFailures) {
114 dispatched_reports_.clear(); 123 dispatched_reports_.clear();
115 QueueReport(kReportOne); 124 QueueReport(kReportOne);
116 QueueReport(kReportTwo); 125 QueueReport(kReportTwo);
117 QueueReport(kReportThree); 126 QueueReport(kReportThree);
118 QueueReport(kReportFour); 127 QueueReport(kReportFour);
119 128
120 ReportFailure(kReportThree); 129 ReportFailure(kReportThree);
121 ReportFailure(kReportTwo); 130 ReportFailure(kReportTwo);
122 QueueReport(kReportFive); 131 QueueReport(kReportFive);
123 132
124 expected_reports_ = 7; 133 expected_reports_ = 7;
125 RunMessageLoop(); 134 RunMessageLoop();
126 135
127 EXPECT_EQ(dispatched_reports_.size(), 7u); 136 EXPECT_EQ(dispatched_reports_.size(), 7u);
128 EXPECT_EQ(dispatched_reports_[0], kReportOne); 137 EXPECT_EQ(dispatched_reports_[0], kReportOne);
129 EXPECT_EQ(dispatched_reports_[1], kReportTwo); 138 EXPECT_EQ(dispatched_reports_[1], kReportTwo);
130 EXPECT_EQ(dispatched_reports_[2], kReportThree); 139 EXPECT_EQ(dispatched_reports_[2], kReportThree);
131 EXPECT_EQ(dispatched_reports_[3], kReportFour); 140 EXPECT_EQ(dispatched_reports_[3], kReportFour);
132 EXPECT_EQ(dispatched_reports_[4], kReportFive); 141 EXPECT_EQ(dispatched_reports_[4], kReportFive);
133 EXPECT_EQ(dispatched_reports_[5], kReportThree); 142 EXPECT_EQ(dispatched_reports_[5], kReportThree);
134 EXPECT_EQ(dispatched_reports_[6], kReportTwo); 143 EXPECT_EQ(dispatched_reports_[6], kReportTwo);
135 } 144 }
136 145
137 } // namespace feedback 146 } // namespace feedback
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698