Chromium Code Reviews| Index: chrome/common/page_load_metrics/page_load_metrics_struct_traits_unittest.cc |
| diff --git a/chrome/common/page_load_metrics/page_load_metrics_struct_traits_unittest.cc b/chrome/common/page_load_metrics/page_load_metrics_struct_traits_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4094ccdc888c79609cfe2a0159bd8adce21f770b |
| --- /dev/null |
| +++ b/chrome/common/page_load_metrics/page_load_metrics_struct_traits_unittest.cc |
| @@ -0,0 +1,195 @@ |
| +// Copyright 2017 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 "chrome/common/page_load_metrics/page_load_metrics_struct_traits.h" |
| + |
| +#include "base/time/time.h" |
| +#include "chrome/common/page_load_metrics/page_load_metrics.mojom.h" |
| +#include "chrome/common/page_load_metrics/page_load_timing.h" |
| +#include "ipc/ipc_message_utils.h" |
| +#include "mojo/common/common_custom_types_struct_traits.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace page_load_metrics { |
| + |
| +TEST(DocumentTimingStructTraitsTest, Basic) { |
|
Bryan McQuade
2017/05/07 19:44:41
Let's make all of these part of PageLoadMetricsStr
lpy
2017/05/08 18:38:33
Done. I don't think these names are more descripti
|
| + DocumentTiming document_timing; |
| + document_timing.dom_content_loaded_event_start = |
| + base::TimeDelta::FromMicroseconds(1); |
| + document_timing.load_event_start = base::TimeDelta::FromMicroseconds(2); |
| + document_timing.first_layout = base::TimeDelta::FromMicroseconds(3); |
| + |
| + DocumentTiming document_timing2; |
| + ASSERT_TRUE(mojom::DocumentTiming::Deserialize( |
| + mojom::DocumentTiming::Serialize(&document_timing), &document_timing2)); |
| + |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(1), |
| + document_timing2.dom_content_loaded_event_start); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(2), |
| + document_timing2.load_event_start); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(3), |
| + document_timing2.first_layout); |
| +} |
| + |
| +TEST(PaintTimingStructTraitsTest, Basic) { |
| + PaintTiming paint_timing; |
| + paint_timing.first_paint = base::TimeDelta::FromMicroseconds(1); |
| + paint_timing.first_text_paint = base::TimeDelta::FromMicroseconds(2); |
| + paint_timing.first_image_paint = base::TimeDelta::FromMicroseconds(3); |
| + paint_timing.first_contentful_paint = base::TimeDelta::FromMicroseconds(4); |
| + paint_timing.first_meaningful_paint = base::TimeDelta::FromMicroseconds(5); |
| + |
| + PaintTiming paint_timing2; |
| + ASSERT_TRUE(mojom::PaintTiming::Deserialize( |
| + mojom::PaintTiming::Serialize(&paint_timing), &paint_timing2)); |
| + |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(1), paint_timing2.first_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(2), |
| + paint_timing2.first_text_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(3), |
| + paint_timing2.first_image_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(4), |
| + paint_timing2.first_contentful_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(5), |
| + paint_timing2.first_meaningful_paint); |
| +} |
| + |
| +TEST(ParseTimingStructTraitsTest, Basic) { |
| + ParseTiming parse_timing; |
| + parse_timing.parse_start = base::TimeDelta::FromMicroseconds(1); |
| + parse_timing.parse_stop = base::TimeDelta::FromMicroseconds(2); |
| + parse_timing.parse_blocked_on_script_load_duration = |
| + base::TimeDelta::FromMicroseconds(3); |
| + parse_timing.parse_blocked_on_script_load_from_document_write_duration = |
| + base::TimeDelta::FromMicroseconds(4); |
| + parse_timing.parse_blocked_on_script_execution_duration = |
| + base::TimeDelta::FromMicroseconds(5); |
| + parse_timing.parse_blocked_on_script_execution_from_document_write_duration = |
| + base::TimeDelta::FromMicroseconds(6); |
| + |
| + ParseTiming parse_timing2; |
| + ASSERT_TRUE(mojom::ParseTiming::Deserialize( |
| + mojom::ParseTiming::Serialize(&parse_timing), &parse_timing2)); |
| + |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(1), parse_timing2.parse_start); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(2), parse_timing2.parse_stop); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(3), |
| + parse_timing2.parse_blocked_on_script_load_duration); |
| + EXPECT_EQ( |
| + base::TimeDelta::FromMicroseconds(4), |
| + parse_timing2.parse_blocked_on_script_load_from_document_write_duration); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(5), |
| + parse_timing2.parse_blocked_on_script_execution_duration); |
| + EXPECT_EQ( |
| + base::TimeDelta::FromMicroseconds(6), |
| + parse_timing2 |
| + .parse_blocked_on_script_execution_from_document_write_duration); |
| +} |
| + |
| +TEST(StyleSheetTimingStructTraitsTest, Basic) { |
| + StyleSheetTiming style_sheet_timing; |
| + style_sheet_timing.author_style_sheet_parse_duration_before_fcp = |
| + base::TimeDelta::FromMicroseconds(1); |
| + style_sheet_timing.update_style_duration_before_fcp = |
| + base::TimeDelta::FromMicroseconds(2); |
| + |
| + StyleSheetTiming style_sheet_timing2; |
| + ASSERT_TRUE(mojom::StyleSheetTiming::Deserialize( |
| + mojom::StyleSheetTiming::Serialize(&style_sheet_timing), |
| + &style_sheet_timing2)); |
| + |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(1), |
| + style_sheet_timing2.author_style_sheet_parse_duration_before_fcp); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(2), |
| + style_sheet_timing2.update_style_duration_before_fcp); |
| +} |
| + |
| +TEST(PageLoadTimingStructTraitsTest, Basic) { |
| + PageLoadTiming page_load_timing; |
| + page_load_timing.navigation_start = base::Time::FromDoubleT(1); |
| + page_load_timing.response_start = base::TimeDelta::FromMicroseconds(1); |
| + page_load_timing.document_timing.dom_content_loaded_event_start = |
| + base::TimeDelta::FromMicroseconds(2); |
| + page_load_timing.document_timing.load_event_start = |
| + base::TimeDelta::FromMicroseconds(3); |
| + page_load_timing.document_timing.first_layout = |
| + base::TimeDelta::FromMicroseconds(4); |
| + page_load_timing.paint_timing.first_paint = |
| + base::TimeDelta::FromMicroseconds(5); |
| + page_load_timing.paint_timing.first_text_paint = |
| + base::TimeDelta::FromMicroseconds(6); |
| + page_load_timing.paint_timing.first_image_paint = |
| + base::TimeDelta::FromMicroseconds(7); |
| + page_load_timing.paint_timing.first_contentful_paint = |
| + base::TimeDelta::FromMicroseconds(8); |
| + page_load_timing.paint_timing.first_meaningful_paint = |
| + base::TimeDelta::FromMicroseconds(9); |
| + page_load_timing.parse_timing.parse_start = |
| + base::TimeDelta::FromMicroseconds(10); |
| + page_load_timing.parse_timing.parse_stop = |
| + base::TimeDelta::FromMicroseconds(11); |
| + page_load_timing.parse_timing.parse_blocked_on_script_load_duration = |
| + base::TimeDelta::FromMicroseconds(12); |
| + page_load_timing.parse_timing |
| + .parse_blocked_on_script_load_from_document_write_duration = |
| + base::TimeDelta::FromMicroseconds(13); |
| + page_load_timing.parse_timing.parse_blocked_on_script_execution_duration = |
| + base::TimeDelta::FromMicroseconds(14); |
| + page_load_timing.parse_timing |
| + .parse_blocked_on_script_execution_from_document_write_duration = |
| + base::TimeDelta::FromMicroseconds(15); |
| + page_load_timing.style_sheet_timing |
| + .author_style_sheet_parse_duration_before_fcp = |
| + base::TimeDelta::FromMicroseconds(16); |
| + page_load_timing.style_sheet_timing.update_style_duration_before_fcp = |
| + base::TimeDelta::FromMicroseconds(17); |
| + |
| + PageLoadTiming page_load_timing2; |
| + ASSERT_TRUE(mojom::PageLoadTiming::Deserialize( |
| + mojom::PageLoadTiming::Serialize(&page_load_timing), &page_load_timing2)); |
| + EXPECT_EQ(base::Time::FromDoubleT(1), page_load_timing2.navigation_start); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(1), |
| + page_load_timing2.response_start); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(2), |
| + page_load_timing2.document_timing.dom_content_loaded_event_start); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(3), |
| + page_load_timing2.document_timing.load_event_start); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(4), |
| + page_load_timing2.document_timing.first_layout); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(5), |
| + page_load_timing2.paint_timing.first_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(6), |
| + page_load_timing2.paint_timing.first_text_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(7), |
| + page_load_timing2.paint_timing.first_image_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(8), |
| + page_load_timing2.paint_timing.first_contentful_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(9), |
| + page_load_timing2.paint_timing.first_meaningful_paint); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(10), |
| + page_load_timing2.parse_timing.parse_start); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(11), |
| + page_load_timing2.parse_timing.parse_stop); |
| + EXPECT_EQ( |
| + base::TimeDelta::FromMicroseconds(12), |
| + page_load_timing2.parse_timing.parse_blocked_on_script_load_duration); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(13), |
| + page_load_timing2.parse_timing |
| + .parse_blocked_on_script_load_from_document_write_duration); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(14), |
| + page_load_timing2.parse_timing |
| + .parse_blocked_on_script_execution_duration); |
| + EXPECT_EQ( |
| + base::TimeDelta::FromMicroseconds(15), |
| + page_load_timing2.parse_timing |
| + .parse_blocked_on_script_execution_from_document_write_duration); |
| + EXPECT_EQ(base::TimeDelta::FromMicroseconds(16), |
| + page_load_timing2.style_sheet_timing |
| + .author_style_sheet_parse_duration_before_fcp); |
| + EXPECT_EQ( |
| + base::TimeDelta::FromMicroseconds(17), |
| + page_load_timing2.style_sheet_timing.update_style_duration_before_fcp); |
| +} |
| + |
| +} // namespace page_load_metrics |