Imarlier has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/396279 )
Change subject: ext.NavigationTiming: Include Network Information in NavTiming events ...................................................................... ext.NavigationTiming: Include Network Information in NavTiming events This adds properties from the Network Information API[1] to the events that we receive from the NavigationTiming extension. Though this is not a W3C standard, it is now supported in Chrome, and as supporting it has little cost it seems like we may as well. As written, this depends on two other open NavTiming extension reviews (T182262, T181413). There's no rush on this particular item so I don't see a reason not to just wait until they're ready to go for this one to go out. Bug: T182361 [1] http://wicg.github.io/netinfo/ Change-Id: I61c8dbe7fd8a1e02db5c41f732af73e6a3bd30b5 --- M extension.json M modules/ext.navigationTiming.js M tests/ext.navigationTiming.test.js 3 files changed, 92 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/NavigationTiming refs/changes/79/396279/1 diff --git a/extension.json b/extension.json index 44e15f8..49d38a3 100644 --- a/extension.json +++ b/extension.json @@ -49,7 +49,7 @@ ] }, "EventLoggingSchemas": { - "NavigationTiming": 17490599, + "NavigationTiming": 17521327, "SaveTiming": 15396492 }, "config": { diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js index b94b219..307c171 100644 --- a/modules/ext.navigationTiming.js +++ b/modules/ext.navigationTiming.js @@ -245,6 +245,27 @@ } } + if ( navigator.connection ) { + if ( typeof navigator.connection.type === 'string' ) { + event.connectionType = navigator.connection.type; + } + if ( typeof navigator.connection.effectiveType === 'string' ) { + event.effectiveConnectionType = navigator.connection.effectiveType; + } + if ( typeof navigator.connection.downlinkMax === 'number' ) { + event.downlinkMax = navigator.connection.downlinkMax; + } + if ( typeof navigator.connection.downlink === 'number' ) { + event.downlink = navigator.connection.downlink; + } + if ( typeof navigator.connection.rtt === 'number' ) { + event.rtt = navigator.connection.rtt; + } + if ( typeof navigator.connection.saveData === 'boolean' ) { + event.saveData = navigator.connection.saveData; + } + } + // Omit page information for special pages: they don't have real page // IDs or revisions. (They appear as 0 to client-side code.) if ( !isSpecialPage ) { diff --git a/tests/ext.navigationTiming.test.js b/tests/ext.navigationTiming.test.js index 682bf48..44de640 100644 --- a/tests/ext.navigationTiming.test.js +++ b/tests/ext.navigationTiming.test.js @@ -29,7 +29,8 @@ this.navigator = Object.getOwnPropertyDescriptor( window, 'navigator' ) || {}; delete window.navigator; window.navigator = { - userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.12345.94 Safari/537.36' + userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.12345.94 Safari/537.36', + connection: {} }; }, @@ -270,6 +271,74 @@ } } ); + // Case where browser exposes the Network Information API + QUnit.test( 'Network Information API', function ( assert ) { + var logEventStub, event, expected, key, type, val; + + logEventStub = this.sandbox.stub( mw.eventLog, 'logEvent' ); + + this.sandbox.stub( window, 'performance', { + timing: performance.timing, + navigation: { + type: 0, + redirectCount: 0 + } + } ); + this.sandbox.stub( navigator, 'connection', { + type: 'wifi', + effectiveType: '4g', + downlinkMax: 1000, + downlink: 100, + rtt: 30, + saveData: false + } ); + + navigationTiming.reinit(); + navigationTiming.emitNavTiming(); + assert.ok( logEventStub.calledOnce, 'mw.eventLog.logEvent was called once' ); + assert.equal( logEventStub.getCall( 0 ).args[ 0 ], 'NavigationTiming', 'Schema name' ); + event = logEventStub.getCall( 0 ).args[ 1 ]; + + expected = { + // Base + isAnon: 'boolean', + isHiDPI: 'boolean', + isHttp2: 'boolean', + isOversample: 'boolean', + mediaWikiVersion: [ 'string', mw.config.get( 'wgVersion' ) ], + + // ResourceLoader + mediaWikiLoadComplete: 'number', + + // Navigation Timing + responseStart: 'number', + domComplete: 'number', + loadEventEnd: 'number', + + // Network Information + connectionType: 'string', + effectiveConnectionType: 'string', + downlinkMax: 'number', + downlink: 'number', + rtt: 'number', + saveData: 'boolean' + }; + + for ( key in expected ) { + if ( Array.isArray( expected[ key ] ) ) { + type = expected[ key ][ 0 ]; + val = expected[ key ][ 1 ]; + } else { + type = expected[ key ]; + val = undefined; + } + assert.strictEqual( typeof event[ key ], type, 'Type of event property: ' + key ); + if ( val !== undefined ) { + assert.strictEqual( event[ key ], val, 'Value of event property: ' + key ); + } + } + } ); + QUnit.test( 'Asia (old)', function ( assert ) { var stub = this.sandbox.stub( mw, 'track' ); -- To view, visit https://gerrit.wikimedia.org/r/396279 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I61c8dbe7fd8a1e02db5c41f732af73e6a3bd30b5 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/NavigationTiming Gerrit-Branch: master Gerrit-Owner: Imarlier <imarl...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits