Infobar material design refresh: bg color
[chromium-blink-merge.git] / chrome / renderer / media / chrome_webrtc_log_message_delegate_unittest.cc
blob6680c7ea07fd8b4ec2b1862f50c9f6e39d8ae546
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.
5 #include <string>
7 #include "base/bind.h"
8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/single_thread_task_runner.h"
11 #include "chrome/renderer/media/chrome_webrtc_log_message_delegate.h"
12 #include "chrome/renderer/media/mock_webrtc_logging_message_filter.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 TEST(ChromeWebRtcLogMessageDelegateTest, Basic) {
16 const char kTestString[] = "abcdefghijklmnopqrstuvwxyz";
17 base::MessageLoopForIO message_loop;
18 scoped_refptr<MockWebRtcLoggingMessageFilter> log_message_filter(
19 new MockWebRtcLoggingMessageFilter(message_loop.task_runner()));
20 // Run message loop to initialize delegate.
21 // TODO(vrk): Fix this so that we can construct a delegate without needing to
22 // construct a message filter.
23 message_loop.RunUntilIdle();
25 ChromeWebRtcLogMessageDelegate* log_message_delegate =
26 log_message_filter->log_message_delegate();
28 // Start logging on the IO loop.
29 message_loop.task_runner()->PostTask(
30 FROM_HERE, base::Bind(&ChromeWebRtcLogMessageDelegate::OnStartLogging,
31 base::Unretained(log_message_delegate)));
33 // These log messages should be added to the log buffer outside of the IO
34 // loop.
35 log_message_delegate->LogMessage(kTestString);
36 log_message_delegate->LogMessage(kTestString);
38 // Stop logging on IO loop.
39 message_loop.task_runner()->PostTask(
40 FROM_HERE, base::Bind(&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());