Permalink
Browse files

Auto merge of #22599 - aditj:patch-1-re, r=ferjm

Implement performance interface extension for PerformanceResourceTiming

<!-- Please describe your changes on the following line: -->

(There is a previous closed pull for this #22431)
Implemented the following :
a) Added the maxSize Field to the PerformanceEntryList structure.
b) Implemented the clearResourceTimings, setResourceTimingBufferSize, onresourcetimingbufferfull fuctions for the Performance Structure according to the Interface Specification given at : https://w3c.github.io/resource-timing/#sec-extensions-performance-interface

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #22307 (GitHub issue number if applicable)

<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because ___

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22599)
<!-- Reviewable:end -->
  • Loading branch information...
bors-servo committed Jan 10, 2019
2 parents 61893dd + 3ca8247 commit 106f1377d20b29fd4568423525554e493e1eebd7
Showing with 121 additions and 72 deletions.
  1. +1 −0 components/atoms/static_atoms.txt
  2. +96 −0 components/script/dom/performance.rs
  3. +8 −1 components/script/dom/webidls/Performance.webidl
  4. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-add-after-full-event.html.ini
  5. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-add-entries-during-callback-that-drop.html.ini
  6. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-add-entries-during-callback.html.ini
  7. +0 −1 tests/wpt/metadata/resource-timing/buffer-full-add-then-clear.html.ini
  8. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-decrease-buffer-during-callback.html.ini
  9. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-increase-buffer-during-callback.html.ini
  10. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-inspect-buffer-during-callback.html.ini
  11. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-set-to-current-buffer.html.ini
  12. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-store-and-clear-during-callback.html.ini
  13. +0 −1 tests/wpt/metadata/resource-timing/buffer-full-then-increased.html.ini
  14. +1 −1 tests/wpt/metadata/resource-timing/buffer-full-when-populate-entries.html.ini
  15. +0 −1 tests/wpt/metadata/resource-timing/clear_resource_timing_functionality.html.ini
  16. +0 −42 tests/wpt/metadata/resource-timing/idlharness.any.js.ini
  17. +0 −1 tests/wpt/metadata/resource-timing/resource_memory_cached.sub.html.ini
  18. +5 −4 tests/wpt/metadata/resource-timing/resource_subframe_self_navigation.html.ini
  19. +2 −1 tests/wpt/metadata/resource-timing/resource_timing.worker.js.ini
  20. +0 −5 tests/wpt/metadata/resource-timing/resource_timing_buffer_full_eventually.html.ini
  21. +0 −6 tests/wpt/metadata/workers/worker-performance.worker.js.ini
@@ -75,6 +75,7 @@ rejectionhandled
removetrack
reset
resize
resourcetimingbufferfull
right
rtl
sans-serif
@@ -26,6 +26,7 @@ use dom_struct::dom_struct;
use metrics::ToMs;
use std::cell::Cell;
use std::cmp::Ordering;
use std::collections::VecDeque;

const INVALID_ENTRY_NAMES: &'static [&'static str] = &[
"navigationStart",
@@ -139,6 +140,10 @@ pub struct Performance {
observers: DomRefCell<Vec<PerformanceObserver>>,
pending_notification_observers_task: Cell<bool>,
navigation_start_precise: u64,
resource_timing_buffer_size_limit: Cell<usize>,
resource_timing_buffer_current_size: Cell<usize>,
resource_timing_buffer_pending_full_event: Cell<bool>,
resource_timing_secondary_entries: DomRefCell<VecDeque<DomRoot<PerformanceEntry>>>,
}

impl Performance {
@@ -149,6 +154,10 @@ impl Performance {
observers: DomRefCell::new(Vec::new()),
pending_notification_observers_task: Cell::new(false),
navigation_start_precise,
resource_timing_buffer_size_limit: Cell::new(250),
resource_timing_buffer_current_size: Cell::new(0),
resource_timing_buffer_pending_full_event: Cell::new(false),
resource_timing_secondary_entries: DomRefCell::new(VecDeque::new()),
}
}

@@ -208,7 +217,13 @@ impl Performance {
///
/// Algorithm spec:
/// <https://w3c.github.io/performance-timeline/#queue-a-performanceentry>
/// Also this algorithm has been extented according to :
/// <https://w3c.github.io/resource-timing/#sec-extensions-performance-interface>
pub fn queue_entry(&self, entry: &PerformanceEntry, add_to_performance_entries_buffer: bool) {
if entry.entry_type() == "resource" && !self.should_queue_resource_entry(entry) {
return;
}

// Steps 1-3.
// Add the performance entry to the list of performance entries that have not
// been notified to each performance observer owner, filtering the ones it's
@@ -279,6 +294,67 @@ impl Performance {
fn now(&self) -> f64 {
(time::precise_time_ns() - self.navigation_start_precise).to_ms()
}

fn can_add_resource_timing_entry(&self) -> bool {
self.resource_timing_buffer_current_size.get() <=
self.resource_timing_buffer_size_limit.get()
}
fn copy_secondary_resource_timing_buffer(&self) {
while self.can_add_resource_timing_entry() {
let entry = self
.resource_timing_secondary_entries
.borrow_mut()
.pop_front();
if let Some(ref entry) = entry {
self.queue_entry(entry, true);
} else {
break;
}
}
}
// `fire a buffer full event` paragraph of
// https://w3c.github.io/resource-timing/#sec-extensions-performance-interface
fn fire_buffer_full_event(&self) {
while !self.resource_timing_secondary_entries.borrow().is_empty() {
let no_of_excess_entries_before = self.resource_timing_secondary_entries.borrow().len();

if !self.can_add_resource_timing_entry() {
self.upcast::<EventTarget>()
.fire_event(atom!("resourcetimingbufferfull"));
}
self.copy_secondary_resource_timing_buffer();
let no_of_excess_entries_after = self.resource_timing_secondary_entries.borrow().len();
if no_of_excess_entries_before <= no_of_excess_entries_after {
self.resource_timing_secondary_entries.borrow_mut().clear();
break;
}
}
self.resource_timing_buffer_pending_full_event.set(false);
}
/// `add a PerformanceResourceTiming entry` paragraph of
/// https://w3c.github.io/resource-timing/#sec-extensions-performance-interface
fn should_queue_resource_entry(&self, entry: &PerformanceEntry) -> bool {
// Step 1 is done in the args list.
if !self.resource_timing_buffer_pending_full_event.get() {
// Step 2.
if self.can_add_resource_timing_entry() {
// Step 2.a is done in `queue_entry`
// Step 2.b.
self.resource_timing_buffer_current_size
.set(self.resource_timing_buffer_current_size.get() + 1);
// Step 2.c.
return true;
}
// Step 3.
self.resource_timing_buffer_pending_full_event.set(true);
self.fire_buffer_full_event();
}
// Steps 4 and 5.
self.resource_timing_secondary_entries
.borrow_mut()
.push_back(DomRoot::from_ref(entry));
false
}
}

impl PerformanceMethods for Performance {
@@ -407,4 +483,24 @@ impl PerformanceMethods for Performance {
.borrow_mut()
.clear_entries_by_name_and_type(measure_name, Some(DOMString::from("measure")));
}
// https://w3c.github.io/resource-timing/#dom-performance-clearresourcetimings
fn ClearResourceTimings(&self) {
self.entries
.borrow_mut()
.clear_entries_by_name_and_type(None, Some(DOMString::from("resource")));
self.resource_timing_buffer_current_size.set(0);
}

// https://w3c.github.io/resource-timing/#dom-performance-setresourcetimingbuffersize
fn SetResourceTimingBufferSize(&self, max_size: u32) {
self.resource_timing_buffer_size_limit
.set(max_size as usize);
}

// https://w3c.github.io/resource-timing/#dom-performance-onresourcetimingbufferfull
event_handler!(
resourcetimingbufferfull,
GetOnresourcetimingbufferfull,
SetOnresourcetimingbufferfull
);
}
@@ -34,8 +34,15 @@ partial interface Performance {
[Throws]
void measure(DOMString measureName, optional DOMString startMark, optional DOMString endMark);
void clearMeasures(optional DOMString measureName);
};


};
//https://w3c.github.io/resource-timing/#sec-extensions-performance-interface
partial interface Performance {
void clearResourceTimings ();
void setResourceTimingBufferSize (unsigned long maxSize);
attribute EventHandler onresourcetimingbufferfull;
};
// FIXME(avada): this should be deprecated, but is currently included for web compat
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html#performance-timing-attribute
[Exposed=(Window)]
@@ -1,5 +1,5 @@
[buffer-full-add-after-full-event.html]
expected: ERROR
expected: TIMEOUT
[Test that entry was added to the buffer after a buffer full event]
expected: TIMEOUT

@@ -1,5 +1,5 @@
[buffer-full-add-entries-during-callback-that-drop.html]
expected: ERROR
expected: TIMEOUT
[Test that entries synchronously added to the buffer during the callback are dropped]
expected: TIMEOUT

@@ -1,5 +1,5 @@
[buffer-full-add-entries-during-callback.html]
expected: ERROR
expected: TIMEOUT
[Test that entries synchronously added to the buffer during the callback don't get dropped if the buffer is increased]
expected: TIMEOUT
@@ -1,5 +1,4 @@
[buffer-full-add-then-clear.html]
expected: ERROR
[Test that if the buffer is cleared after entries were added to the secondary buffer, those entries make it into the primary one]
expected: FAIL

@@ -1,5 +1,5 @@
[buffer-full-decrease-buffer-during-callback.html]
expected: ERROR
expected: TIMEOUT
[Test that decreasing the buffer limit during the callback does not drop entries]
expected: TIMEOUT

@@ -1,5 +1,5 @@
[buffer-full-increase-buffer-during-callback.html]
expected: ERROR
expected: TIMEOUT
[Test that increasing the buffer during the callback is enough for entries not to be dropped]
expected: TIMEOUT

@@ -1,5 +1,5 @@
[buffer-full-inspect-buffer-during-callback.html]
expected: ERROR
expected: TIMEOUT
[Test that entries in the secondary buffer are not exposed during the callback and before they are copied to the primary buffer]
expected: TIMEOUT

@@ -1,5 +1,5 @@
[buffer-full-set-to-current-buffer.html]
expected: ERROR
expected: TIMEOUT
[Test that entries added and event firing happened in the right sequence]
expected: TIMEOUT

@@ -1,5 +1,5 @@
[buffer-full-store-and-clear-during-callback.html]
expected: ERROR
expected: TIMEOUT
[Test that entries overflowing the buffer trigger the buffer full event, can be stored, and find themselves in the primary buffer after it's cleared.]
expected: TIMEOUT
@@ -1,5 +1,4 @@
[buffer-full-then-increased.html]
expected: ERROR
[Test that overflowing the buffer and immediately increasing its limit does not trigger the resourcetimingbufferfull event]
expected: FAIL

@@ -1,5 +1,5 @@
[buffer-full-when-populate-entries.html]
expected: ERROR
expected: TIMEOUT
[Test that a buffer full event does not bubble and that resourcetimingbufferfull is called only once per overflow]
expected: TIMEOUT

@@ -1,5 +1,4 @@
[clear_resource_timing_functionality.html]
expected: ERROR
[4 resource timing entries should be stored in this page.]
expected: FAIL

@@ -38,15 +38,9 @@
[PerformanceResourceTiming interface: attribute responseEnd]
expected: FAIL

[Performance interface: operation setResourceTimingBufferSize(unsigned long)]
expected: FAIL

[PerformanceResourceTiming interface: attribute secureConnectionStart]
expected: FAIL

[Performance interface: calling setResourceTimingBufferSize(unsigned long) on performance with too few arguments must throw TypeError]
expected: FAIL

[PerformanceResourceTiming interface: attribute fetchStart]
expected: FAIL

@@ -71,21 +65,9 @@
[PerformanceResourceTiming interface: attribute connectStart]
expected: FAIL

[Performance interface: operation clearResourceTimings()]
expected: FAIL

[PerformanceResourceTiming interface: resource must inherit property "responseEnd" with the proper type]
expected: FAIL

[Performance interface: performance must inherit property "onresourcetimingbufferfull" with the proper type]
expected: FAIL

[Performance interface: performance must inherit property "setResourceTimingBufferSize(unsigned long)" with the proper type]
expected: FAIL

[Performance interface: attribute onresourcetimingbufferfull]
expected: FAIL

[PerformanceResourceTiming interface: attribute connectEnd]
expected: FAIL

@@ -98,9 +80,6 @@
[PerformanceResourceTiming interface: resource must inherit property "domainLookupEnd" with the proper type]
expected: FAIL

[Performance interface: performance must inherit property "clearResourceTimings()" with the proper type]
expected: FAIL

[PerformanceResourceTiming interface: attribute domainLookupEnd]
expected: FAIL

@@ -193,15 +172,9 @@
[PerformanceResourceTiming interface: attribute responseEnd]
expected: FAIL

[Performance interface: operation setResourceTimingBufferSize(unsigned long)]
expected: FAIL

[PerformanceResourceTiming interface: attribute secureConnectionStart]
expected: FAIL

[Performance interface: calling setResourceTimingBufferSize(unsigned long) on performance with too few arguments must throw TypeError]
expected: FAIL

[PerformanceResourceTiming interface: attribute fetchStart]
expected: FAIL

@@ -214,27 +187,12 @@
[PerformanceResourceTiming interface: attribute connectStart]
expected: FAIL

[Performance interface: operation clearResourceTimings()]
expected: FAIL

[Performance interface: performance must inherit property "onresourcetimingbufferfull" with the proper type]
expected: FAIL

[Performance interface: performance must inherit property "setResourceTimingBufferSize(unsigned long)" with the proper type]
expected: FAIL

[Performance interface: attribute onresourcetimingbufferfull]
expected: FAIL

[PerformanceResourceTiming interface: attribute connectEnd]
expected: FAIL

[PerformanceResourceTiming interface: attribute redirectEnd]
expected: FAIL

[Performance interface: performance must inherit property "clearResourceTimings()" with the proper type]
expected: FAIL

[PerformanceResourceTiming interface: attribute domainLookupEnd]
expected: FAIL

@@ -1,5 +1,4 @@
[resource_memory_cached.sub.html]
expected: ERROR
[http://web-platform.test:8000/resource-timing/resources/blue.png?id=cached is expected to be in the Resource Timing buffer]
expected: FAIL

@@ -1,13 +1,14 @@
[resource_subframe_self_navigation.html]
expected: TIMEOUT
[Subsequent <iframe> navigations don't appear in the resource-timing buffer.]
expected: FAIL
expected: TIMEOUT
[Subsequent <frame> navigations don't appear in the resource-timing buffer.]
expected: FAIL
expected: NOTRUN

[Subsequent <embed> navigations don't appear in the resource-timing buffer.]
expected: FAIL
expected: NOTRUN
[Subsequent <object> navigations don't appear in the resource-timing buffer.]
expected: FAIL
expected: NOTRUN

@@ -1,7 +1,8 @@
[resource_timing.worker.html]
expected: TIMEOUT
[Performance Resouce Entries in workers]
expected: FAIL

[Performance Resource Entries in workers]
expected: FAIL
expected: TIMEOUT

This file was deleted.

Oops, something went wrong.
@@ -12,12 +12,6 @@
[Resource timing seems to work in workers]
expected: FAIL

[performance.clearResourceTimings in workers]
expected: FAIL

[performance.setResourceTimingBufferSize in workers]
expected: FAIL

[performance.timing is not available in workers]
expected: FAIL

0 comments on commit 106f137

Please sign in to comment.