Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: chrome/renderer/media/chrome_webrtc_log_message_delegate_unittest.cc

Issue 23691066: Hook up WebRTC logging extension API to the underlying functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "base/process/process_handle.h" 7 #include "base/process/process_handle.h"
8 #include "chrome/common/partial_circular_buffer.h" 8 #include "chrome/common/partial_circular_buffer.h"
9 #include "chrome/renderer/media/chrome_webrtc_log_message_delegate.h" 9 #include "chrome/renderer/media/chrome_webrtc_log_message_delegate.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 TEST(ChromeWebRtcLogMessageDelegateTest, Basic) { 12 TEST(ChromeWebRtcLogMessageDelegateTest, Basic) {
13 const uint32 kTestLogSize = 1024; // 1 KB 13 const uint32 kTestLogSize = 1024; // 1 KB
14 const char kTestString[] = "abcdefghijklmnopqrstuvwxyz"; 14 const char kTestString[] = "abcdefghijklmnopqrstuvwxyz";
15 15
16 base::MessageLoop message_loop(base::MessageLoop::TYPE_IO); 16 base::MessageLoop message_loop(base::MessageLoop::TYPE_IO);
17 17
18 scoped_ptr<ChromeWebRtcLogMessageDelegate> log_message_delegate( 18 scoped_ptr<ChromeWebRtcLogMessageDelegate> log_message_delegate(
19 new ChromeWebRtcLogMessageDelegate(message_loop.message_loop_proxy(), 19 new ChromeWebRtcLogMessageDelegate(message_loop.message_loop_proxy(),
20 NULL)); 20 NULL));
21 21
22 base::SharedMemory shared_memory; 22 base::SharedMemory shared_memory;
23 ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(kTestLogSize)); 23 ASSERT_TRUE(shared_memory.CreateAndMapAnonymous(kTestLogSize));
24 base::SharedMemoryHandle new_handle; 24 base::SharedMemoryHandle new_handle;
25 ASSERT_TRUE(shared_memory.ShareToProcess(base::GetCurrentProcessHandle(), 25 ASSERT_TRUE(shared_memory.ShareToProcess(base::GetCurrentProcessHandle(),
26 &new_handle)); 26 &new_handle));
27 log_message_delegate->OnLogOpened(new_handle, kTestLogSize); 27 log_message_delegate->OnStartLogging(new_handle, kTestLogSize);
28 28
29 // These log messages should be added to the log buffer.
29 log_message_delegate->LogMessage(kTestString); 30 log_message_delegate->LogMessage(kTestString);
30 log_message_delegate->LogMessage(kTestString); 31 log_message_delegate->LogMessage(kTestString);
31 32
33 log_message_delegate->OnStopLogging();
34
35 // This log message should not be added to the log buffer.
36 log_message_delegate->LogMessage(kTestString);
37
32 PartialCircularBuffer read_pcb( 38 PartialCircularBuffer read_pcb(
33 reinterpret_cast<uint8*>(shared_memory.memory()), kTestLogSize); 39 reinterpret_cast<uint8*>(shared_memory.memory()), kTestLogSize);
34 40
35 // Size is calculated as (sizeof(kTestString) - 1 for terminating null 41 // Size is calculated as (sizeof(kTestString) - 1 for terminating null
36 // + 1 for eol added for each log message in LogMessage) * 2 + 1 for 42 // + 1 for eol added for each log message in LogMessage) * 2.
37 // terminating null. 43 // Use a larger buffer to read the log into be able to ensure log content is
38 char read_buffer[sizeof(kTestString) * 2 + 1] = {0}; 44 // not larger than expected.
45 const uint32 kExpectedSize = sizeof(kTestString) * 2;
46 char read_buffer[kExpectedSize * 2] = {0};
39 47
40 uint32 read = read_pcb.Read(read_buffer, sizeof(read_buffer)); 48 uint32 read = read_pcb.Read(read_buffer, kExpectedSize * 2);
41 EXPECT_EQ(sizeof(read_buffer) - 1, read); 49 EXPECT_EQ(kExpectedSize, read);
42 std::string ref_output = kTestString; 50 std::string ref_output = kTestString;
43 ref_output.append("\n"); 51 ref_output.append("\n");
44 ref_output.append(kTestString); 52 ref_output.append(kTestString);
45 ref_output.append("\n"); 53 ref_output.append("\n");
46 EXPECT_STREQ(ref_output.c_str(), read_buffer); 54 EXPECT_STREQ(ref_output.c_str(), read_buffer);
47 } 55 }
OLDNEW
« no previous file with comments | « chrome/renderer/media/chrome_webrtc_log_message_delegate.cc ('k') | chrome/renderer/media/webrtc_logging_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698