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.
8 #include "base/message_loop/message_loop.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";
15 base::MessageLoopForIO message_loop
;
16 scoped_refptr
<MockWebRtcLoggingMessageFilter
> log_message_filter(
17 new MockWebRtcLoggingMessageFilter(message_loop
.message_loop_proxy()));
18 // Run message loop to initialize delegate.
19 // TODO(vrk): Fix this so that we can construct a delegate without needing to
20 // construct a message filter.
21 message_loop
.RunUntilIdle();
23 ChromeWebRtcLogMessageDelegate
* log_message_delegate
=
24 log_message_filter
->log_message_delegate();
26 // Start logging on the IO loop.
27 message_loop
.message_loop_proxy()->PostTask(
28 FROM_HERE
, base::Bind(
29 &ChromeWebRtcLogMessageDelegate::OnStartLogging
,
30 base::Unretained(log_message_delegate
)));
32 // These log messages should be added to the log buffer outside of the IO
34 log_message_delegate
->LogMessage(kTestString
);
35 log_message_delegate
->LogMessage(kTestString
);
37 // Stop logging on IO loop.
38 message_loop
.message_loop_proxy()->PostTask(
39 FROM_HERE
, base::Bind(
40 &ChromeWebRtcLogMessageDelegate::OnStopLogging
,
41 base::Unretained(log_message_delegate
)));
43 // This log message should not be added to the log buffer.
44 log_message_delegate
->LogMessage(kTestString
);
46 message_loop
.RunUntilIdle();
48 // Size is calculated as (sizeof(kTestString) - 1 for terminating null
49 // + 1 for eol added for each log message in LogMessage) * 2.
50 const uint32 kExpectedSize
= sizeof(kTestString
) * 2;
51 EXPECT_EQ(kExpectedSize
, log_message_filter
->log_buffer_
.size());
53 std::string ref_output
= kTestString
;
54 ref_output
.append("\n");
55 ref_output
.append(kTestString
);
56 ref_output
.append("\n");
57 EXPECT_STREQ(ref_output
.c_str(), log_message_filter
->log_buffer_
.c_str());