1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use base::cross_process_instant::CrossProcessInstant;
use base::id::TEST_PIPELINE_ID;
use base::Epoch;
use ipc_channel::ipc;
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory, ProgressiveWebMetric};
use profile_traits::time::{ProfilerChan, TimerMetadata};
use servo_url::ServoUrl;
struct DummyProfilerMetadataFactory {}
impl ProfilerMetadataFactory for DummyProfilerMetadataFactory {
fn new_metadata(&self) -> Option<TimerMetadata> {
None
}
}
#[test]
fn test_paint_metrics_construction() {
let (sender, _) = ipc::channel().unwrap();
let profiler_chan = ProfilerChan(sender);
let (layout_sender, _) = ipc::channel().unwrap();
let (script_sender, _) = ipc::channel().unwrap();
let start_time = CrossProcessInstant::now();
let paint_time_metrics = PaintTimeMetrics::new(
TEST_PIPELINE_ID,
profiler_chan,
layout_sender,
script_sender,
ServoUrl::parse("about:blank").unwrap(),
start_time,
);
assert_eq!(
(&paint_time_metrics).get_navigation_start(),
Some(start_time),
"navigation start is set properly"
);
assert_eq!(
paint_time_metrics.get_first_paint(),
None,
"first paint is None"
);
assert_eq!(
paint_time_metrics.get_first_contentful_paint(),
None,
"first contentful paint is None"
);
}
fn test_common(display_list_is_contentful: bool, epoch: Epoch) -> PaintTimeMetrics {
let (sender, _) = ipc::channel().unwrap();
let profiler_chan = ProfilerChan(sender);
let (layout_sender, _) = ipc::channel().unwrap();
let (script_sender, _) = ipc::channel().unwrap();
let start_time = CrossProcessInstant::now();
let mut paint_time_metrics = PaintTimeMetrics::new(
TEST_PIPELINE_ID,
profiler_chan,
layout_sender,
script_sender,
ServoUrl::parse("about:blank").unwrap(),
start_time,
);
let dummy_profiler_metadata_factory = DummyProfilerMetadataFactory {};
paint_time_metrics.maybe_observe_paint_time(
&dummy_profiler_metadata_factory,
epoch,
display_list_is_contentful,
);
assert_eq!(
paint_time_metrics.get_first_paint(),
None,
"first paint is None"
);
assert_eq!(
paint_time_metrics.get_first_contentful_paint(),
None,
"first contentful paint is None"
);
let navigation_start = CrossProcessInstant::now();
paint_time_metrics.set_navigation_start(navigation_start);
assert_eq!(
(&paint_time_metrics).get_navigation_start().unwrap(),
navigation_start,
"navigation start is set"
);
paint_time_metrics
}
#[test]
fn test_first_paint_setter() {
let epoch = Epoch(0);
let paint_time_metrics = test_common(false, epoch);
let now = CrossProcessInstant::now();
paint_time_metrics.maybe_set_metric(epoch, now);
assert!(
paint_time_metrics.get_first_paint().is_some(),
"first paint is set"
);
assert_eq!(
paint_time_metrics.get_first_contentful_paint(),
None,
"first contentful paint is None"
);
}
#[test]
fn test_first_contentful_paint_setter() {
let epoch = Epoch(0);
let paint_time_metrics = test_common(true, epoch);
let now = CrossProcessInstant::now();
paint_time_metrics.maybe_set_metric(epoch, now);
assert!(
paint_time_metrics.get_first_contentful_paint().is_some(),
"first contentful paint is set"
);
assert!(
paint_time_metrics.get_first_paint().is_some(),
"first paint is set"
);
}
|