Index: content/browser/trace_subscriber_stdio_unittest.cc |
=================================================================== |
--- content/browser/trace_subscriber_stdio_unittest.cc (revision 0) |
+++ content/browser/trace_subscriber_stdio_unittest.cc (revision 0) |
@@ -0,0 +1,48 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/trace_subscriber_stdio.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "testing/platform_test.h" |
+ |
+namespace { |
+ |
+const FilePath::CharType kFolderPrefix[] = |
+ FILE_PATH_LITERAL("TraceSubscriberStdioTest"); |
+ |
+class TraceSubscriberStdioTest : public testing::Test { |
+ public: |
+ virtual void SetUp() { |
+ ASSERT_TRUE(file_util::CreateNewTempDirectory(kFolderPrefix, &trace_dir_)); |
Paweł Hajdan Jr.
2011/05/18 20:00:46
Oh, could you just use ScopedTempDir instead?
lain Merrick
2011/05/19 15:49:00
Done.
I originally based this code on some existi
|
+ trace_file_ = trace_dir_.AppendASCII("trace.txt"); |
+ } |
+ virtual void TearDown() { |
+ if (!trace_dir_.empty()) { |
+ file_util::Delete(trace_dir_, true); |
+ trace_dir_.clear(); |
+ } |
+ } |
+ std::string ReadTraceFile() { |
+ std::string result; |
+ file_util::ReadFileToString(trace_file_, &result); |
Paweł Hajdan Jr.
2011/05/18 20:00:46
How about checking the return value?
lain Merrick
2011/05/19 15:49:00
Done.
|
+ return result; |
+ } |
+ |
+ FilePath trace_dir_; |
+ FilePath trace_file_; |
+}; |
+ |
+TEST_F(TraceSubscriberStdioTest, CanWriteBracketedDataToFile) { |
+ TraceSubscriberStdio subscriber(trace_file_); |
+ subscriber.OnTraceDataCollected("[foo]"); |
+ subscriber.OnTraceDataCollected("[bar]"); |
+ EXPECT_TRUE(subscriber.IsValid()); |
+ |
+ subscriber.OnEndTracingComplete(); |
+ EXPECT_FALSE(subscriber.IsValid()); |
+ |
+ EXPECT_EQ("[foo,bar,]", ReadTraceFile()); |
+} |
+ |
+} |
Paweł Hajdan Jr.
2011/05/18 20:00:46
nit: Add " // namespace"
lain Merrick
2011/05/19 15:49:00
Done.
|
Property changes on: content/browser/trace_subscriber_stdio_unittest.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |