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_common.h" | 5 #include "components/feedback/feedback_common.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "components/feedback/proto/common.pb.h" | 8 #include "components/feedback/proto/common.pb.h" |
9 #include "components/feedback/proto/dom.pb.h" | 9 #include "components/feedback/proto/dom.pb.h" |
10 #include "components/feedback/proto/extension.pb.h" | 10 #include "components/feedback/proto/extension.pb.h" |
11 #include "components/feedback/proto/math.pb.h" | 11 #include "components/feedback/proto/math.pb.h" |
12 #include "content/public/test/test_browser_thread.h" | 12 #include "content/public/test/test_browser_thread.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace { | 15 namespace { |
16 const char kOne[] = "one"; | 16 const char kOne[] = "one"; |
17 const char kTwo[] = "two"; | 17 const char kTwo[] = "two"; |
18 const char kThree[] = "three"; | 18 const char kThree[] = "three"; |
19 const char kFour[] = "four"; | 19 const char kFour[] = "four"; |
20 #define TEN_LINES "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" | 20 #define TEN_LINES "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" |
21 const char kLongLog[] = TEN_LINES TEN_LINES TEN_LINES TEN_LINES TEN_LINES; | 21 const char kLongLog[] = TEN_LINES TEN_LINES TEN_LINES TEN_LINES TEN_LINES; |
22 const char kLogsAttachmentName[] = "system_logs.zip"; | 22 const char kLogsAttachmentName[] = "system_logs.zip"; |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 class FeedbackCommonTest : public testing::Test { | 25 class FeedbackCommonTest : public testing::Test { |
26 protected: | 26 protected: |
27 FeedbackCommonTest() { | 27 FeedbackCommonTest() { |
28 feedback = scoped_refptr<FeedbackCommon>(new FeedbackCommon()); | 28 feedback_ = scoped_refptr<FeedbackCommon>(new FeedbackCommon()); |
29 } | 29 } |
30 | 30 |
31 ~FeedbackCommonTest() override {} | 31 ~FeedbackCommonTest() override {} |
32 | 32 |
33 scoped_refptr<FeedbackCommon> feedback; | 33 scoped_refptr<FeedbackCommon> feedback_; |
34 userfeedback::ExtensionSubmit report; | 34 userfeedback::ExtensionSubmit report_; |
35 }; | 35 }; |
36 | 36 |
37 TEST_F(FeedbackCommonTest, TestBasicData) { | 37 TEST_F(FeedbackCommonTest, TestBasicData) { |
38 // Test that basic data can be set and propagates to the request. | 38 // Test that basic data can be set and propagates to the request. |
39 feedback->set_category_tag(kOne); | 39 feedback_->set_category_tag(kOne); |
40 feedback->set_description(kTwo); | 40 feedback_->set_description(kTwo); |
41 feedback->set_page_url(kThree); | 41 feedback_->set_page_url(kThree); |
42 feedback->set_user_email(kFour); | 42 feedback_->set_user_email(kFour); |
43 feedback->PrepareReport(&report); | 43 feedback_->PrepareReport(&report_); |
44 | 44 |
45 EXPECT_EQ(kOne, report.bucket()); | 45 EXPECT_EQ(kOne, report_.bucket()); |
46 EXPECT_EQ(kTwo, report.common_data().description()); | 46 EXPECT_EQ(kTwo, report_.common_data().description()); |
47 EXPECT_EQ(kThree, report.web_data().url()); | 47 EXPECT_EQ(kThree, report_.web_data().url()); |
48 EXPECT_EQ(kFour, report.common_data().user_email()); | 48 EXPECT_EQ(kFour, report_.common_data().user_email()); |
49 } | 49 } |
50 | 50 |
51 TEST_F(FeedbackCommonTest, TestAddLogs) { | 51 TEST_F(FeedbackCommonTest, TestAddLogs) { |
52 feedback->AddLog(kOne, kTwo); | 52 feedback_->AddLog(kOne, kTwo); |
53 feedback->AddLog(kThree, kFour); | 53 feedback_->AddLog(kThree, kFour); |
54 | 54 |
55 EXPECT_EQ(2U, feedback->sys_info()->size()); | 55 EXPECT_EQ(2U, feedback_->sys_info()->size()); |
56 } | 56 } |
57 | 57 |
58 TEST_F(FeedbackCommonTest, TestCompressionThreshold) { | 58 TEST_F(FeedbackCommonTest, TestCompressionThreshold) { |
59 // Add a large and small log, verify that only the small log gets | 59 // Add a large and small log, verify that only the small log gets |
60 // included in the report. | 60 // included in the report. |
61 feedback->AddLog(kOne, kTwo); | 61 feedback_->AddLog(kOne, kTwo); |
62 feedback->AddLog(kThree, kLongLog); | 62 feedback_->AddLog(kThree, kLongLog); |
63 feedback->PrepareReport(&report); | 63 feedback_->PrepareReport(&report_); |
64 | 64 |
65 EXPECT_EQ(1, report.web_data().product_specific_data_size()); | 65 EXPECT_EQ(1, report_.web_data().product_specific_data_size()); |
66 EXPECT_EQ(kOne, report.web_data().product_specific_data(0).key()); | 66 EXPECT_EQ(kOne, report_.web_data().product_specific_data(0).key()); |
67 } | 67 } |
68 | 68 |
69 TEST_F(FeedbackCommonTest, TestCompression) { | 69 TEST_F(FeedbackCommonTest, TestCompression) { |
70 // Add a large and small log, verify that an attachment has been | 70 // Add a large and small log, verify that an attachment has been |
71 // added with the right name. | 71 // added with the right name. |
72 feedback->AddLog(kOne, kTwo); | 72 feedback_->AddLog(kOne, kTwo); |
73 feedback->AddLog(kThree, kLongLog); | 73 feedback_->AddLog(kThree, kLongLog); |
74 feedback->CompressLogs(); | 74 feedback_->CompressLogs(); |
75 feedback->PrepareReport(&report); | 75 feedback_->PrepareReport(&report_); |
76 | 76 |
77 EXPECT_EQ(1, report.product_specific_binary_data_size()); | 77 EXPECT_EQ(1, report_.product_specific_binary_data_size()); |
78 EXPECT_EQ(kLogsAttachmentName, report.product_specific_binary_data(0).name()); | 78 EXPECT_EQ(kLogsAttachmentName, |
| 79 report_.product_specific_binary_data(0).name()); |
79 } | 80 } |
OLD | NEW |