OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
| 9 #include "base/threading/thread_restrictions.h" |
| 10 #include "content/browser/browser_thread_impl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
9 | 12 |
10 namespace { | 13 namespace { |
11 | 14 |
12 class TraceSubscriberStdioTest : public testing::Test { | 15 class TraceSubscriberStdioTest : public testing::Test { |
13 public: | 16 public: |
| 17 TraceSubscriberStdioTest() |
| 18 : file_thread_(content::BrowserThread::FILE, &loop_) { |
| 19 } |
| 20 |
14 virtual void SetUp() { | 21 virtual void SetUp() { |
15 ASSERT_TRUE(trace_dir_.CreateUniqueTempDir()); | 22 ASSERT_TRUE(trace_dir_.CreateUniqueTempDir()); |
16 trace_file_ = trace_dir_.path().AppendASCII("trace.txt"); | 23 trace_file_ = trace_dir_.path().AppendASCII("trace.txt"); |
17 } | 24 } |
18 | 25 |
19 std::string ReadTraceFile() { | 26 std::string ReadTraceFile() { |
20 std::string result; | 27 std::string result; |
21 EXPECT_TRUE(file_util::ReadFileToString(trace_file_, &result)); | 28 EXPECT_TRUE(file_util::ReadFileToString(trace_file_, &result)); |
22 return result; | 29 return result; |
23 } | 30 } |
24 | 31 |
| 32 MessageLoop loop_; |
| 33 content::BrowserThreadImpl file_thread_; |
25 ScopedTempDir trace_dir_; | 34 ScopedTempDir trace_dir_; |
26 FilePath trace_file_; | 35 FilePath trace_file_; |
27 }; | 36 }; |
28 | 37 |
29 } // namespace | 38 } // namespace |
30 | 39 |
31 TEST_F(TraceSubscriberStdioTest, CanWriteDataToFile) { | 40 TEST_F(TraceSubscriberStdioTest, CanWriteDataToFile) { |
32 TraceSubscriberStdio subscriber(trace_file_); | 41 std::string foo("foo"); |
33 subscriber.OnTraceDataCollected("[foo]"); | 42 std::string bar("bar"); |
34 subscriber.OnTraceDataCollected("[bar]"); | |
35 EXPECT_TRUE(subscriber.IsValid()); | |
36 | 43 |
37 subscriber.OnEndTracingComplete(); | 44 { |
38 EXPECT_FALSE(subscriber.IsValid()); | 45 content::TraceSubscriberStdio subscriber(trace_file_); |
| 46 subscriber.OnTraceDataCollected( |
| 47 make_scoped_refptr(base::RefCountedString::TakeString(&foo))); |
| 48 subscriber.OnTraceDataCollected( |
| 49 make_scoped_refptr(base::RefCountedString::TakeString(&bar))); |
| 50 subscriber.OnEndTracingComplete(); |
| 51 } |
| 52 |
| 53 file_thread_.message_loop()->RunAllPending(); |
| 54 std::string result; |
| 55 EXPECT_TRUE(file_util::ReadFileToString(trace_file_, &result)); |
| 56 EXPECT_EQ("[foo,bar]", result); |
39 } | 57 } |
40 | |
OLD | NEW |