1 // Copyright (c) 2012 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 "content/browser/trace_subscriber_stdio.h"
7 #include "base/files/scoped_temp_dir.h"
8 #include "base/threading/sequenced_worker_pool.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "testing/gtest/include/gtest/gtest.h"
14 class TraceSubscriberStdioTest
: public ::testing::Test
{};
16 TEST_F(TraceSubscriberStdioTest
, CanWriteDataToFile
) {
17 base::ScopedTempDir trace_dir
;
18 ASSERT_TRUE(trace_dir
.CreateUniqueTempDir());
19 FilePath
trace_file(trace_dir
.path().AppendASCII("trace.txt"));
21 TraceSubscriberStdio
subscriber(trace_file
);
23 std::string
foo("foo");
24 subscriber
.OnTraceDataCollected(
25 make_scoped_refptr(base::RefCountedString::TakeString(&foo
)));
27 std::string
bar("bar");
28 subscriber
.OnTraceDataCollected(
29 make_scoped_refptr(base::RefCountedString::TakeString(&bar
)));
31 subscriber
.OnEndTracingComplete();
33 BrowserThread::GetBlockingPool()->FlushForTesting();
35 EXPECT_TRUE(file_util::ReadFileToString(trace_file
, &result
));
36 EXPECT_EQ("[foo,bar]", result
);
39 } // namespace content