Chromium Code Reviews| Index: components/feedback/feedback_common_unittest.cc |
| diff --git a/components/feedback/feedback_common_unittest.cc b/components/feedback/feedback_common_unittest.cc |
| index d3fb9502210c7de0d591c84275b96038a58a6793..c7aa83f4ce754c82297d73ace4d3e7754d0c2c22 100644 |
| --- a/components/feedback/feedback_common_unittest.cc |
| +++ b/components/feedback/feedback_common_unittest.cc |
| @@ -5,12 +5,14 @@ |
| #include "components/feedback/feedback_common.h" |
| #include "base/bind.h" |
| +#include "base/files/scoped_temp_dir.h" |
| #include "components/feedback/proto/common.pb.h" |
| #include "components/feedback/proto/dom.pb.h" |
| #include "components/feedback/proto/extension.pb.h" |
| #include "components/feedback/proto/math.pb.h" |
| #include "content/public/test/test_browser_thread.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "third_party/zlib/google/zip.h" |
| namespace { |
| const char kOne[] = "one"; |
| @@ -20,6 +22,7 @@ const char kFour[] = "four"; |
| #define TEN_LINES "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" |
| const char kLongLog[] = TEN_LINES TEN_LINES TEN_LINES TEN_LINES TEN_LINES; |
| const char kLogsAttachmentName[] = "system_logs.zip"; |
| +const char kLogsFilename[] = "system_logs.txt"; |
| } // namespace |
| class FeedbackCommonTest : public testing::Test { |
| @@ -77,3 +80,41 @@ TEST_F(FeedbackCommonTest, TestCompression) { |
| EXPECT_EQ(1, report.product_specific_binary_data_size()); |
| EXPECT_EQ(kLogsAttachmentName, report.product_specific_binary_data(0).name()); |
| } |
| + |
| +TEST_F(FeedbackCommonTest, TestAddLogsAnonymization) { |
| + std::string mac_address = "Some text 00:11:22:33:44:55 text"; |
| + std::string anonymized_mac_address = "Some text 00:11:22:00:00:01 text"; |
| + feedback->AddLog(kOne, mac_address); |
| + feedback->AddLog(kThree, mac_address + kLongLog); |
| + feedback->CompressLogs(); |
| + feedback->PrepareReport(&report); |
|
vasilii
2015/12/17 12:40:37
The class members aren't marked with '_'. It's ver
battre
2015/12/17 13:24:24
Done.
|
| + |
| + // Verify that uncompressed data is anonymized. |
|
vasilii
2015/12/17 12:40:37
But you compress them above.
battre
2015/12/17 13:24:24
The feedback can contain two types of data at the
vasilii
2015/12/17 13:39:05
Then it should go to a comment explaining why two
battre
2015/12/17 14:34:55
Done.
|
| + ASSERT_EQ(1, report.web_data().product_specific_data_size()); |
| + EXPECT_EQ(anonymized_mac_address, |
| + report.web_data().product_specific_data(0).value()); |
| + |
| + // Verify that compressed data is anonymized. |
| + ASSERT_EQ(1, report.product_specific_binary_data_size()); |
| + const ::userfeedback::ProductSpecificBinaryData& binary_data = |
| + report.product_specific_binary_data(0); |
| + |
| + base::ScopedTempDir scoped_dir; |
| + ASSERT_TRUE(scoped_dir.CreateUniqueTempDir()); |
| + base::FilePath zip_file = scoped_dir.path().Append("logs.zip"); |
| + |
| + ASSERT_TRUE(binary_data.has_data()); |
| + bool success = base::WriteFile(zip_file, binary_data.data().data(), |
|
vasilii
2015/12/17 12:40:37
Why do you test filesystem and zip here?
battre
2015/12/17 13:24:24
Not sure I understand you. My goal is to test whet
vasilii
2015/12/17 13:39:05
Isn't there a way to unzip |binary_data| without t
battre
2015/12/17 14:34:56
Ok, found one.
Done.
|
| + binary_data.data().size()); |
| + ASSERT_TRUE(success); |
| + success = zip::Unzip(zip_file, scoped_dir.path()); |
| + ASSERT_TRUE(success); |
| + |
| + std::string file_content; |
| + success = base::ReadFileToString(scoped_dir.path().Append(kLogsFilename), |
| + &file_content); |
| + ASSERT_TRUE(success); |
| + |
| + EXPECT_TRUE(file_content.find(anonymized_mac_address) != std::string::npos); |
| + EXPECT_TRUE(file_content.find(mac_address) == std::string::npos); |
| +} |