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

Side by Side Diff: components/feedback/feedback_data_unittest.cc

Issue 296173003: Refactor FeedbackData and add tests. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add feedback.gypi to OWNERS file Created 6 years, 6 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
« no previous file with comments | « components/feedback/feedback_data.cc ('k') | components/feedback/feedback_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/feedback/feedback_data.h"
6
7 #include <set>
8
9 #include "base/message_loop/message_loop.h"
10 #include "base/prefs/testing_pref_service.h"
11 #include "base/run_loop.h"
12 #include "components/feedback/feedback_uploader.h"
13 #include "components/feedback/feedback_uploader_factory.h"
14 #include "components/keyed_service/core/keyed_service.h"
15 #include "components/user_prefs/user_prefs.h"
16 #include "content/public/test/test_browser_context.h"
17 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 namespace {
22
23 const char kHistograms[] = "";
24 const char kImageData[] = "";
25 const char kFileData[] = "";
26
27 const base::TimeDelta kRetryDelayForTest =
28 base::TimeDelta::FromMilliseconds(100);
29
30 using content::BrowserThread;
31
32 class MockUploader : public feedback::FeedbackUploader, public KeyedService {
33 public:
34 MockUploader(content::BrowserContext* context)
35 : FeedbackUploader(context ? context->GetPath() : base::FilePath(),
36 BrowserThread::GetBlockingPool()) {}
37
38 MOCK_METHOD1(DispatchReport, void(const std::string&));
39 };
40
41 MockUploader *g_uploader;
42
43 KeyedService* CreateFeedbackUploaderService(content::BrowserContext* context) {
44 if (!g_uploader)
45 g_uploader = new MockUploader(context);
46 EXPECT_CALL(*g_uploader, DispatchReport(testing::_)).Times(1);
47 return g_uploader;
48 }
49
50 scoped_ptr<std::string> MakeScoped(const char* str) {
51 return scoped_ptr<std::string>(new std::string(str));
52 }
53
54 } // namespace
55
56 namespace feedback {
57
58 class FeedbackDataTest : public testing::Test {
59 protected:
60 FeedbackDataTest()
61 : context_(new content::TestBrowserContext()),
62 data_(new FeedbackData()),
63 ui_thread_(content::BrowserThread::UI, &message_loop_) {
64 user_prefs::UserPrefs::Set(context_.get(), new TestingPrefServiceSimple());
65 data_->set_context(context_.get());
66 data_->set_send_report_callback(base::Bind(
67 &FeedbackDataTest::set_send_report_callback, base::Unretained(this)));
68
69 FeedbackUploaderFactory::GetInstance()->SetTestingFactory(
70 context_.get(), &CreateFeedbackUploaderService);
71 }
72
73 void Send() {
74 bool attached_file_completed =
75 data_->attached_file_uuid().empty();
76 bool screenshot_completed =
77 data_->screenshot_uuid().empty();
78
79 if (screenshot_completed && attached_file_completed) {
80 data_->OnFeedbackPageDataComplete();
81 }
82 }
83
84 void RunMessageLoop() {
85 run_loop_.reset(new base::RunLoop());
86 quit_closure_ = run_loop_->QuitClosure();
87 run_loop_->Run();
88 }
89
90 void set_send_report_callback(scoped_refptr<FeedbackData> data) {
91 quit_closure_.Run();
92 }
93
94 base::Closure quit_closure_;
95 scoped_ptr<base::RunLoop> run_loop_;
96 scoped_ptr<content::TestBrowserContext> context_;
97 scoped_refptr<FeedbackData> data_;
98 base::MessageLoop message_loop_;
99 content::TestBrowserThread ui_thread_;
100 };
101
102 TEST_F(FeedbackDataTest, ReportSending) {
103 data_->SetAndCompressHistograms(MakeScoped(kHistograms).Pass());
104 data_->set_image(MakeScoped(kImageData).Pass());
105 data_->AttachAndCompressFileData(MakeScoped(kFileData).Pass());
106 Send();
107 RunMessageLoop();
108 EXPECT_TRUE(data_->IsDataComplete());
109 delete g_uploader;
110 g_uploader = NULL;
111 }
112
113 } // namespace feedback
OLDNEW
« no previous file with comments | « components/feedback/feedback_data.cc ('k') | components/feedback/feedback_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698