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