Linux: The App Launcher now appears on the "Internet" menu, not "Other".
[chromium-blink-merge.git] / base / debug / trace_event_system_stats_monitor_unittest.cc
blob5cc2a0fd383f7f67bc7b6ff124767a9ee0b613f2
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/debug/trace_event_system_stats_monitor.h"
7 #include <sstream>
8 #include <string>
10 #include "base/debug/trace_event_impl.h"
11 #include "base/message_loop/message_loop.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace base {
15 namespace debug {
17 #if !defined(OS_IOS)
18 // Tests for the system stats monitor.
19 // Exists as a class so it can be a friend of TraceEventSystemStatsMonitor.
20 class TraceSystemStatsMonitorTest : public testing::Test {
21 public:
22 TraceSystemStatsMonitorTest() {}
23 virtual ~TraceSystemStatsMonitorTest() {}
25 private:
26 DISALLOW_COPY_AND_ASSIGN(TraceSystemStatsMonitorTest);
29 //////////////////////////////////////////////////////////////////////////////
31 TEST_F(TraceSystemStatsMonitorTest, TraceEventSystemStatsMonitor) {
32 MessageLoop message_loop;
34 // Start with no observers of the TraceLog.
35 EXPECT_EQ(0u, TraceLog::GetInstance()->GetObserverCountForTest());
37 // Creating a system stats monitor adds it to the TraceLog observer list.
38 scoped_ptr<TraceEventSystemStatsMonitor> system_stats_monitor(
39 new TraceEventSystemStatsMonitor(
40 message_loop.message_loop_proxy()));
41 EXPECT_EQ(1u, TraceLog::GetInstance()->GetObserverCountForTest());
42 EXPECT_TRUE(
43 TraceLog::GetInstance()->HasEnabledStateObserver(
44 system_stats_monitor.get()));
46 // By default the observer isn't dumping memory profiles.
47 EXPECT_FALSE(system_stats_monitor->IsTimerRunningForTest());
49 // Simulate enabling tracing.
50 system_stats_monitor->StartProfiling();
51 message_loop.RunUntilIdle();
52 EXPECT_TRUE(system_stats_monitor->IsTimerRunningForTest());
54 // Simulate disabling tracing.
55 system_stats_monitor->StopProfiling();
56 message_loop.RunUntilIdle();
57 EXPECT_FALSE(system_stats_monitor->IsTimerRunningForTest());
59 // Deleting the observer removes it from the TraceLog observer list.
60 system_stats_monitor.reset();
61 EXPECT_EQ(0u, TraceLog::GetInstance()->GetObserverCountForTest());
63 #endif // !defined(OS_IOS)
65 } // namespace debug
66 } // namespace base