Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / feedback / feedback_data_unittest.cc
blobe10bc2fa8f0d8f3e849123f5599b5b84f20b2c86
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.
5 #include "components/feedback/feedback_data.h"
7 #include <set>
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/prefs/testing_pref_service.h"
12 #include "base/run_loop.h"
13 #include "components/feedback/feedback_uploader.h"
14 #include "components/feedback/feedback_uploader_factory.h"
15 #include "components/keyed_service/core/keyed_service.h"
16 #include "components/user_prefs/user_prefs.h"
17 #include "content/public/test/test_browser_context.h"
18 #include "content/public/test/test_browser_thread.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 namespace {
24 const char kHistograms[] = "";
25 const char kImageData[] = "";
26 const char kFileData[] = "";
28 const base::TimeDelta kRetryDelayForTest =
29 base::TimeDelta::FromMilliseconds(100);
31 using content::BrowserThread;
33 class MockUploader : public feedback::FeedbackUploader, public KeyedService {
34 public:
35 MockUploader(content::BrowserContext* context)
36 : FeedbackUploader(context ? context->GetPath() : base::FilePath(),
37 BrowserThread::GetBlockingPool()) {}
39 MOCK_METHOD1(DispatchReport, void(const std::string&));
42 scoped_ptr<KeyedService> CreateFeedbackUploaderService(
43 content::BrowserContext* context) {
44 scoped_ptr<MockUploader> uploader(new MockUploader(context));
45 EXPECT_CALL(*uploader, DispatchReport(testing::_)).Times(1);
46 return uploader.Pass();
49 scoped_ptr<std::string> MakeScoped(const char* str) {
50 return scoped_ptr<std::string>(new std::string(str));
53 } // namespace
55 namespace feedback {
57 class FeedbackDataTest : public testing::Test {
58 protected:
59 FeedbackDataTest()
60 : context_(new content::TestBrowserContext()),
61 prefs_(new TestingPrefServiceSimple()),
62 data_(new FeedbackData()),
63 ui_thread_(content::BrowserThread::UI, &message_loop_) {
64 user_prefs::UserPrefs::Set(context_.get(), prefs_.get());
65 data_->set_context(context_.get());
66 data_->set_send_report_callback(base::Bind(
67 &FeedbackDataTest::set_send_report_callback, base::Unretained(this)));
69 FeedbackUploaderFactory::GetInstance()->SetTestingFactory(
70 context_.get(), &CreateFeedbackUploaderService);
73 void Send() {
74 bool attached_file_completed =
75 data_->attached_file_uuid().empty();
76 bool screenshot_completed =
77 data_->screenshot_uuid().empty();
79 if (screenshot_completed && attached_file_completed) {
80 data_->OnFeedbackPageDataComplete();
84 void RunMessageLoop() {
85 run_loop_.reset(new base::RunLoop());
86 quit_closure_ = run_loop_->QuitClosure();
87 run_loop_->Run();
90 void set_send_report_callback(scoped_refptr<FeedbackData> data) {
91 quit_closure_.Run();
94 base::Closure quit_closure_;
95 scoped_ptr<base::RunLoop> run_loop_;
96 scoped_ptr<content::TestBrowserContext> context_;
97 scoped_ptr<PrefService> prefs_;
98 scoped_refptr<FeedbackData> data_;
99 base::MessageLoop message_loop_;
100 content::TestBrowserThread ui_thread_;
103 TEST_F(FeedbackDataTest, ReportSending) {
104 data_->SetAndCompressHistograms(MakeScoped(kHistograms).Pass());
105 data_->set_image(MakeScoped(kImageData).Pass());
106 data_->AttachAndCompressFileData(MakeScoped(kFileData).Pass());
107 Send();
108 RunMessageLoop();
109 EXPECT_TRUE(data_->IsDataComplete());
112 } // namespace feedback