forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
servo: Merge #17816 - PWM tests (from ferjm:pwm-tests); r=jdm
- [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] There are tests for these changes Source-Repo: https://github.com/servo/servo Source-Revision: 291c9576cf386179bddace6cd39815de03beb8f1
- Loading branch information
Showing
6 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "metrics_tests" | ||
version = "0.0.1" | ||
authors = ["The Servo Project Developers"] | ||
license = "MPL-2.0" | ||
|
||
[lib] | ||
name = "metrics_tests" | ||
path = "lib.rs" | ||
doctest = false | ||
|
||
[dependencies] | ||
euclid = "0.15" | ||
gfx = {path = "../../../components/gfx"} | ||
ipc-channel = "0.8" | ||
metrics = {path = "../../../components/metrics"} | ||
msg = {path = "../../../components/msg"} | ||
net_traits = {path = "../../../components/net_traits"} | ||
profile_traits = {path = "../../../components/profile_traits"} | ||
style = {path = "../../../components/style"} | ||
time = "0.1.12" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
extern crate euclid; | ||
extern crate gfx; | ||
extern crate ipc_channel; | ||
extern crate metrics; | ||
extern crate msg; | ||
extern crate net_traits; | ||
extern crate profile_traits; | ||
extern crate style; | ||
extern crate time; | ||
|
||
#[cfg(test)] | ||
mod paint_time; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
use euclid::Size2D; | ||
use gfx::display_list::{BaseDisplayItem, WebRenderImageInfo}; | ||
use gfx::display_list::{DisplayItem, DisplayList, ImageDisplayItem}; | ||
use ipc_channel::ipc; | ||
use metrics::{PaintTimeMetrics, ProfilerMetadataFactory}; | ||
use msg::constellation_msg::{PipelineId, PipelineIndex, PipelineNamespaceId}; | ||
use net_traits::image::base::PixelFormat; | ||
use profile_traits::time::{ProfilerChan, TimerMetadata}; | ||
use style::computed_values::image_rendering; | ||
use time; | ||
|
||
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 paint_time_metrics = PaintTimeMetrics::new(profiler_chan); | ||
assert_eq!(paint_time_metrics.get_navigation_start(), None, "navigation start is None"); | ||
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"); | ||
} | ||
|
||
#[test] | ||
fn test_first_paint_setter() { | ||
let (sender, _) = ipc::channel().unwrap(); | ||
let profiler_chan = ProfilerChan(sender); | ||
let mut paint_time_metrics = PaintTimeMetrics::new(profiler_chan); | ||
let dummy_profiler_metadata_factory = DummyProfilerMetadataFactory {}; | ||
|
||
// Should not set any metric until navigation start is set. | ||
paint_time_metrics.maybe_set_first_paint(&dummy_profiler_metadata_factory); | ||
assert_eq!(paint_time_metrics.get_first_paint(), None, "first paint is None"); | ||
|
||
let navigation_start = time::precise_time_ns() as f64; | ||
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.maybe_set_first_paint(&dummy_profiler_metadata_factory); | ||
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 (sender, _) = ipc::channel().unwrap(); | ||
let profiler_chan = ProfilerChan(sender); | ||
let mut paint_time_metrics = PaintTimeMetrics::new(profiler_chan); | ||
let dummy_profiler_metadata_factory = DummyProfilerMetadataFactory {}; | ||
let empty_display_list = DisplayList { | ||
list: Vec::new() | ||
}; | ||
|
||
// Should not set any metric until navigation start is set. | ||
paint_time_metrics.maybe_set_first_contentful_paint(&dummy_profiler_metadata_factory, | ||
&empty_display_list); | ||
assert_eq!(paint_time_metrics.get_first_contentful_paint(), None, "first contentful paint is None"); | ||
|
||
// Should not set first contentful paint if no appropriate display item is present. | ||
let navigation_start = time::precise_time_ns() as f64; | ||
paint_time_metrics.set_navigation_start(navigation_start); | ||
paint_time_metrics.maybe_set_first_contentful_paint(&dummy_profiler_metadata_factory, | ||
&empty_display_list); | ||
assert_eq!(paint_time_metrics.get_first_contentful_paint(), None, "first contentful paint is None"); | ||
|
||
let pipeline_id = PipelineId { | ||
namespace_id: PipelineNamespaceId(1), | ||
index: PipelineIndex(1), | ||
}; | ||
let image = DisplayItem::Image(Box::new(ImageDisplayItem { | ||
base: BaseDisplayItem::empty(pipeline_id), | ||
webrender_image: WebRenderImageInfo { | ||
width: 1, | ||
height: 1, | ||
format: PixelFormat::RGB8, | ||
key: None, | ||
}, | ||
image_data: None, | ||
stretch_size: Size2D::zero(), | ||
tile_spacing: Size2D::zero(), | ||
image_rendering: image_rendering::T::auto, | ||
})); | ||
let display_list = DisplayList { | ||
list: vec![image] | ||
}; | ||
paint_time_metrics.maybe_set_first_contentful_paint(&dummy_profiler_metadata_factory, | ||
&display_list); | ||
assert!(paint_time_metrics.get_first_contentful_paint().is_some(), "first contentful paint is set"); | ||
assert_eq!(paint_time_metrics.get_first_paint(), None, "first paint is None"); | ||
} |