Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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. | |
| 4 | |
| 5 #include "content/browser/trace_subscriber_stdio.h" | |
| 6 #include "testing/gtest/include/gtest/gtest.h" | |
| 7 #include "testing/platform_test.h" | |
| 8 | |
| 9 namespace { | |
| 10 | |
| 11 const FilePath::CharType kFolderPrefix[] = | |
| 12 FILE_PATH_LITERAL("TraceSubscriberStdioTest"); | |
| 13 | |
| 14 class TraceSubscriberStdioTest : public testing::Test { | |
| 15 public: | |
| 16 virtual void SetUp() { | |
| 17 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
| |
| 18 trace_file_ = trace_dir_.AppendASCII("trace.txt"); | |
| 19 } | |
| 20 virtual void TearDown() { | |
| 21 if (!trace_dir_.empty()) { | |
| 22 file_util::Delete(trace_dir_, true); | |
| 23 trace_dir_.clear(); | |
| 24 } | |
| 25 } | |
| 26 std::string ReadTraceFile() { | |
| 27 std::string result; | |
| 28 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.
| |
| 29 return result; | |
| 30 } | |
| 31 | |
| 32 FilePath trace_dir_; | |
| 33 FilePath trace_file_; | |
| 34 }; | |
| 35 | |
| 36 TEST_F(TraceSubscriberStdioTest, CanWriteBracketedDataToFile) { | |
| 37 TraceSubscriberStdio subscriber(trace_file_); | |
| 38 subscriber.OnTraceDataCollected("[foo]"); | |
| 39 subscriber.OnTraceDataCollected("[bar]"); | |
| 40 EXPECT_TRUE(subscriber.IsValid()); | |
| 41 | |
| 42 subscriber.OnEndTracingComplete(); | |
| 43 EXPECT_FALSE(subscriber.IsValid()); | |
| 44 | |
| 45 EXPECT_EQ("[foo,bar,]", ReadTraceFile()); | |
| 46 } | |
| 47 | |
| 48 } | |
|
Paweł Hajdan Jr.
2011/05/18 20:00:46
nit: Add " // namespace"
lain Merrick
2011/05/19 15:49:00
Done.
| |
| OLD | NEW |