OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/feedback/feedback_uploader.h" | 5 #include "components/feedback/feedback_uploader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <set> | 10 #include <set> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/message_loop/message_loop.h" | |
15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
16 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
18 #include "components/feedback/feedback_uploader_chrome.h" | 17 #include "components/feedback/feedback_uploader_chrome.h" |
19 #include "components/feedback/feedback_uploader_factory.h" | 18 #include "components/feedback/feedback_uploader_factory.h" |
20 #include "components/sync_preferences/testing_pref_service_syncable.h" | 19 #include "components/sync_preferences/testing_pref_service_syncable.h" |
21 #include "components/user_prefs/user_prefs.h" | 20 #include "components/user_prefs/user_prefs.h" |
22 #include "content/public/test/test_browser_context.h" | 21 #include "content/public/test/test_browser_context.h" |
23 #include "content/public/test/test_browser_thread.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
26 | 25 |
27 namespace { | 26 namespace { |
28 | 27 |
29 const char kReportOne[] = "one"; | 28 const char kReportOne[] = "one"; |
30 const char kReportTwo[] = "two"; | 29 const char kReportTwo[] = "two"; |
31 const char kReportThree[] = "three"; | 30 const char kReportThree[] = "three"; |
32 const char kReportFour[] = "four"; | 31 const char kReportFour[] = "four"; |
33 const char kReportFive[] = "five"; | 32 const char kReportFive[] = "five"; |
34 | 33 |
35 const base::TimeDelta kRetryDelayForTest = | 34 const base::TimeDelta kRetryDelayForTest = |
36 base::TimeDelta::FromMilliseconds(100); | 35 base::TimeDelta::FromMilliseconds(100); |
37 | 36 |
38 std::unique_ptr<KeyedService> CreateFeedbackUploaderService( | 37 std::unique_ptr<KeyedService> CreateFeedbackUploaderService( |
39 content::BrowserContext* context) { | 38 content::BrowserContext* context) { |
40 return base::MakeUnique<feedback::FeedbackUploaderChrome>(context); | 39 return base::MakeUnique<feedback::FeedbackUploaderChrome>(context); |
41 } | 40 } |
42 | 41 |
43 } // namespace | 42 } // namespace |
44 | 43 |
45 namespace feedback { | 44 namespace feedback { |
46 | 45 |
47 class FeedbackUploaderTest : public testing::Test { | 46 class FeedbackUploaderTest : public testing::Test { |
48 protected: | 47 protected: |
49 FeedbackUploaderTest() | 48 FeedbackUploaderTest() |
50 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 49 : context_(new content::TestBrowserContext()), |
51 context_(new content::TestBrowserContext()), | |
52 prefs_(new sync_preferences::TestingPrefServiceSyncable()), | 50 prefs_(new sync_preferences::TestingPrefServiceSyncable()), |
53 dispatched_reports_count_(0), | 51 dispatched_reports_count_(0), |
54 expected_reports_(0) { | 52 expected_reports_(0) { |
55 user_prefs::UserPrefs::Set(context_.get(), prefs_.get()); | 53 user_prefs::UserPrefs::Set(context_.get(), prefs_.get()); |
56 FeedbackUploaderFactory::GetInstance()->SetTestingFactory( | 54 FeedbackUploaderFactory::GetInstance()->SetTestingFactory( |
57 context_.get(), &CreateFeedbackUploaderService); | 55 context_.get(), &CreateFeedbackUploaderService); |
58 | 56 |
59 uploader_ = FeedbackUploaderFactory::GetForBrowserContext(context_.get()); | 57 uploader_ = FeedbackUploaderFactory::GetForBrowserContext(context_.get()); |
60 uploader_->setup_for_test( | 58 uploader_->setup_for_test( |
61 base::Bind(&FeedbackUploaderTest::MockDispatchReport, | 59 base::Bind(&FeedbackUploaderTest::MockDispatchReport, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 return (dispatched_reports_count_ >= expected_reports_); | 96 return (dispatched_reports_count_ >= expected_reports_); |
99 } | 97 } |
100 | 98 |
101 void RunMessageLoop() { | 99 void RunMessageLoop() { |
102 if (ProcessingComplete()) | 100 if (ProcessingComplete()) |
103 return; | 101 return; |
104 run_loop_.reset(new base::RunLoop()); | 102 run_loop_.reset(new base::RunLoop()); |
105 run_loop_->Run(); | 103 run_loop_->Run(); |
106 } | 104 } |
107 | 105 |
108 base::MessageLoop message_loop_; | 106 content::TestBrowserThreadBundle test_browser_thread_bundle_; |
109 std::unique_ptr<base::RunLoop> run_loop_; | 107 std::unique_ptr<base::RunLoop> run_loop_; |
110 content::TestBrowserThread ui_thread_; | |
111 std::unique_ptr<content::TestBrowserContext> context_; | 108 std::unique_ptr<content::TestBrowserContext> context_; |
112 std::unique_ptr<PrefService> prefs_; | 109 std::unique_ptr<PrefService> prefs_; |
113 | 110 |
114 FeedbackUploader* uploader_; | 111 FeedbackUploader* uploader_; |
115 | 112 |
116 std::map<std::string, unsigned int> dispatched_reports_; | 113 std::map<std::string, unsigned int> dispatched_reports_; |
117 size_t dispatched_reports_count_; | 114 size_t dispatched_reports_count_; |
118 size_t expected_reports_; | 115 size_t expected_reports_; |
119 }; | 116 }; |
120 | 117 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 158 |
162 EXPECT_EQ(dispatched_reports_.size(), 5u); | 159 EXPECT_EQ(dispatched_reports_.size(), 5u); |
163 EXPECT_EQ(dispatched_reports_[kReportOne], 1u); | 160 EXPECT_EQ(dispatched_reports_[kReportOne], 1u); |
164 EXPECT_EQ(dispatched_reports_[kReportTwo], 2u); | 161 EXPECT_EQ(dispatched_reports_[kReportTwo], 2u); |
165 EXPECT_EQ(dispatched_reports_[kReportThree], 2u); | 162 EXPECT_EQ(dispatched_reports_[kReportThree], 2u); |
166 EXPECT_EQ(dispatched_reports_[kReportFour], 1u); | 163 EXPECT_EQ(dispatched_reports_[kReportFour], 1u); |
167 EXPECT_EQ(dispatched_reports_[kReportFive], 1u); | 164 EXPECT_EQ(dispatched_reports_[kReportFive], 1u); |
168 } | 165 } |
169 | 166 |
170 } // namespace feedback | 167 } // namespace feedback |
OLD | NEW |