Merge "Use NumberInputWidget in HTMLFloatField"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 12 Sep 2018 16:08:48 +0000 (16:08 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 12 Sep 2018 16:08:48 +0000 (16:08 +0000)
maintenance/includes/DeleteLocalPasswords.php
resources/src/startup/.eslintrc.json [new file with mode: 0644]
resources/src/startup/mediawiki.js
resources/src/startup/mediawiki.log.js
resources/src/startup/mediawiki.requestIdleCallback.js
resources/src/startup/profiler.js
resources/src/startup/startup.js
tests/qunit/suites/resources/mediawiki/mediawiki.loader.test.js

index e3f8926..bfbbcdc 100644 (file)
@@ -157,7 +157,7 @@ ERROR
        protected function getUserBatches() {
                if ( !is_null( $this->user ) ) {
                        $this->output( "\t ... querying '$this->user'\n" );
-                       yield [ $this->user ];
+                       yield [ [ $this->user ] ];
                        return;
                }
 
diff --git a/resources/src/startup/.eslintrc.json b/resources/src/startup/.eslintrc.json
new file mode 100644 (file)
index 0000000..c085e60
--- /dev/null
@@ -0,0 +1,10 @@
+{
+       "root": true,
+       "extends": "wikimedia",
+       "env": {
+               "browser": true
+       },
+       "rules": {
+               "max-len": 0
+       }
+}
index 57ac43c..ba8869b 100644 (file)
                /**
                 * Get the current time, measured in milliseconds since January 1, 1970 (UTC).
                 *
-                * On browsers that implement the Navigation Timing API, this function will produce floating-point
-                * values with microsecond precision that are guaranteed to be monotonic. On all other browsers,
-                * it will fall back to using `Date`.
+                * On browsers that implement the Navigation Timing API, this function will produce
+                * floating-point values with microsecond precision that are guaranteed to be monotonic.
+                * On all other browsers, it will fall back to using `Date`.
                 *
                 * @return {number} Current time
                 */
-               now: ( function () {
+               now: function () {
+                       // Optimisation: Define the shortcut on first call, not at module definition.
                        var perf = window.performance,
                                navStart = perf && perf.timing && perf.timing.navigationStart;
-                       return navStart && typeof perf.now === 'function' ?
+
+                       // Define the relevant shortcut
+                       mw.now = navStart && typeof perf.now === 'function' ?
                                function () { return navStart + perf.now(); } :
-                               function () { return Date.now(); };
-               }() ),
+                               Date.now;
+
+                       return mw.now();
+               },
 
                /**
                 * List of all analytic events emitted so far.
index af59c7f..9283b16 100644 (file)
@@ -7,7 +7,7 @@
  * @author Trevor Parscal <tparscal@wikimedia.org>
  */
 ( function () {
-       /* global console */
+       /* global console, mw */
        /* eslint-disable no-console */
        var original = mw.log;
 
index 9f8c598..afb4737 100644 (file)
@@ -1,3 +1,4 @@
+/* global mw */
 ( function () {
        var maxBusy = 50;
 
@@ -44,7 +45,8 @@
         *  by that time.
         */
        mw.requestIdleCallback = window.requestIdleCallback ?
-               window.requestIdleCallback.bind( window ) : // Bind because it throws TypeError if context is not window
+               // Bind because it throws TypeError if context is not window
+               window.requestIdleCallback.bind( window ) :
                mw.requestIdleCallbackInternal;
        // Note: Polyfill was previously disabled due to
        // https://bugs.chromium.org/p/chromium/issues/detail?id=647870
index 588750c..5e9b6ab 100644 (file)
@@ -4,6 +4,7 @@
  * @author Timo Tijhof
  * @since 1.32
  */
+/* global mw */
 ( function () {
        'use strict';
 
index 8e75535..5483ad2 100644 (file)
@@ -110,6 +110,7 @@ if ( !isCompatible() ) {
         * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
         */
        ( function () {
+               /* global mw */
                mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals );
 
                $CODE.registrations();
index 677905f..3a48e6e 100644 (file)
@@ -5,6 +5,14 @@
                        mw.loader.testFail = function ( reason ) {
                                assert.ok( false, reason );
                        };
+
+                       this.useStubClock = function () {
+                               this.clock = this.sandbox.useFakeTimers();
+                               this.tick = function ( forward ) {
+                                       return this.clock.tick( forward || 1 );
+                               };
+                               this.sandbox.stub( mw, 'requestIdleCallback', mw.requestIdleCallbackInternal );
+                       };
                },
                teardown: function () {
                        // Teardown for StringSet shim test
 
        QUnit.test( '.implement( only scripts )', function ( assert ) {
                mw.loader.implement( 'test.onlyscripts', function () {} );
-               assert.strictEqual( mw.loader.getState( 'test.onlyscripts' ), 'ready' );
+               return mw.loader.using( 'test.onlyscripts', function () {
+                       assert.strictEqual( mw.loader.getState( 'test.onlyscripts' ), 'ready' );
+               } );
        } );
 
        QUnit.test( '.implement( only messages )', function ( assert ) {
 
        QUnit.test( '.implement( empty )', function ( assert ) {
                mw.loader.implement( 'test.empty' );
-               assert.strictEqual( mw.loader.getState( 'test.empty' ), 'ready' );
+               return mw.loader.using( 'test.empty', function () {
+                       assert.strictEqual( mw.loader.getState( 'test.empty' ), 'ready' );
+               } );
        } );
 
        QUnit.test( '.addSource()', function ( assert ) {
        } );
 
        QUnit.test( 'Broken indirect dependency', function ( assert ) {
-               // don't emit an error event
+               this.useStubClock();
+
+               // Don't actually emit an error event
                this.sandbox.stub( mw, 'track' );
 
                mw.loader.register( [
                mw.loader.implement( 'test.module1', function () {
                        throw new Error( 'expected' );
                }, {}, {} );
+               this.tick();
+
                assert.strictEqual( mw.loader.getState( 'test.module1' ), 'error', 'Expected "error" state for test.module1' );
                assert.strictEqual( mw.loader.getState( 'test.module2' ), 'error', 'Expected "error" state for test.module2' );
                assert.strictEqual( mw.loader.getState( 'test.module3' ), 'error', 'Expected "error" state for test.module3' );
        } );
 
        QUnit.test( 'Out-of-order implementation', function ( assert ) {
+               this.useStubClock();
+
                mw.loader.register( [
                        [ 'test.module4', '0' ],
                        [ 'test.module5', '0', [ 'test.module4' ] ],
                        [ 'test.module6', '0', [ 'test.module5' ] ]
                ] );
+
                mw.loader.implement( 'test.module4', function () {} );
+               this.tick();
                assert.strictEqual( mw.loader.getState( 'test.module4' ), 'ready', 'Expected "ready" state for test.module4' );
                assert.strictEqual( mw.loader.getState( 'test.module5' ), 'registered', 'Expected "registered" state for test.module5' );
                assert.strictEqual( mw.loader.getState( 'test.module6' ), 'registered', 'Expected "registered" state for test.module6' );
+
                mw.loader.implement( 'test.module6', function () {} );
+               this.tick();
                assert.strictEqual( mw.loader.getState( 'test.module4' ), 'ready', 'Expected "ready" state for test.module4' );
                assert.strictEqual( mw.loader.getState( 'test.module5' ), 'registered', 'Expected "registered" state for test.module5' );
                assert.strictEqual( mw.loader.getState( 'test.module6' ), 'loaded', 'Expected "loaded" state for test.module6' );
+
                mw.loader.implement( 'test.module5', function () {} );
+               this.tick();
                assert.strictEqual( mw.loader.getState( 'test.module4' ), 'ready', 'Expected "ready" state for test.module4' );
                assert.strictEqual( mw.loader.getState( 'test.module5' ), 'ready', 'Expected "ready" state for test.module5' );
                assert.strictEqual( mw.loader.getState( 'test.module6' ), 'ready', 'Expected "ready" state for test.module6' );
        } );
 
        QUnit.test( 'Missing dependency', function ( assert ) {
+               this.useStubClock();
+
                mw.loader.register( [
                        [ 'test.module7', '0' ],
                        [ 'test.module8', '0', [ 'test.module7' ] ],
                        [ 'test.module9', '0', [ 'test.module8' ] ]
                ] );
+
                mw.loader.implement( 'test.module8', function () {} );
+               this.tick();
                assert.strictEqual( mw.loader.getState( 'test.module7' ), 'registered', 'Expected "registered" state for test.module7' );
                assert.strictEqual( mw.loader.getState( 'test.module8' ), 'loaded', 'Expected "loaded" state for test.module8' );
                assert.strictEqual( mw.loader.getState( 'test.module9' ), 'registered', 'Expected "registered" state for test.module9' );
+
                mw.loader.state( { 'test.module7': 'missing' } );
+               this.tick();
                assert.strictEqual( mw.loader.getState( 'test.module7' ), 'missing', 'Expected "missing" state for test.module7' );
                assert.strictEqual( mw.loader.getState( 'test.module8' ), 'error', 'Expected "error" state for test.module8' );
                assert.strictEqual( mw.loader.getState( 'test.module9' ), 'error', 'Expected "error" state for test.module9' );
+
                mw.loader.implement( 'test.module9', function () {} );
+               this.tick();
                assert.strictEqual( mw.loader.getState( 'test.module7' ), 'missing', 'Expected "missing" state for test.module7' );
                assert.strictEqual( mw.loader.getState( 'test.module8' ), 'error', 'Expected "error" state for test.module8' );
                assert.strictEqual( mw.loader.getState( 'test.module9' ), 'error', 'Expected "error" state for test.module9' );
-               mw.loader.using(
-                       [ 'test.module7' ],
+
+               // Restore clock for QUnit and $.Deferred internals
+               this.clock.restore();
+               return mw.loader.using( [ 'test.module7' ] ).then(
                        function () {
-                               assert.ok( false, 'Success fired despite missing dependency' );
-                               assert.ok( true, 'QUnit expected() count dummy' );
+                               throw new Error( 'Success fired despite missing dependency' );
                        },
                        function ( e, dependencies ) {
                                assert.strictEqual( Array.isArray( dependencies ), true, 'Expected array of dependencies' );
                                        'Error callback called with module test.module7'
                                );
                        }
-               );
-               mw.loader.using(
-                       [ 'test.module9' ],
+               ).then( function () {
+                       return mw.loader.using( [ 'test.module9' ] );
+               } ).then(
                        function () {
-                               assert.ok( false, 'Success fired despite missing dependency' );
-                               assert.ok( true, 'QUnit expected() count dummy' );
+                               throw new Error( 'Success fired despite missing dependency' );
                        },
                        function ( e, dependencies ) {
                                assert.strictEqual( Array.isArray( dependencies ), true, 'Expected array of dependencies' );
        } );
 
        QUnit.test( 'Dependency handling', function ( assert ) {
-               var done = assert.async();
                mw.loader.register( [
                        // [module, version, dependencies, group, source]
                        [ 'testMissing', '1', [], null, 'testloader' ],
                        assert.strictEqual( mw.loader.getState( 'testUsesNestedMissing' ), 'error', 'Module "testUsesNestedMissing" state' );
                }
 
-               mw.loader.using( [ 'testUsesNestedMissing' ],
+               return mw.loader.using( [ 'testUsesNestedMissing' ] ).then(
                        function () {
-                               assert.ok( false, 'Error handler should be invoked.' );
-                               assert.ok( true ); // Dummy to reach QUnit expect()
-
                                verifyModuleStates();
-
-                               done();
+                               throw new Error( 'Error handler should be invoked.' );
                        },
-                       function ( e, badmodules ) {
-                               assert.ok( true, 'Error handler should be invoked.' );
-                               // As soon as server sets state of 'testMissing' to 'missing'
-                               // it will bubble up and trigger the error callback.
-                               // Therefor the badmodules array is not testUsesMissing or testUsesNestedMissing.
-                               assert.deepEqual( badmodules, [ 'testMissing' ], 'Bad modules as expected.' );
+                       function ( e, modules ) {
+                               // When the server sets state of 'testMissing' to 'missing'
+                               // it should bubble up and trigger the error callback of the job for 'testUsesNestedMissing'.
+                               assert.strictEqual( modules.indexOf( 'testMissing' ) !== -1, true, 'Triggered by testMissing.' );
 
                                verifyModuleStates();
-
-                               done();
                        }
                );
        } );