1 // Copyright 2013 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 "base/file_util.h"
6 #include "base/run_loop.h"
7 #include "content/browser/tracing/tracing_controller_impl.h"
8 #include "content/public/test/browser_test_utils.h"
9 #include "content/shell/browser/shell.h"
10 #include "content/test/content_browser_test.h"
11 #include "content/test/content_browser_test_utils.h"
15 class TracingControllerTest
: public ContentBrowserTest
{
17 TracingControllerTest() {}
19 virtual void SetUp() OVERRIDE
{
20 get_categories_done_callback_count_
= 0;
21 enable_recording_done_callback_count_
= 0;
22 disable_recording_done_callback_count_
= 0;
23 ContentBrowserTest::SetUp();
26 virtual void TearDown() OVERRIDE
{
27 ContentBrowserTest::TearDown();
30 void Navigate(Shell
* shell
) {
31 NavigateToURL(shell
, GetTestUrl("", "title.html"));
34 void GetCategoriesDoneCallbackTest(base::Closure quit_callback
,
35 const std::set
<std::string
>& categories
) {
36 get_categories_done_callback_count_
++;
37 EXPECT_TRUE(categories
.size() > 0);
41 void EnableRecordingDoneCallbackTest(base::Closure quit_callback
) {
42 enable_recording_done_callback_count_
++;
46 void DisableRecordingDoneCallbackTest(base::Closure quit_callback
,
47 scoped_ptr
<base::FilePath
> file_path
) {
48 disable_recording_done_callback_count_
++;
49 EXPECT_TRUE(PathExists(*file_path
));
53 int get_categories_done_callback_count() const {
54 return get_categories_done_callback_count_
;
57 int enable_recording_done_callback_count() const {
58 return enable_recording_done_callback_count_
;
61 int disable_recording_done_callback_count() const {
62 return disable_recording_done_callback_count_
;
66 int get_categories_done_callback_count_
;
67 int enable_recording_done_callback_count_
;
68 int disable_recording_done_callback_count_
;
71 IN_PROC_BROWSER_TEST_F(TracingControllerTest
, GetCategories
) {
74 TracingController
* controller
= TracingController::GetInstance();
76 base::RunLoop run_loop
;
77 TracingController::GetCategoriesDoneCallback callback
=
78 base::Bind(&TracingControllerTest::GetCategoriesDoneCallbackTest
,
79 base::Unretained(this),
80 run_loop
.QuitClosure());
81 controller
->GetCategories(callback
);
83 EXPECT_EQ(get_categories_done_callback_count(), 1);
86 IN_PROC_BROWSER_TEST_F(TracingControllerTest
, EnableAndDisableRecording
) {
89 TracingController
* controller
= TracingController::GetInstance();
92 base::RunLoop run_loop
;
93 TracingController::EnableRecordingDoneCallback callback
=
94 base::Bind(&TracingControllerTest::EnableRecordingDoneCallbackTest
,
95 base::Unretained(this),
96 run_loop
.QuitClosure());
97 controller
->EnableRecording(base::debug::CategoryFilter("*"),
98 TracingController::Options(), callback
);
100 EXPECT_EQ(enable_recording_done_callback_count(), 1);
104 base::RunLoop run_loop
;
105 TracingController::TracingFileResultCallback callback
=
106 base::Bind(&TracingControllerTest::DisableRecordingDoneCallbackTest
,
107 base::Unretained(this),
108 run_loop
.QuitClosure());
109 controller
->DisableRecording(callback
);
111 EXPECT_EQ(disable_recording_done_callback_count(), 1);
115 } // namespace content