| 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 <set> | 10 #include <set> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 17 #include "components/feedback/feedback_uploader_chrome.h" | 18 #include "components/feedback/feedback_uploader_chrome.h" |
| 18 #include "components/feedback/feedback_uploader_factory.h" | 19 #include "components/feedback/feedback_uploader_factory.h" |
| 19 #include "components/pref_registry/testing_pref_service_syncable.h" | 20 #include "components/pref_registry/testing_pref_service_syncable.h" |
| 20 #include "components/user_prefs/user_prefs.h" | 21 #include "components/user_prefs/user_prefs.h" |
| 21 #include "content/public/test/test_browser_context.h" | 22 #include "content/public/test/test_browser_context.h" |
| 22 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
| 23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 const char kReportOne[] = "one"; | 29 const char kReportOne[] = "one"; |
| 29 const char kReportTwo[] = "two"; | 30 const char kReportTwo[] = "two"; |
| 30 const char kReportThree[] = "three"; | 31 const char kReportThree[] = "three"; |
| 31 const char kReportFour[] = "four"; | 32 const char kReportFour[] = "four"; |
| 32 const char kReportFive[] = "five"; | 33 const char kReportFive[] = "five"; |
| 33 | 34 |
| 34 const base::TimeDelta kRetryDelayForTest = | 35 const base::TimeDelta kRetryDelayForTest = |
| 35 base::TimeDelta::FromMilliseconds(100); | 36 base::TimeDelta::FromMilliseconds(100); |
| 36 | 37 |
| 37 scoped_ptr<KeyedService> CreateFeedbackUploaderService( | 38 std::unique_ptr<KeyedService> CreateFeedbackUploaderService( |
| 38 content::BrowserContext* context) { | 39 content::BrowserContext* context) { |
| 39 return make_scoped_ptr(new feedback::FeedbackUploaderChrome(context)); | 40 return base::WrapUnique(new feedback::FeedbackUploaderChrome(context)); |
| 40 } | 41 } |
| 41 | 42 |
| 42 } // namespace | 43 } // namespace |
| 43 | 44 |
| 44 namespace feedback { | 45 namespace feedback { |
| 45 | 46 |
| 46 class FeedbackUploaderTest : public testing::Test { | 47 class FeedbackUploaderTest : public testing::Test { |
| 47 protected: | 48 protected: |
| 48 FeedbackUploaderTest() | 49 FeedbackUploaderTest() |
| 49 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 50 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 } | 99 } |
| 99 | 100 |
| 100 void RunMessageLoop() { | 101 void RunMessageLoop() { |
| 101 if (ProcessingComplete()) | 102 if (ProcessingComplete()) |
| 102 return; | 103 return; |
| 103 run_loop_.reset(new base::RunLoop()); | 104 run_loop_.reset(new base::RunLoop()); |
| 104 run_loop_->Run(); | 105 run_loop_->Run(); |
| 105 } | 106 } |
| 106 | 107 |
| 107 base::MessageLoop message_loop_; | 108 base::MessageLoop message_loop_; |
| 108 scoped_ptr<base::RunLoop> run_loop_; | 109 std::unique_ptr<base::RunLoop> run_loop_; |
| 109 content::TestBrowserThread ui_thread_; | 110 content::TestBrowserThread ui_thread_; |
| 110 scoped_ptr<content::TestBrowserContext> context_; | 111 std::unique_ptr<content::TestBrowserContext> context_; |
| 111 scoped_ptr<PrefService> prefs_; | 112 std::unique_ptr<PrefService> prefs_; |
| 112 | 113 |
| 113 FeedbackUploader* uploader_; | 114 FeedbackUploader* uploader_; |
| 114 | 115 |
| 115 std::map<std::string, unsigned int> dispatched_reports_; | 116 std::map<std::string, unsigned int> dispatched_reports_; |
| 116 size_t dispatched_reports_count_; | 117 size_t dispatched_reports_count_; |
| 117 size_t expected_reports_; | 118 size_t expected_reports_; |
| 118 }; | 119 }; |
| 119 | 120 |
| 120 #if defined(OS_LINUX) || defined(OS_MACOSX) | 121 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 121 #define MAYBE_QueueMultiple QueueMultiple | 122 #define MAYBE_QueueMultiple QueueMultiple |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 161 |
| 161 EXPECT_EQ(dispatched_reports_.size(), 5u); | 162 EXPECT_EQ(dispatched_reports_.size(), 5u); |
| 162 EXPECT_EQ(dispatched_reports_[kReportOne], 1u); | 163 EXPECT_EQ(dispatched_reports_[kReportOne], 1u); |
| 163 EXPECT_EQ(dispatched_reports_[kReportTwo], 2u); | 164 EXPECT_EQ(dispatched_reports_[kReportTwo], 2u); |
| 164 EXPECT_EQ(dispatched_reports_[kReportThree], 2u); | 165 EXPECT_EQ(dispatched_reports_[kReportThree], 2u); |
| 165 EXPECT_EQ(dispatched_reports_[kReportFour], 1u); | 166 EXPECT_EQ(dispatched_reports_[kReportFour], 1u); |
| 166 EXPECT_EQ(dispatched_reports_[kReportFive], 1u); | 167 EXPECT_EQ(dispatched_reports_[kReportFive], 1u); |
| 167 } | 168 } |
| 168 | 169 |
| 169 } // namespace feedback | 170 } // namespace feedback |
| OLD | NEW |