1 // Copyright 2013 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.
7 #include "base/process/process_handle.h"
8 #include "chrome/common/partial_circular_buffer.h"
9 #include "chrome/renderer/media/chrome_webrtc_log_message_delegate.h"
10 #include "chrome/renderer/media/mock_webrtc_logging_message_filter.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 TEST(ChromeWebRtcLogMessageDelegateTest
, Basic
) {
14 const char kTestString
[] = "abcdefghijklmnopqrstuvwxyz";
16 base::MessageLoopForIO message_loop
;
18 scoped_refptr
<MockWebRtcLoggingMessageFilter
> log_message_filter(
19 new MockWebRtcLoggingMessageFilter(message_loop
.message_loop_proxy()));
21 scoped_ptr
<ChromeWebRtcLogMessageDelegate
> log_message_delegate(
22 new ChromeWebRtcLogMessageDelegate(message_loop
.message_loop_proxy(),
25 log_message_delegate
->OnStartLogging();
27 // These log messages should be added to the log buffer.
28 log_message_delegate
->LogMessage(kTestString
);
29 log_message_delegate
->LogMessage(kTestString
);
31 log_message_delegate
->OnStopLogging();
33 // This log message should not be added to the log buffer.
34 log_message_delegate
->LogMessage(kTestString
);
36 // Size is calculated as (sizeof(kTestString) - 1 for terminating null
37 // + 1 for eol added for each log message in LogMessage) * 2.
38 const uint32 kExpectedSize
= sizeof(kTestString
) * 2;
39 EXPECT_EQ(kExpectedSize
, log_message_filter
->log_buffer_
.size());
41 std::string ref_output
= kTestString
;
42 ref_output
.append("\n");
43 ref_output
.append(kTestString
);
44 ref_output
.append("\n");
45 EXPECT_STREQ(ref_output
.c_str(), log_message_filter
->log_buffer_
.c_str());