Home | History | Annotate | Download | only in tracing
      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.
      4 
      5 #include "content/browser/tracing/trace_subscriber_stdio.h"
      6 
      7 #include "base/file_util.h"
      8 #include "base/files/scoped_temp_dir.h"
      9 #include "base/threading/sequenced_worker_pool.h"
     10 #include "content/public/browser/browser_thread.h"
     11 #include "testing/gtest/include/gtest/gtest.h"
     12 
     13 namespace content {
     14 
     15 class TraceSubscriberStdioTest : public ::testing::Test {};
     16 
     17 TEST_F(TraceSubscriberStdioTest, CanWriteDataToFile) {
     18   base::ScopedTempDir trace_dir;
     19   ASSERT_TRUE(trace_dir.CreateUniqueTempDir());
     20   base::FilePath trace_file(trace_dir.path().AppendASCII("trace.txt"));
     21   {
     22     TraceSubscriberStdio subscriber(trace_file);
     23 
     24     std::string foo("foo");
     25     subscriber.OnTraceDataCollected(
     26         make_scoped_refptr(base::RefCountedString::TakeString(&foo)));
     27 
     28     std::string bar("bar");
     29     subscriber.OnTraceDataCollected(
     30         make_scoped_refptr(base::RefCountedString::TakeString(&bar)));
     31 
     32     subscriber.OnEndTracingComplete();
     33   }
     34   BrowserThread::GetBlockingPool()->FlushForTesting();
     35   std::string result;
     36   EXPECT_TRUE(file_util::ReadFileToString(trace_file, &result));
     37   EXPECT_EQ("[foo,bar]", result);
     38 }
     39 
     40 }  // namespace content
     41