aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFernando Jiménez Moreno <ferjmoreno@gmail.com>2017-07-21 14:58:30 +0200
committerFernando Jiménez Moreno <ferjmoreno@gmail.com>2017-07-21 15:10:04 +0200
commit585d0e52aff86fd02e8a76b8f4ca380d48c18c23 (patch)
treefe1b3fa544f3ad061139a8e4ec1ea8dd10c9ad33
parent06b409ad603688658815fd1a71a02fd03cd5094a (diff)
downloadservo-585d0e52aff86fd02e8a76b8f4ca380d48c18c23.tar.gz
servo-585d0e52aff86fd02e8a76b8f4ca380d48c18c23.zip
PWM tests
-rw-r--r--Cargo.lock16
-rw-r--r--components/metrics/lib.rs12
-rw-r--r--ports/servo/Cargo.toml1
-rw-r--r--tests/unit/metrics/Cargo.toml21
-rw-r--r--tests/unit/metrics/lib.rs16
-rw-r--r--tests/unit/metrics/paint_time.rs100
6 files changed, 166 insertions, 0 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 988fab13cae..b5f6aaa139e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1708,6 +1708,21 @@ dependencies = [
]
[[package]]
+name = "metrics_tests"
+version = "0.0.1"
+dependencies = [
+ "euclid 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "gfx 0.0.1",
+ "ipc-channel 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "metrics 0.0.1",
+ "msg 0.0.1",
+ "net_traits 0.0.1",
+ "profile_traits 0.0.1",
+ "style 0.0.1",
+ "time 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "mime"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -2666,6 +2681,7 @@ dependencies = [
"layout_tests 0.0.1",
"libservo 0.0.1",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
+ "metrics_tests 0.0.1",
"net_tests 0.0.1",
"net_traits_tests 0.0.1",
"plugin_compiletest 0.0.1",
diff --git a/components/metrics/lib.rs b/components/metrics/lib.rs
index 98773a1d205..0cbf703a1ec 100644
--- a/components/metrics/lib.rs
+++ b/components/metrics/lib.rs
@@ -110,4 +110,16 @@ impl PaintTimeMetrics {
}
}
}
+
+ pub fn get_navigation_start(&self) -> Option<f64> {
+ self.navigation_start
+ }
+
+ pub fn get_first_paint(&self) -> Option<f64> {
+ self.first_paint.get()
+ }
+
+ pub fn get_first_contentful_paint(&self) -> Option<f64> {
+ self.first_contentful_paint.get()
+ }
}
diff --git a/ports/servo/Cargo.toml b/ports/servo/Cargo.toml
index a25833c5bf4..d8a2e609adf 100644
--- a/ports/servo/Cargo.toml
+++ b/ports/servo/Cargo.toml
@@ -17,6 +17,7 @@ bench = false
compiletest_helper = {path = "../../tests/compiletest/helper"}
gfx_tests = {path = "../../tests/unit/gfx"}
layout_tests = {path = "../../tests/unit/layout"}
+metrics_tests = {path = "../../tests/unit/metrics"}
net_tests = {path = "../../tests/unit/net"}
net_traits_tests = {path = "../../tests/unit/net_traits"}
plugin_compiletest = {path = "../../tests/compiletest/plugin"}
diff --git a/tests/unit/metrics/Cargo.toml b/tests/unit/metrics/Cargo.toml
new file mode 100644
index 00000000000..24b8dd52109
--- /dev/null
+++ b/tests/unit/metrics/Cargo.toml
@@ -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"
diff --git a/tests/unit/metrics/lib.rs b/tests/unit/metrics/lib.rs
new file mode 100644
index 00000000000..4a6e9889735
--- /dev/null
+++ b/tests/unit/metrics/lib.rs
@@ -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;
diff --git a/tests/unit/metrics/paint_time.rs b/tests/unit/metrics/paint_time.rs
new file mode 100644
index 00000000000..fd28a7e891b
--- /dev/null
+++ b/tests/unit/metrics/paint_time.rs
@@ -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");
+}