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_data.h" | 5 #include "components/feedback/feedback_data.h" |
6 | 6 |
| 7 #include <memory> |
7 #include <set> | 8 #include <set> |
8 #include <utility> | 9 #include <utility> |
9 | 10 |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/ptr_util.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
13 #include "components/feedback/feedback_uploader.h" | 14 #include "components/feedback/feedback_uploader.h" |
14 #include "components/feedback/feedback_uploader_factory.h" | 15 #include "components/feedback/feedback_uploader_factory.h" |
15 #include "components/keyed_service/core/keyed_service.h" | 16 #include "components/keyed_service/core/keyed_service.h" |
16 #include "components/prefs/testing_pref_service.h" | 17 #include "components/prefs/testing_pref_service.h" |
17 #include "components/user_prefs/user_prefs.h" | 18 #include "components/user_prefs/user_prefs.h" |
18 #include "content/public/test/test_browser_context.h" | 19 #include "content/public/test/test_browser_context.h" |
19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 12 matching lines...) Expand all Loading... |
33 | 34 |
34 class MockUploader : public feedback::FeedbackUploader, public KeyedService { | 35 class MockUploader : public feedback::FeedbackUploader, public KeyedService { |
35 public: | 36 public: |
36 MockUploader(content::BrowserContext* context) | 37 MockUploader(content::BrowserContext* context) |
37 : FeedbackUploader(context ? context->GetPath() : base::FilePath(), | 38 : FeedbackUploader(context ? context->GetPath() : base::FilePath(), |
38 BrowserThread::GetBlockingPool()) {} | 39 BrowserThread::GetBlockingPool()) {} |
39 | 40 |
40 MOCK_METHOD1(DispatchReport, void(const std::string&)); | 41 MOCK_METHOD1(DispatchReport, void(const std::string&)); |
41 }; | 42 }; |
42 | 43 |
43 scoped_ptr<KeyedService> CreateFeedbackUploaderService( | 44 std::unique_ptr<KeyedService> CreateFeedbackUploaderService( |
44 content::BrowserContext* context) { | 45 content::BrowserContext* context) { |
45 scoped_ptr<MockUploader> uploader(new MockUploader(context)); | 46 std::unique_ptr<MockUploader> uploader(new MockUploader(context)); |
46 EXPECT_CALL(*uploader, DispatchReport(testing::_)).Times(1); | 47 EXPECT_CALL(*uploader, DispatchReport(testing::_)).Times(1); |
47 return std::move(uploader); | 48 return std::move(uploader); |
48 } | 49 } |
49 | 50 |
50 scoped_ptr<std::string> MakeScoped(const char* str) { | 51 std::unique_ptr<std::string> MakeScoped(const char* str) { |
51 return scoped_ptr<std::string>(new std::string(str)); | 52 return base::WrapUnique(new std::string(str)); |
52 } | 53 } |
53 | 54 |
54 } // namespace | 55 } // namespace |
55 | 56 |
56 namespace feedback { | 57 namespace feedback { |
57 | 58 |
58 class FeedbackDataTest : public testing::Test { | 59 class FeedbackDataTest : public testing::Test { |
59 protected: | 60 protected: |
60 FeedbackDataTest() | 61 FeedbackDataTest() |
61 : context_(new content::TestBrowserContext()), | 62 : context_(new content::TestBrowserContext()), |
(...skipping 24 matching lines...) Expand all Loading... |
86 run_loop_.reset(new base::RunLoop()); | 87 run_loop_.reset(new base::RunLoop()); |
87 quit_closure_ = run_loop_->QuitClosure(); | 88 quit_closure_ = run_loop_->QuitClosure(); |
88 run_loop_->Run(); | 89 run_loop_->Run(); |
89 } | 90 } |
90 | 91 |
91 void set_send_report_callback(scoped_refptr<FeedbackData> data) { | 92 void set_send_report_callback(scoped_refptr<FeedbackData> data) { |
92 quit_closure_.Run(); | 93 quit_closure_.Run(); |
93 } | 94 } |
94 | 95 |
95 base::Closure quit_closure_; | 96 base::Closure quit_closure_; |
96 scoped_ptr<base::RunLoop> run_loop_; | 97 std::unique_ptr<base::RunLoop> run_loop_; |
97 scoped_ptr<content::TestBrowserContext> context_; | 98 std::unique_ptr<content::TestBrowserContext> context_; |
98 scoped_ptr<PrefService> prefs_; | 99 std::unique_ptr<PrefService> prefs_; |
99 scoped_refptr<FeedbackData> data_; | 100 scoped_refptr<FeedbackData> data_; |
100 base::MessageLoop message_loop_; | 101 base::MessageLoop message_loop_; |
101 content::TestBrowserThread ui_thread_; | 102 content::TestBrowserThread ui_thread_; |
102 }; | 103 }; |
103 | 104 |
104 TEST_F(FeedbackDataTest, ReportSending) { | 105 TEST_F(FeedbackDataTest, ReportSending) { |
105 data_->SetAndCompressHistograms(MakeScoped(kHistograms)); | 106 data_->SetAndCompressHistograms(MakeScoped(kHistograms)); |
106 data_->set_image(MakeScoped(kImageData)); | 107 data_->set_image(MakeScoped(kImageData)); |
107 data_->AttachAndCompressFileData(MakeScoped(kFileData)); | 108 data_->AttachAndCompressFileData(MakeScoped(kFileData)); |
108 Send(); | 109 Send(); |
109 RunMessageLoop(); | 110 RunMessageLoop(); |
110 EXPECT_TRUE(data_->IsDataComplete()); | 111 EXPECT_TRUE(data_->IsDataComplete()); |
111 } | 112 } |
112 | 113 |
113 } // namespace feedback | 114 } // namespace feedback |
OLD | NEW |