| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/trace_subscriber_stdio.h" | 5 #include "content/browser/trace_subscriber_stdio.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 TEST(TraceSubscriberStdioTest, CanWriteDataToFile) { | 13 class TraceSubscriberStdioTest : public ::testing::Test { |
| 14 private: |
| 15 // Needed by the blocking pool (but no need to pump it). |
| 16 MessageLoop message_loop_; |
| 17 }; |
| 18 |
| 19 TEST_F(TraceSubscriberStdioTest, CanWriteDataToFile) { |
| 14 ScopedTempDir trace_dir; | 20 ScopedTempDir trace_dir; |
| 15 ASSERT_TRUE(trace_dir.CreateUniqueTempDir()); | 21 ASSERT_TRUE(trace_dir.CreateUniqueTempDir()); |
| 16 FilePath trace_file(trace_dir.path().AppendASCII("trace.txt")); | 22 FilePath trace_file(trace_dir.path().AppendASCII("trace.txt")); |
| 17 { | 23 { |
| 18 content::TraceSubscriberStdio subscriber(trace_file); | 24 content::TraceSubscriberStdio subscriber(trace_file); |
| 19 | 25 |
| 20 std::string foo("foo"); | 26 std::string foo("foo"); |
| 21 subscriber.OnTraceDataCollected( | 27 subscriber.OnTraceDataCollected( |
| 22 make_scoped_refptr(base::RefCountedString::TakeString(&foo))); | 28 make_scoped_refptr(base::RefCountedString::TakeString(&foo))); |
| 23 | 29 |
| 24 std::string bar("bar"); | 30 std::string bar("bar"); |
| 25 subscriber.OnTraceDataCollected( | 31 subscriber.OnTraceDataCollected( |
| 26 make_scoped_refptr(base::RefCountedString::TakeString(&bar))); | 32 make_scoped_refptr(base::RefCountedString::TakeString(&bar))); |
| 27 | 33 |
| 28 subscriber.OnEndTracingComplete(); | 34 subscriber.OnEndTracingComplete(); |
| 29 } | 35 } |
| 30 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 36 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 31 std::string result; | 37 std::string result; |
| 32 EXPECT_TRUE(file_util::ReadFileToString(trace_file, &result)); | 38 EXPECT_TRUE(file_util::ReadFileToString(trace_file, &result)); |
| 33 EXPECT_EQ("[foo,bar]", result); | 39 EXPECT_EQ("[foo,bar]", result); |
| 34 } | 40 } |
| OLD | NEW |