| 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 constexpr char kOne[] = "one"; |
| 17 const char kTwo[] = "two"; | 17 constexpr char kTwo[] = "two"; |
| 18 const char kThree[] = "three"; | 18 constexpr char kThree[] = "three"; |
| 19 const char kFour[] = "four"; | 19 constexpr 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 constexpr char kLongLog[] = TEN_LINES TEN_LINES TEN_LINES TEN_LINES TEN_LINES; |
| 22 const char kLogsAttachmentName[] = "system_logs.zip"; | 22 constexpr char kLogsAttachmentName[] = "system_logs.zip"; |
| 23 constexpr int kTestProductId = 3490; |
| 24 |
| 25 #if defined(OS_CHROMEOS) |
| 26 constexpr int kDefaultProductId = 208; // ChromeOS default product ID. |
| 27 #else |
| 28 constexpr int kDefaultProductId = 237; // Chrome default product ID. |
| 29 #endif // defined(OS_CHROMEOS) |
| 23 } // namespace | 30 } // namespace |
| 24 | 31 |
| 25 class FeedbackCommonTest : public testing::Test { | 32 class FeedbackCommonTest : public testing::Test { |
| 26 protected: | 33 protected: |
| 27 FeedbackCommonTest() { | 34 FeedbackCommonTest() |
| 28 feedback_ = scoped_refptr<FeedbackCommon>(new FeedbackCommon()); | 35 : feedback_(new FeedbackCommon()) { |
| 29 } | 36 } |
| 30 | 37 |
| 31 ~FeedbackCommonTest() override {} | 38 ~FeedbackCommonTest() override {} |
| 32 | 39 |
| 40 bool FeedbackHasProductId() const { return feedback_->HasProductId(); } |
| 41 |
| 33 scoped_refptr<FeedbackCommon> feedback_; | 42 scoped_refptr<FeedbackCommon> feedback_; |
| 34 userfeedback::ExtensionSubmit report_; | 43 userfeedback::ExtensionSubmit report_; |
| 35 }; | 44 }; |
| 36 | 45 |
| 37 TEST_F(FeedbackCommonTest, TestBasicData) { | 46 TEST_F(FeedbackCommonTest, TestBasicData) { |
| 38 // Test that basic data can be set and propagates to the request. | 47 // Test that basic data can be set and propagates to the request. |
| 39 feedback_->set_category_tag(kOne); | 48 feedback_->set_category_tag(kOne); |
| 40 feedback_->set_description(kTwo); | 49 feedback_->set_description(kTwo); |
| 41 feedback_->set_page_url(kThree); | 50 feedback_->set_page_url(kThree); |
| 42 feedback_->set_user_email(kFour); | 51 feedback_->set_user_email(kFour); |
| 52 EXPECT_FALSE(FeedbackHasProductId()); |
| 53 feedback_->set_product_id(kTestProductId); |
| 54 EXPECT_TRUE(FeedbackHasProductId()); |
| 43 feedback_->PrepareReport(&report_); | 55 feedback_->PrepareReport(&report_); |
| 44 | 56 |
| 45 EXPECT_EQ(kOne, report_.bucket()); | 57 EXPECT_EQ(kOne, report_.bucket()); |
| 46 EXPECT_EQ(kTwo, report_.common_data().description()); | 58 EXPECT_EQ(kTwo, report_.common_data().description()); |
| 47 EXPECT_EQ(kThree, report_.web_data().url()); | 59 EXPECT_EQ(kThree, report_.web_data().url()); |
| 48 EXPECT_EQ(kFour, report_.common_data().user_email()); | 60 EXPECT_EQ(kFour, report_.common_data().user_email()); |
| 61 EXPECT_EQ(kTestProductId, report_.product_id()); |
| 62 } |
| 63 |
| 64 // If an feedback requester doesn't set the product ID, the report will be sent |
| 65 // with the default product ID for Chrome/ChromeOS depending on the platform. |
| 66 TEST_F(FeedbackCommonTest, TestDefaultProductId) { |
| 67 EXPECT_FALSE(FeedbackHasProductId()); |
| 68 feedback_->PrepareReport(&report_); |
| 69 EXPECT_EQ(kDefaultProductId, report_.product_id()); |
| 49 } | 70 } |
| 50 | 71 |
| 51 TEST_F(FeedbackCommonTest, TestAddLogs) { | 72 TEST_F(FeedbackCommonTest, TestAddLogs) { |
| 52 feedback_->AddLog(kOne, kTwo); | 73 feedback_->AddLog(kOne, kTwo); |
| 53 feedback_->AddLog(kThree, kFour); | 74 feedback_->AddLog(kThree, kFour); |
| 54 | 75 |
| 55 EXPECT_EQ(2U, feedback_->sys_info()->size()); | 76 EXPECT_EQ(2U, feedback_->sys_info()->size()); |
| 56 } | 77 } |
| 57 | 78 |
| 58 TEST_F(FeedbackCommonTest, TestCompressionThreshold) { | 79 TEST_F(FeedbackCommonTest, TestCompressionThreshold) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 71 // added with the right name. | 92 // added with the right name. |
| 72 feedback_->AddLog(kOne, kTwo); | 93 feedback_->AddLog(kOne, kTwo); |
| 73 feedback_->AddLog(kThree, kLongLog); | 94 feedback_->AddLog(kThree, kLongLog); |
| 74 feedback_->CompressLogs(); | 95 feedback_->CompressLogs(); |
| 75 feedback_->PrepareReport(&report_); | 96 feedback_->PrepareReport(&report_); |
| 76 | 97 |
| 77 EXPECT_EQ(1, report_.product_specific_binary_data_size()); | 98 EXPECT_EQ(1, report_.product_specific_binary_data_size()); |
| 78 EXPECT_EQ(kLogsAttachmentName, | 99 EXPECT_EQ(kLogsAttachmentName, |
| 79 report_.product_specific_binary_data(0).name()); | 100 report_.product_specific_binary_data(0).name()); |
| 80 } | 101 } |
| OLD | NEW |