[MediaWiki-commits] [Gerrit] Small clean-ups - change (mediawiki...NavigationTiming)

2015-09-15 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Small clean-ups
..


Small clean-ups

* Fold getPaintTiming() into getNavTiming(). It's less code that way.

* Don't check for window.performance in onLoadComplete and isCompliant, we 
already
  have an alias for that in module scope (timing).

* Remove check for Firefox 7/8. This bug was fixed in 2011 and any stragglers
  in the wild would fail the compliance check anyway.

* Unroll the loop in inCompliant().

* Remove check for mw.now() in emitNavigationTiming. This always exists.

* Remove check for navTiming in emitSaveTiming. It always returns an object.

Change-Id: I62647b284d2728ed05b7d5532b36b1094018c99b
---
M modules/ext.navigationTiming.js
1 file changed, 31 insertions(+), 65 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  Ori.livneh: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js
index 72410cb..5ec6e8d 100644
--- a/modules/ext.navigationTiming.js
+++ b/modules/ext.navigationTiming.js
@@ -23,68 +23,34 @@
return Math.floor( Math.random() * factor ) === 0;
}
 
-   /** Assert that the attribute order complies with the W3C spec. **/
+   /**
+* Assert that the attribute order complies with the W3C spec
+*
+* @return {boolean}
+*/
function isCompliant() {
-   // Tests derived from 
-   var attr, current,
-   last = 0,
-   order = [
-   'loadEventEnd',
-   'loadEventStart',
-   'domContentLoadedEventEnd',
-   'domContentLoadedEventStart',
-   'domInteractive',
-   'responseEnd',
-   'responseStart',
-   'requestStart',
-   'connectEnd',
-   'connectStart'
-   ];
-
-   if ( !timing || !performance ) {
-   // Browser does not implement the Navigation Timing API.
-   return false;
-   }
-
-   if ( /Firefox\/[78]\b/.test( navigator.userAgent ) ) {
-   // The Navigation Timing API is broken in Firefox 7 and 
8 and reports
-   // inaccurate measurements. See 
.
-   return false;
-   }
-
-   while ( ( attr = order.pop() ) !== undefined ) {
-   current = timing[ attr ];
-   if ( current < 0 || current < last ) {
-   return false;
-   }
-   last = current;
-   }
-   return true;
-   }
-
-   function getPaintTiming() {
-   var firstPaint, relativeTo;
-
-   if ( window.chrome && $.isFunction( chrome.loadTimes ) ) {
-   // Chrome
-   firstPaint = chrome.loadTimes().firstPaintTime * 1000;
-   relativeTo = chrome.loadTimes().startLoadTime * 1000;
-   } else if ( timing && timing.msFirstPaint ) {
-   // Internet Explorer 9+ 
()
-   firstPaint = timing.msFirstPaint;
-   relativeTo = timing.navigationStart;
-   }
-
-   if ( firstPaint > relativeTo ) {
-   return { firstPaint: Math.round( firstPaint - 
relativeTo ) };
-   }
+   // Tests derived from
+   // 

+   return (
+   timing  
&&
+   timing.loadEventEnd   >= 
timing.loadEventStart  &&
+   timing.loadEventStart >= 
timing.domContentLoadedEventEnd&&
+   timing.domContentLoadedEventEnd   >= 
timing.domContentLoadedEventStart  &&
+   timing.domContentLoadedEventStart >= 
timing.domInteractive  &&
+   timing.domInteractive >= timing.responseEnd 
&&
+   timing.responseEnd>= 
timing.responseStart   &&
+   timing.responseStart  >= 
timing.requestStart&&
+   timing.requestStart   >= timing.connectEnd  

[MediaWiki-commits] [Gerrit] Small clean-ups - change (mediawiki...NavigationTiming)

2015-09-09 Thread Ori.livneh (Code Review)
Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/237320

Change subject: Small clean-ups
..

Small clean-ups

* Fold getPaintTiming() into getNavTiming(). It's less code that way.
* Don't check for window.timing in onLoadComplete, since we already have an
  alias for that in module scope (timing).
* Remove check for Firefox 7/8. This bug was fixed in 2011 and any stragglers
  in the wild would fail the compliance check anyway.
* Unroll the loop in inCompliant().

Change-Id: I62647b284d2728ed05b7d5532b36b1094018c99b
---
M modules/ext.navigationTiming.js
1 file changed, 20 insertions(+), 58 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NavigationTiming 
refs/changes/20/237320/1

diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js
index 72410cb..74824e1 100644
--- a/modules/ext.navigationTiming.js
+++ b/modules/ext.navigationTiming.js
@@ -27,58 +27,19 @@
function isCompliant() {
// Tests derived from 
-   var attr, current,
-   last = 0,
-   order = [
-   'loadEventEnd',
-   'loadEventStart',
-   'domContentLoadedEventEnd',
-   'domContentLoadedEventStart',
-   'domInteractive',
-   'responseEnd',
-   'responseStart',
-   'requestStart',
-   'connectEnd',
-   'connectStart'
-   ];
-
-   if ( !timing || !performance ) {
-   // Browser does not implement the Navigation Timing API.
-   return false;
-   }
-
-   if ( /Firefox\/[78]\b/.test( navigator.userAgent ) ) {
-   // The Navigation Timing API is broken in Firefox 7 and 
8 and reports
-   // inaccurate measurements. See 
.
-   return false;
-   }
-
-   while ( ( attr = order.pop() ) !== undefined ) {
-   current = timing[ attr ];
-   if ( current < 0 || current < last ) {
-   return false;
-   }
-   last = current;
-   }
-   return true;
-   }
-
-   function getPaintTiming() {
-   var firstPaint, relativeTo;
-
-   if ( window.chrome && $.isFunction( chrome.loadTimes ) ) {
-   // Chrome
-   firstPaint = chrome.loadTimes().firstPaintTime * 1000;
-   relativeTo = chrome.loadTimes().startLoadTime * 1000;
-   } else if ( timing && timing.msFirstPaint ) {
-   // Internet Explorer 9+ 
()
-   firstPaint = timing.msFirstPaint;
-   relativeTo = timing.navigationStart;
-   }
-
-   if ( firstPaint > relativeTo ) {
-   return { firstPaint: Math.round( firstPaint - 
relativeTo ) };
-   }
+   return (
+   timing
+   && timing.loadEventEnd   >= 
timing.loadEventStart
+   && timing.loadEventStart >= 
timing.domContentLoadedEventEnd
+   && timing.domContentLoadedEventEnd   >= 
timing.domContentLoadedEventStart
+   && timing.domContentLoadedEventStart >= 
timing.domInteractive
+   && timing.domInteractive >= 
timing.responseEnd
+   && timing.responseEnd>= 
timing.responseStart
+   && timing.responseStart  >= 
timing.requestStart
+   && timing.requestStart   >= 
timing.connectEnd
+   && timing.connectEnd >= 
timing.connectStart
+   && timing.connectStart   >= 0
+   );
}
 
function getNavTiming() {
@@ -123,7 +84,12 @@
timingData.redirecting = timing.redirectEnd - 
timing.redirectStart;
}
 
-   $.extend( timingData, getPaintTiming() );
+   if ( timing.msFirstPaint > navStart ) {
+   timingData.firstPaint = timing.msFirstPaint - navStart;
+   } else if ( window.chrome && $.isFunction( chrome.loadTimes ) ) 
{
+   timingData.firstPaint = Math.round( 1000 *
+   (