| Index: extensions/browser/api/cast_channel/logger_unittest.cc
|
| diff --git a/extensions/browser/api/cast_channel/logger_unittest.cc b/extensions/browser/api/cast_channel/logger_unittest.cc
|
| index d1ec5fcdbbf2d676c92814e2eb21fdd5e3a7b7bc..ba6f9903b6b74e6ce357ab87beddb3d085def087 100644
|
| --- a/extensions/browser/api/cast_channel/logger_unittest.cc
|
| +++ b/extensions/browser/api/cast_channel/logger_unittest.cc
|
| @@ -6,6 +6,7 @@
|
| #include "extensions/browser/api/cast_channel/cast_auth_util.h"
|
| #include "extensions/browser/api/cast_channel/logger.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| +#include "third_party/zlib/zlib.h"
|
|
|
| namespace extensions {
|
| namespace core_api {
|
| @@ -25,6 +26,38 @@ class CastChannelLoggerTest : public testing::Test {
|
| base::TimeTicks())) {}
|
| virtual ~CastChannelLoggerTest() {}
|
|
|
| + bool Uncompress(const std::string& input, std::string* output) {
|
| + z_stream stream = {0};
|
| +
|
| + stream.next_in = reinterpret_cast<uint8*>(const_cast<char*>(&input[0]));
|
| + stream.avail_in = input.size();
|
| + stream.next_out = reinterpret_cast<uint8*>(&(*output)[0]);
|
| + stream.avail_out = output->size();
|
| +
|
| + bool success = false;
|
| + while (stream.avail_in > 0 && stream.avail_out > 0) {
|
| + // 16 is added to read in gzip format.
|
| + int result = inflateInit2(&stream, MAX_WBITS + 16);
|
| + DCHECK_EQ(Z_OK, result);
|
| +
|
| + result = inflate(&stream, Z_FINISH);
|
| + success = (result == Z_STREAM_END);
|
| + if (!success) {
|
| + DVLOG(2) << "inflate() failed. Result: " << result;
|
| + break;
|
| + }
|
| +
|
| + result = inflateEnd(&stream);
|
| + DCHECK(result == Z_OK);
|
| + }
|
| +
|
| + if (stream.avail_in == 0) {
|
| + success = true;
|
| + output->resize(output->size() - stream.avail_out);
|
| + }
|
| + return success;
|
| + }
|
| +
|
| protected:
|
| base::SimpleTestTickClock* clock_;
|
| scoped_refptr<Logger> logger_;
|
| @@ -58,8 +91,13 @@ TEST_F(CastChannelLoggerTest, BasicLogging) {
|
| bool success = logger_->LogToString(&output);
|
| ASSERT_TRUE(success);
|
|
|
| + // 10kb should be enough for test purposes.
|
| + std::string uncompressed(10000, 0);
|
| + success = Uncompress(output, &uncompressed);
|
| + ASSERT_TRUE(success);
|
| +
|
| Log log;
|
| - success = log.ParseFromString(output);
|
| + success = log.ParseFromString(uncompressed);
|
| ASSERT_TRUE(success);
|
|
|
| ASSERT_EQ(2, log.aggregated_socket_event_size());
|
| @@ -131,8 +169,13 @@ TEST_F(CastChannelLoggerTest, TooManySockets) {
|
| bool success = logger_->LogToString(&output);
|
| ASSERT_TRUE(success);
|
|
|
| + // 10kb should be enough for test purposes.
|
| + std::string uncompressed(10000, 0);
|
| + success = Uncompress(output, &uncompressed);
|
| + ASSERT_TRUE(success);
|
| +
|
| Log log;
|
| - success = log.ParseFromString(output);
|
| + success = log.ParseFromString(uncompressed);
|
| ASSERT_TRUE(success);
|
|
|
| ASSERT_EQ(kMaxSocketsToLog, log.aggregated_socket_event_size());
|
| @@ -154,8 +197,13 @@ TEST_F(CastChannelLoggerTest, TooManyEvents) {
|
| bool success = logger_->LogToString(&output);
|
| ASSERT_TRUE(success);
|
|
|
| + // 100kb should be enough for test purposes.
|
| + std::string uncompressed(100000, 0);
|
| + success = Uncompress(output, &uncompressed);
|
| + ASSERT_TRUE(success);
|
| +
|
| Log log;
|
| - success = log.ParseFromString(output);
|
| + success = log.ParseFromString(uncompressed);
|
| ASSERT_TRUE(success);
|
|
|
| ASSERT_EQ(1, log.aggregated_socket_event_size());
|
| @@ -175,8 +223,13 @@ TEST_F(CastChannelLoggerTest, Reset) {
|
| bool success = logger_->LogToString(&output);
|
| ASSERT_TRUE(success);
|
|
|
| + // 10kb should be enough for test purposes.
|
| + std::string uncompressed(10000, 0);
|
| + success = Uncompress(output, &uncompressed);
|
| + ASSERT_TRUE(success);
|
| +
|
| Log log;
|
| - success = log.ParseFromString(output);
|
| + success = log.ParseFromString(uncompressed);
|
| ASSERT_TRUE(success);
|
|
|
| EXPECT_EQ(1, log.aggregated_socket_event_size());
|
| @@ -185,7 +238,9 @@ TEST_F(CastChannelLoggerTest, Reset) {
|
|
|
| success = logger_->LogToString(&output);
|
| ASSERT_TRUE(success);
|
| - success = log.ParseFromString(output);
|
| + success = Uncompress(output, &uncompressed);
|
| + ASSERT_TRUE(success);
|
| + success = log.ParseFromString(uncompressed);
|
| ASSERT_TRUE(success);
|
|
|
| EXPECT_EQ(0, log.aggregated_socket_event_size());
|
|
|