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

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: rebase to latest Created 6 years, 7 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
29 KeyedService* CreateFeedbackUploaderService(content::BrowserContext* context) { 33 KeyedService* CreateFeedbackUploaderService(content::BrowserContext* context) {
30 return new feedback::FeedbackUploaderChrome( 34 return new feedback::FeedbackUploaderChrome(context);
31 Profile::FromBrowserContext(context));
32 } 35 }
33 36
34 } // namespace 37 } // namespace
35 38
36 namespace feedback { 39 namespace feedback {
37 40
38 class FeedbackUploaderTest : public testing::Test { 41 class FeedbackUploaderTest : public testing::Test {
39 protected: 42 protected:
40 FeedbackUploaderTest() 43 FeedbackUploaderTest()
41 : ui_thread_(content::BrowserThread::UI, &message_loop_), 44 : ui_thread_(content::BrowserThread::UI, &message_loop_),
42 profile_(new TestingProfile()), 45 context_(new content::TestBrowserContext()),
43 dispatched_reports_count_(0), 46 dispatched_reports_count_(0),
44 expected_reports_(0) { 47 expected_reports_(0) {
48 user_prefs::UserPrefs::Set(context_.get(), new TestingPrefServiceSimple());
45 FeedbackUploaderFactory::GetInstance()->SetTestingFactory( 49 FeedbackUploaderFactory::GetInstance()->SetTestingFactory(
46 profile_.get(), &CreateFeedbackUploaderService); 50 context_.get(), &CreateFeedbackUploaderService);
47 51
48 uploader_ = FeedbackUploaderFactory::GetForBrowserContext(profile_.get()); 52 uploader_ = FeedbackUploaderFactory::GetForBrowserContext(context_.get());
49 uploader_->setup_for_test( 53 uploader_->setup_for_test(
50 base::Bind(&FeedbackUploaderTest::MockDispatchReport, 54 base::Bind(&FeedbackUploaderTest::MockDispatchReport,
51 base::Unretained(this)), 55 base::Unretained(this)),
52 kRetryDelayForTest); 56 kRetryDelayForTest);
53 } 57 }
54 58
55 virtual ~FeedbackUploaderTest() { 59 virtual ~FeedbackUploaderTest() {
56 FeedbackUploaderFactory::GetInstance()->SetTestingFactory( 60 FeedbackUploaderFactory::GetInstance()->SetTestingFactory(
57 profile_.get(), NULL); 61 context_.get(), NULL);
58 } 62 }
59 63
60 void QueueReport(const std::string& data) { 64 void QueueReport(const std::string& data) {
61 uploader_->QueueReport(data); 65 uploader_->QueueReport(data);
62 } 66 }
63 67
64 void ReportFailure(const std::string& data) { 68 void ReportFailure(const std::string& data) {
65 uploader_->RetryReport(data); 69 uploader_->RetryReport(data);
66 } 70 }
67 71
(...skipping 22 matching lines...) Expand all
90 void RunMessageLoop() { 94 void RunMessageLoop() {
91 if (ProcessingComplete()) 95 if (ProcessingComplete())
92 return; 96 return;
93 run_loop_.reset(new base::RunLoop()); 97 run_loop_.reset(new base::RunLoop());
94 run_loop_->Run(); 98 run_loop_->Run();
95 } 99 }
96 100
97 base::MessageLoop message_loop_; 101 base::MessageLoop message_loop_;
98 scoped_ptr<base::RunLoop> run_loop_; 102 scoped_ptr<base::RunLoop> run_loop_;
99 content::TestBrowserThread ui_thread_; 103 content::TestBrowserThread ui_thread_;
100 scoped_ptr<TestingProfile> profile_; 104 scoped_ptr<content::TestBrowserContext> context_;
101 105
102 FeedbackUploader* uploader_; 106 FeedbackUploader* uploader_;
103 107
104 std::map<std::string, unsigned int> dispatched_reports_; 108 std::map<std::string, unsigned int> dispatched_reports_;
105 size_t dispatched_reports_count_; 109 size_t dispatched_reports_count_;
106 size_t expected_reports_; 110 size_t expected_reports_;
107 }; 111 };
108 112
109 #if defined(OS_LINUX) || defined(OS_MACOSX) 113 #if defined(OS_LINUX) || defined(OS_MACOSX)
110 #define MAYBE_QueueMultiple QueueMultiple 114 #define MAYBE_QueueMultiple QueueMultiple
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 153
150 EXPECT_EQ(dispatched_reports_.size(), 5u); 154 EXPECT_EQ(dispatched_reports_.size(), 5u);
151 EXPECT_EQ(dispatched_reports_[kReportOne], 1u); 155 EXPECT_EQ(dispatched_reports_[kReportOne], 1u);
152 EXPECT_EQ(dispatched_reports_[kReportTwo], 2u); 156 EXPECT_EQ(dispatched_reports_[kReportTwo], 2u);
153 EXPECT_EQ(dispatched_reports_[kReportThree], 2u); 157 EXPECT_EQ(dispatched_reports_[kReportThree], 2u);
154 EXPECT_EQ(dispatched_reports_[kReportFour], 1u); 158 EXPECT_EQ(dispatched_reports_[kReportFour], 1u);
155 EXPECT_EQ(dispatched_reports_[kReportFive], 1u); 159 EXPECT_EQ(dispatched_reports_[kReportFive], 1u);
156 } 160 }
157 161
158 } // namespace feedback 162 } // namespace feedback
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698