summaryrefslogtreecommitdiffstats
path: root/content/browser/trace_subscriber_stdio_unittest.cc
blob: 51d913da06dd8548b5567e51deab966a023b5c09 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright (c) 2012 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 "base/scoped_temp_dir.h"
#include "base/threading/sequenced_worker_pool.h"
#include "content/public/browser/browser_thread.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {

TEST(TraceSubscriberStdioTest, CanWriteDataToFile) {
  ScopedTempDir trace_dir;
  ASSERT_TRUE(trace_dir.CreateUniqueTempDir());
  FilePath trace_file(trace_dir.path().AppendASCII("trace.txt"));
  {
    TraceSubscriberStdio subscriber(trace_file);

    std::string foo("foo");
    subscriber.OnTraceDataCollected(
        make_scoped_refptr(base::RefCountedString::TakeString(&foo)));

    std::string bar("bar");
    subscriber.OnTraceDataCollected(
        make_scoped_refptr(base::RefCountedString::TakeString(&bar)));

    subscriber.OnEndTracingComplete();
  }
  BrowserThread::GetBlockingPool()->FlushForTesting();
  std::string result;
  EXPECT_TRUE(file_util::ReadFileToString(trace_file, &result));
  EXPECT_EQ("[foo,bar]", result);
}

}  // namespace content