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

Side by Side Diff: components/feedback/feedback_uploader_unittest.cc

Issue 225183018: Move feedback files into src/components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix deps, merge gyp targets, sync with latest Created 6 years, 8 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
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 "components/feedback/feedback_uploader.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/testing_pref_service.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "chrome/browser/feedback/feedback_uploader_chrome.h" 13 #include "base/stl_util.h"
13 #include "chrome/browser/feedback/feedback_uploader_factory.h" 14 #include "components/feedback/feedback_uploader_chrome.h"
14 #include "chrome/test/base/testing_profile.h" 15 #include "components/feedback/feedback_uploader_factory.h"
16 #include "components/user_prefs/user_prefs.h"
17 #include "content/public/test/test_browser_context.h"
15 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
19 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
17 21
18 namespace { 22 namespace {
19 23
20 const char kReportOne[] = "one"; 24 const char kReportOne[] = "one";
21 const char kReportTwo[] = "two"; 25 const char kReportTwo[] = "two";
22 const char kReportThree[] = "three"; 26 const char kReportThree[] = "three";
23 const char kReportFour[] = "four"; 27 const char kReportFour[] = "four";
24 const char kReportFive[] = "five"; 28 const char kReportFive[] = "five";
25 29
26 const base::TimeDelta kRetryDelayForTest = 30 const base::TimeDelta kRetryDelayForTest =
27 base::TimeDelta::FromMilliseconds(100); 31 base::TimeDelta::FromMilliseconds(100);
28 32
33 class MockUploader : public feedback::FeedbackUploader, public KeyedService {
34 public:
35 MockUploader(content::BrowserContext* context)
36 : FeedbackUploader(context ? context->GetPath() : base::FilePath(),
37 content::BrowserThread::GetBlockingPool()) {}
38
39 MOCK_METHOD1(DispatchReport, void(const std::string&));
40 };
41
29 KeyedService* CreateFeedbackUploaderService(content::BrowserContext* context) { 42 KeyedService* CreateFeedbackUploaderService(content::BrowserContext* context) {
30 return new feedback::FeedbackUploaderChrome( 43 return new MockUploader(context);
rkc 2014/04/28 22:41:32 Any particular reason we're using a mock uploader
achaulk 2014/04/30 17:12:34 Oh, this is a holdover when when the actual upload
31 Profile::FromBrowserContext(context));
32 } 44 }
33 45
34 } // namespace 46 } // namespace
35 47
36 namespace feedback { 48 namespace feedback {
37 49
38 class FeedbackUploaderTest : public testing::Test { 50 class FeedbackUploaderTest : public testing::Test {
39 protected: 51 protected:
40 FeedbackUploaderTest() 52 FeedbackUploaderTest()
41 : ui_thread_(content::BrowserThread::UI, &message_loop_), 53 : ui_thread_(content::BrowserThread::UI, &message_loop_),
42 profile_(new TestingProfile()), 54 context_(new content::TestBrowserContext()),
43 dispatched_reports_count_(0), 55 dispatched_reports_count_(0),
44 expected_reports_(0) { 56 expected_reports_(0) {
57 user_prefs::UserPrefs::Set(context_.get(), new TestingPrefServiceSimple());
45 FeedbackUploaderFactory::GetInstance()->SetTestingFactory( 58 FeedbackUploaderFactory::GetInstance()->SetTestingFactory(
46 profile_.get(), &CreateFeedbackUploaderService); 59 context_.get(), &CreateFeedbackUploaderService);
47 60
48 uploader_ = FeedbackUploaderFactory::GetForBrowserContext(profile_.get()); 61 uploader_ = FeedbackUploaderFactory::GetForBrowserContext(context_.get());
49 uploader_->setup_for_test( 62 uploader_->setup_for_test(
50 base::Bind(&FeedbackUploaderTest::MockDispatchReport, 63 base::Bind(&FeedbackUploaderTest::MockDispatchReport,
51 base::Unretained(this)), 64 base::Unretained(this)),
52 kRetryDelayForTest); 65 kRetryDelayForTest);
53 } 66 }
54 67
55 virtual ~FeedbackUploaderTest() { 68 virtual ~FeedbackUploaderTest() {
56 FeedbackUploaderFactory::GetInstance()->SetTestingFactory( 69 FeedbackUploaderFactory::GetInstance()->SetTestingFactory(
57 profile_.get(), NULL); 70 context_.get(), NULL);
58 } 71 }
59 72
60 void QueueReport(const std::string& data) { 73 void QueueReport(const std::string& data) {
61 uploader_->QueueReport(data); 74 uploader_->QueueReport(data);
62 } 75 }
63 76
64 void ReportFailure(const std::string& data) { 77 void ReportFailure(const std::string& data) {
65 uploader_->RetryReport(data); 78 uploader_->RetryReport(data);
66 } 79 }
67 80
(...skipping 22 matching lines...) Expand all
90 void RunMessageLoop() { 103 void RunMessageLoop() {
91 if (ProcessingComplete()) 104 if (ProcessingComplete())
92 return; 105 return;
93 run_loop_.reset(new base::RunLoop()); 106 run_loop_.reset(new base::RunLoop());
94 run_loop_->Run(); 107 run_loop_->Run();
95 } 108 }
96 109
97 base::MessageLoop message_loop_; 110 base::MessageLoop message_loop_;
98 scoped_ptr<base::RunLoop> run_loop_; 111 scoped_ptr<base::RunLoop> run_loop_;
99 content::TestBrowserThread ui_thread_; 112 content::TestBrowserThread ui_thread_;
100 scoped_ptr<TestingProfile> profile_; 113 scoped_ptr<content::TestBrowserContext> context_;
101 114
102 FeedbackUploader* uploader_; 115 FeedbackUploader* uploader_;
103 116
104 std::map<std::string, unsigned int> dispatched_reports_; 117 std::map<std::string, unsigned int> dispatched_reports_;
105 size_t dispatched_reports_count_; 118 size_t dispatched_reports_count_;
106 size_t expected_reports_; 119 size_t expected_reports_;
107 }; 120 };
108 121
109 #if defined(OS_LINUX) || defined(OS_MACOSX) 122 #if defined(OS_LINUX) || defined(OS_MACOSX)
110 #define MAYBE_QueueMultiple QueueMultiple 123 #define MAYBE_QueueMultiple QueueMultiple
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 162
150 EXPECT_EQ(dispatched_reports_.size(), 5u); 163 EXPECT_EQ(dispatched_reports_.size(), 5u);
151 EXPECT_EQ(dispatched_reports_[kReportOne], 1u); 164 EXPECT_EQ(dispatched_reports_[kReportOne], 1u);
152 EXPECT_EQ(dispatched_reports_[kReportTwo], 2u); 165 EXPECT_EQ(dispatched_reports_[kReportTwo], 2u);
153 EXPECT_EQ(dispatched_reports_[kReportThree], 2u); 166 EXPECT_EQ(dispatched_reports_[kReportThree], 2u);
154 EXPECT_EQ(dispatched_reports_[kReportFour], 1u); 167 EXPECT_EQ(dispatched_reports_[kReportFour], 1u);
155 EXPECT_EQ(dispatched_reports_[kReportFive], 1u); 168 EXPECT_EQ(dispatched_reports_[kReportFive], 1u);
156 } 169 }
157 170
158 } // namespace feedback 171 } // namespace feedback
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698