This is a sticky version of generateRandomSessionId,
useful to keep track of the pageview between extensions.
Bug: T187299
Change-Id: I0877c399c60d3fb2fdf8e844cad6acecf6f704c9
*/
/* global Uint32Array */
( function ( mw, $ ) {
*/
/* global Uint32Array */
( function ( mw, $ ) {
+ var userInfoPromise, stickyRandomSessionId;
/**
* Get the current user's groups or rights
/**
* Get the current user's groups or rights
// Support: IE 11
crypto = window.crypto || window.msCrypto;
// Support: IE 11
crypto = window.crypto || window.msCrypto;
- if ( crypto && crypto.getRandomValues ) {
+ if ( crypto && crypto.getRandomValues && typeof Uint32Array === 'function' ) {
// Fill an array with 2 random values, each of which is 32 bits.
// Note that Uint32Array is array-like but does not implement Array.
rnds = new Uint32Array( 2 );
// Fill an array with 2 random values, each of which is 32 bits.
// Note that Uint32Array is array-like but does not implement Array.
rnds = new Uint32Array( 2 );
return hexRnds.join( '' );
},
return hexRnds.join( '' );
},
+ /**
+ * A sticky generateRandomSessionId for the current JS execution context,
+ * cached within this class.
+ *
+ * @return {string} 64 bit integer in hex format, padded
+ */
+ stickyRandomId: function () {
+ if ( !stickyRandomSessionId ) {
+ stickyRandomSessionId = mw.user.generateRandomSessionId();
+ }
+
+ return stickyRandomSessionId;
+ },
+
/**
* Get the current user's database id
*
/**
* Get the current user's database id
*
assert.notEqual( result, result2, 'different when called multiple times' );
} );
assert.notEqual( result, result2, 'different when called multiple times' );
} );
+ QUnit.test( 'stickyRandomId', function ( assert ) {
+ var result = mw.user.stickyRandomId(),
+ result2 = mw.user.stickyRandomId();
+ assert.equal( typeof result, 'string', 'type' );
+ assert.strictEqual( /^[a-f0-9]{16}$/.test( result ), true, '16 HEX symbols string' );
+ assert.equal( result2, result, 'sticky' );
+ } );
+
QUnit.test( 'sessionId', function ( assert ) {
var result = mw.user.sessionId(),
result2 = mw.user.sessionId();
QUnit.test( 'sessionId', function ( assert ) {
var result = mw.user.sessionId(),
result2 = mw.user.sessionId();