Hide Google logo and custom launcher page in app list for non-Google search engines.
[chromium-blink-merge.git] / base / trace_event / trace_event_system_stats_monitor_unittest.cc
blob995f53bd2d475a54d438068ee1c9ef0485f2a776
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/trace_event/trace_event_system_stats_monitor.h"
7 #include <sstream>
8 #include <string>
10 #include "base/message_loop/message_loop.h"
11 #include "base/trace_event/trace_event_impl.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 namespace base {
15 namespace trace_event {
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 ~TraceSystemStatsMonitorTest() override {}
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 trace_event
66 } // namespace base