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 <set> | 7 #include <set> |
8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/testing_pref_service.h" | 11 #include "base/prefs/testing_pref_service.h" |
11 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
12 #include "components/feedback/feedback_uploader.h" | 13 #include "components/feedback/feedback_uploader.h" |
13 #include "components/feedback/feedback_uploader_factory.h" | 14 #include "components/feedback/feedback_uploader_factory.h" |
14 #include "components/keyed_service/core/keyed_service.h" | 15 #include "components/keyed_service/core/keyed_service.h" |
15 #include "components/user_prefs/user_prefs.h" | 16 #include "components/user_prefs/user_prefs.h" |
16 #include "content/public/test/test_browser_context.h" | 17 #include "content/public/test/test_browser_context.h" |
17 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
18 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 12 matching lines...) Expand all Loading... |
31 | 32 |
32 class MockUploader : public feedback::FeedbackUploader, public KeyedService { | 33 class MockUploader : public feedback::FeedbackUploader, public KeyedService { |
33 public: | 34 public: |
34 MockUploader(content::BrowserContext* context) | 35 MockUploader(content::BrowserContext* context) |
35 : FeedbackUploader(context ? context->GetPath() : base::FilePath(), | 36 : FeedbackUploader(context ? context->GetPath() : base::FilePath(), |
36 BrowserThread::GetBlockingPool()) {} | 37 BrowserThread::GetBlockingPool()) {} |
37 | 38 |
38 MOCK_METHOD1(DispatchReport, void(const std::string&)); | 39 MOCK_METHOD1(DispatchReport, void(const std::string&)); |
39 }; | 40 }; |
40 | 41 |
41 MockUploader *g_uploader; | 42 scoped_ptr<KeyedService> CreateFeedbackUploaderService( |
42 | 43 content::BrowserContext* context) { |
43 KeyedService* CreateFeedbackUploaderService(content::BrowserContext* context) { | 44 scoped_ptr<MockUploader> uploader(new MockUploader(context)); |
44 if (!g_uploader) | 45 EXPECT_CALL(*uploader, DispatchReport(testing::_)).Times(1); |
45 g_uploader = new MockUploader(context); | 46 return uploader.Pass(); |
46 EXPECT_CALL(*g_uploader, DispatchReport(testing::_)).Times(1); | |
47 return g_uploader; | |
48 } | 47 } |
49 | 48 |
50 scoped_ptr<std::string> MakeScoped(const char* str) { | 49 scoped_ptr<std::string> MakeScoped(const char* str) { |
51 return scoped_ptr<std::string>(new std::string(str)); | 50 return scoped_ptr<std::string>(new std::string(str)); |
52 } | 51 } |
53 | 52 |
54 } // namespace | 53 } // namespace |
55 | 54 |
56 namespace feedback { | 55 namespace feedback { |
57 | 56 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 content::TestBrowserThread ui_thread_; | 100 content::TestBrowserThread ui_thread_; |
102 }; | 101 }; |
103 | 102 |
104 TEST_F(FeedbackDataTest, ReportSending) { | 103 TEST_F(FeedbackDataTest, ReportSending) { |
105 data_->SetAndCompressHistograms(MakeScoped(kHistograms).Pass()); | 104 data_->SetAndCompressHistograms(MakeScoped(kHistograms).Pass()); |
106 data_->set_image(MakeScoped(kImageData).Pass()); | 105 data_->set_image(MakeScoped(kImageData).Pass()); |
107 data_->AttachAndCompressFileData(MakeScoped(kFileData).Pass()); | 106 data_->AttachAndCompressFileData(MakeScoped(kFileData).Pass()); |
108 Send(); | 107 Send(); |
109 RunMessageLoop(); | 108 RunMessageLoop(); |
110 EXPECT_TRUE(data_->IsDataComplete()); | 109 EXPECT_TRUE(data_->IsDataComplete()); |
111 delete g_uploader; | |
112 g_uploader = NULL; | |
113 } | 110 } |
114 | 111 |
115 } // namespace feedback | 112 } // namespace feedback |
OLD | NEW |