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

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

Issue 2189353003: Sent feedback reports must respect the product ID if any was provided (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comments Created 4 years, 4 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
OLDNEW
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_ = scoped_refptr<FeedbackCommon>(new FeedbackCommon());
29 } 36 }
30 37
31 ~FeedbackCommonTest() override {} 38 ~FeedbackCommonTest() override {}
32 39
33 scoped_refptr<FeedbackCommon> feedback_; 40 scoped_refptr<FeedbackCommon> feedback_;
34 userfeedback::ExtensionSubmit report_; 41 userfeedback::ExtensionSubmit report_;
35 }; 42 };
36 43
37 TEST_F(FeedbackCommonTest, TestBasicData) { 44 TEST_F(FeedbackCommonTest, TestBasicData) {
38 // Test that basic data can be set and propagates to the request. 45 // Test that basic data can be set and propagates to the request.
39 feedback_->set_category_tag(kOne); 46 feedback_->set_category_tag(kOne);
40 feedback_->set_description(kTwo); 47 feedback_->set_description(kTwo);
41 feedback_->set_page_url(kThree); 48 feedback_->set_page_url(kThree);
42 feedback_->set_user_email(kFour); 49 feedback_->set_user_email(kFour);
50 EXPECT_FALSE(feedback_->HasProductId());
51 feedback_->set_product_id(kTestProductId);
52 EXPECT_TRUE(feedback_->HasProductId());
43 feedback_->PrepareReport(&report_); 53 feedback_->PrepareReport(&report_);
44 54
45 EXPECT_EQ(kOne, report_.bucket()); 55 EXPECT_EQ(kOne, report_.bucket());
46 EXPECT_EQ(kTwo, report_.common_data().description()); 56 EXPECT_EQ(kTwo, report_.common_data().description());
47 EXPECT_EQ(kThree, report_.web_data().url()); 57 EXPECT_EQ(kThree, report_.web_data().url());
48 EXPECT_EQ(kFour, report_.common_data().user_email()); 58 EXPECT_EQ(kFour, report_.common_data().user_email());
59 EXPECT_EQ(kTestProductId, report_.product_id());
60 }
61
62 // If an feedback requester doesn't set the product ID, the report will be sent
63 // with the default product ID for Chrome/ChromeOS depending on the platform.
64 TEST_F(FeedbackCommonTest, TestDefaultProductId) {
65 EXPECT_FALSE(feedback_->HasProductId());
66 feedback_->PrepareReport(&report_);
67 EXPECT_EQ(kDefaultProductId, report_.product_id());
49 } 68 }
50 69
51 TEST_F(FeedbackCommonTest, TestAddLogs) { 70 TEST_F(FeedbackCommonTest, TestAddLogs) {
52 feedback_->AddLog(kOne, kTwo); 71 feedback_->AddLog(kOne, kTwo);
53 feedback_->AddLog(kThree, kFour); 72 feedback_->AddLog(kThree, kFour);
54 73
55 EXPECT_EQ(2U, feedback_->sys_info()->size()); 74 EXPECT_EQ(2U, feedback_->sys_info()->size());
56 } 75 }
57 76
58 TEST_F(FeedbackCommonTest, TestCompressionThreshold) { 77 TEST_F(FeedbackCommonTest, TestCompressionThreshold) {
(...skipping 12 matching lines...) Expand all
71 // added with the right name. 90 // added with the right name.
72 feedback_->AddLog(kOne, kTwo); 91 feedback_->AddLog(kOne, kTwo);
73 feedback_->AddLog(kThree, kLongLog); 92 feedback_->AddLog(kThree, kLongLog);
74 feedback_->CompressLogs(); 93 feedback_->CompressLogs();
75 feedback_->PrepareReport(&report_); 94 feedback_->PrepareReport(&report_);
76 95
77 EXPECT_EQ(1, report_.product_specific_binary_data_size()); 96 EXPECT_EQ(1, report_.product_specific_binary_data_size());
78 EXPECT_EQ(kLogsAttachmentName, 97 EXPECT_EQ(kLogsAttachmentName,
79 report_.product_specific_binary_data(0).name()); 98 report_.product_specific_binary_data(0).name());
80 } 99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698