Chromium Code Reviews| Index: components/metrics/profiler/tracking_synchronizer_unittest.cc |
| diff --git a/components/metrics/profiler/tracking_synchronizer_unittest.cc b/components/metrics/profiler/tracking_synchronizer_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..735bd1a60b7ddf3c7201fb469d567783582dc788 |
| --- /dev/null |
| +++ b/components/metrics/profiler/tracking_synchronizer_unittest.cc |
| @@ -0,0 +1,107 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/tracked_objects.h" |
| +#include "components/metrics/profiler/tracking_synchronizer.h" |
| +#include "components/metrics/profiler/tracking_synchronizer_observer.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using tracked_objects::ProcessDataPhaseSnapshot; |
| +using tracked_objects::TaskSnapshot; |
| + |
| +namespace metrics { |
| + |
| +class TestObserver : public TrackingSynchronizerObserver { |
| + public: |
| + ~TestObserver() { |
| + EXPECT_TRUE(got0); |
| + EXPECT_TRUE(got1); |
| + } |
| + |
| + virtual void ReceivedProfilerData( |
| + const tracked_objects::ProcessDataPhaseSnapshot& process_data_phase, |
| + base::ProcessId process_id, |
| + content::ProcessType process_type, |
| + int profiling_phase, |
| + const base::TimeDelta& phase_start, |
| + const base::TimeDelta& phase_finish, |
| + const ProfilerEvents& past_events) override { |
| + ASSERT_EQ(239, process_id); |
| + ASSERT_EQ(content::ProcessType::PROCESS_TYPE_PLUGIN, process_type); |
| + |
| + switch (profiling_phase) { |
| + case 0: |
| + ASSERT_FALSE(got0); |
| + got0 = true; |
| + |
| + ASSERT_EQ(base::TimeDelta::FromMilliseconds(0), phase_start); |
| + ASSERT_EQ(base::TimeDelta::FromMilliseconds(222), phase_finish); |
| + |
| + ASSERT_EQ("death_thread0", |
| + process_data_phase.tasks[0].death_thread_name); |
| + ASSERT_EQ(0, past_events.size()); |
| + break; |
| + |
| + case 1: |
| + ASSERT_FALSE(got1); |
| + got1 = true; |
| + |
| + ASSERT_EQ(base::TimeDelta::FromMilliseconds(222), phase_start); |
| + ASSERT_EQ(base::TimeDelta::FromMilliseconds(666), phase_finish); |
| + |
| + ASSERT_EQ("death_thread1", |
| + process_data_phase.tasks[0].death_thread_name); |
| + ASSERT_EQ(1, past_events.size()); |
| + ASSERT_EQ(ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT, |
| + past_events[0]); |
| + break; |
| + |
| + default: |
| + ASSERT_FALSE("profiling_phase is neither 0 nor 1"); |
| + } |
| + } |
| + |
| + private: |
| + bool got0 = false; |
|
Alexei Svitkine (slow)
2015/03/16 22:00:15
I'm not sure this syntax is allowed yet. Is it? If
vadimt
2015/03/16 23:09:14
Worked for me.
Alexei Svitkine (slow)
2015/03/17 14:53:41
Sorry, I don't mean whether it compiles, but wheth
vadimt
2015/03/17 15:12:53
Not even allowed, but seems like encouraged:
"Use
Alexei Svitkine (slow)
2015/03/17 15:16:43
Great! Thanks for checking.
|
| + bool got1 = false; |
| +}; |
|
Alexei Svitkine (slow)
2015/03/16 22:00:15
Nit: DISALLOW_COPY()
vadimt
2015/03/16 23:09:14
Done.
|
| + |
| +base::TimeTicks TestTimeFromMs(int64 ms) { |
| + return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms); |
| +} |
| + |
| +TEST(TrackingSynchronizerTest, ProfilerData) { |
| + // Testing how TrackingSynchronizer reports 2 phases of profiling to |
| + // TrackingSynchronizerObserver. |
| + content::TestBrowserThreadBundle thread_bundle; |
| + |
| + scoped_refptr<TrackingSynchronizer> ts = |
| + new TrackingSynchronizer(TestTimeFromMs(111)); |
| + |
| + // Mimic a phase change event. |
| + ts->phase_completion_events_sequence_.push_back( |
| + ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT); |
| + ts->phase_start_times_.push_back(TestTimeFromMs(333)); |
| + |
| + tracked_objects::ProcessDataSnapshot profiler_data; |
| + ProcessDataPhaseSnapshot snapshot0; |
| + tracked_objects::TaskSnapshot task_snapshot0; |
| + task_snapshot0.death_thread_name = "death_thread0"; |
| + snapshot0.tasks.push_back(task_snapshot0); |
| + ProcessDataPhaseSnapshot snapshot1; |
| + profiler_data.phased_process_data_snapshots[0] = snapshot0; |
| + tracked_objects::TaskSnapshot task_snapshot1; |
| + task_snapshot1.death_thread_name = "death_thread1"; |
| + snapshot1.tasks.push_back(task_snapshot1); |
| + profiler_data.phased_process_data_snapshots[1] = snapshot1; |
| + profiler_data.process_id = 239; |
| + |
| + TestObserver to; |
| + ts->SendData(profiler_data, content::ProcessType::PROCESS_TYPE_PLUGIN, |
| + TestTimeFromMs(777), &to); |
| +} |
| + |
| +} // namespace metrics |