Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: components/metrics/profiler/tracking_synchronizer_unittest.cc

Issue 1021053003: Delivering the FIRST_NONEMPTY_PAINT phase changing event to base/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@phase_splitting
Patch Set: Evehn more isherman@ comments. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
index a597a477c64a0f5a8cdb6303bd24231149c8928a..9b625be7474f66fb795673098a26f6325bee0aa8 100644
--- a/components/metrics/profiler/tracking_synchronizer_unittest.cc
+++ b/components/metrics/profiler/tracking_synchronizer_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/memory/ref_counted.h"
+#include "base/test/simple_test_tick_clock.h"
#include "base/tracked_objects.h"
#include "components/metrics/profiler/tracking_synchronizer.h"
#include "components/metrics/profiler/tracking_synchronizer_observer.h"
@@ -30,8 +31,8 @@ class TestObserver : public TrackingSynchronizerObserver {
base::ProcessId process_id,
content::ProcessType process_type,
int profiling_phase,
- base::TimeDelta phase_start,
- base::TimeDelta phase_finish,
+ base::TimeTicks phase_start,
+ base::TimeTicks phase_finish,
const ProfilerEvents& past_events) override {
EXPECT_EQ(static_cast<base::ProcessId>(239), process_id);
EXPECT_EQ(content::ProcessType::PROCESS_TYPE_PLUGIN, process_type);
@@ -42,8 +43,10 @@ class TestObserver : public TrackingSynchronizerObserver {
EXPECT_FALSE(got_phase_0_);
got_phase_0_ = true;
- EXPECT_EQ(base::TimeDelta::FromMilliseconds(0), phase_start);
- EXPECT_EQ(base::TimeDelta::FromMilliseconds(222), phase_finish);
+ EXPECT_EQ(base::TimeTicks() + base::TimeDelta::FromMilliseconds(111),
+ phase_start);
+ EXPECT_EQ(base::TimeTicks() + base::TimeDelta::FromMilliseconds(333),
+ phase_finish);
EXPECT_EQ("death_thread0",
process_data_phase.tasks[0].death_thread_name);
@@ -54,8 +57,10 @@ class TestObserver : public TrackingSynchronizerObserver {
EXPECT_FALSE(got_phase_1_);
got_phase_1_ = true;
- EXPECT_EQ(base::TimeDelta::FromMilliseconds(222), phase_start);
- EXPECT_EQ(base::TimeDelta::FromMilliseconds(666), phase_finish);
+ EXPECT_EQ(base::TimeTicks() + base::TimeDelta::FromMilliseconds(333),
+ phase_start);
+ EXPECT_EQ(base::TimeTicks() + base::TimeDelta::FromMilliseconds(777),
+ phase_finish);
EXPECT_EQ("death_thread1",
process_data_phase.tasks[0].death_thread_name);
@@ -77,9 +82,16 @@ class TestObserver : public TrackingSynchronizerObserver {
DISALLOW_COPY_AND_ASSIGN(TestObserver);
};
-base::TimeTicks TestTimeFromMs(int64 ms) {
- return base::TimeTicks() + base::TimeDelta::FromMilliseconds(ms);
-}
+class TestTrackingSynchronizer : public TrackingSynchronizer {
+ public:
+ explicit TestTrackingSynchronizer(base::TickClock* clock)
Alexei Svitkine (slow) 2015/04/09 15:39:06 This should take a scoped_ptr to indicate it's tak
vadimt 2015/04/09 21:28:40 Done.
+ : TrackingSynchronizer(make_scoped_ptr(clock)) {}
+
+ ~TestTrackingSynchronizer() {}
+
+ using TrackingSynchronizer::RegisterPhaseCompletion;
+ using TrackingSynchronizer::SendData;
+};
} // namespace
@@ -88,13 +100,18 @@ TEST(TrackingSynchronizerTest, ProfilerData) {
#if !defined(OS_IOS)
content::TestBrowserThreadBundle thread_bundle;
#endif
- scoped_refptr<TrackingSynchronizer> tracking_synchronizer =
- new TrackingSynchronizer(TestTimeFromMs(111));
- // Mimic a phase change event.
- tracking_synchronizer->phase_completion_events_sequence_.push_back(
+ auto clock = new base::SimpleTestTickClock(); // Will be owned by
+ // |tracking_synchronizer|.
+ clock->Advance(base::TimeDelta::FromMilliseconds(111));
+
+ scoped_refptr<TestTrackingSynchronizer> tracking_synchronizer =
+ new TestTrackingSynchronizer(clock);
+
+ clock->Advance(base::TimeDelta::FromMilliseconds(222));
+
+ tracking_synchronizer->RegisterPhaseCompletion(
ProfilerEventProto::EVENT_FIRST_NONEMPTY_PAINT);
- tracking_synchronizer->phase_start_times_.push_back(TestTimeFromMs(333));
tracked_objects::ProcessDataSnapshot profiler_data;
ProcessDataPhaseSnapshot snapshot0;
@@ -109,10 +126,10 @@ TEST(TrackingSynchronizerTest, ProfilerData) {
profiler_data.phased_process_data_snapshots[1] = snapshot1;
profiler_data.process_id = 239;
+ clock->Advance(base::TimeDelta::FromMilliseconds(444));
TestObserver test_observer;
- tracking_synchronizer->SendData(profiler_data,
- content::ProcessType::PROCESS_TYPE_PLUGIN,
- TestTimeFromMs(777), &test_observer);
+ tracking_synchronizer->SendData(
+ profiler_data, content::ProcessType::PROCESS_TYPE_PLUGIN, &test_observer);
}
} // namespace metrics

Powered by Google App Engine
This is Rietveld 408576698