Merge "RCFilters UI: Adjust popup positioning again"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.loader.test.js
index 92ee7dd..477b04d 100644 (file)
@@ -5,6 +5,11 @@
                },
                teardown: function () {
                        mw.loader.store.enabled = false;
+                       // Teardown for StringSet shim test
+                       if ( this.nativeSet ) {
+                               window.Set = this.nativeSet;
+                               mw.redefineFallbacksForTest();
+                       }
                }
        } ) );
 
 
                function isCssImportApplied() {
                        // Trigger reflow, repaint, redraw, whatever (cross-browser)
-                       var x = $element.css( 'height' );
-                       x = el.innerHTML;
+                       $element.css( 'height' );
+                       el.innerHTML;
                        el.className = el.className;
-                       x = document.documentElement.clientHeight;
+                       document.documentElement.clientHeight;
 
                        return $element.css( prop ) === val;
                }
@@ -75,7 +80,7 @@
                );
        }
 
-       QUnit.test( 'Basic', 2, function ( assert ) {
+       QUnit.test( 'Basic', function ( assert ) {
                var isAwesomeDone;
 
                mw.loader.testCallback = function () {
@@ -94,7 +99,7 @@
                } );
        } );
 
-       QUnit.test( 'Object method as module name', 2, function ( assert ) {
+       QUnit.test( 'Object method as module name', function ( assert ) {
                var isAwesomeDone;
 
                mw.loader.testCallback = function () {
                } );
        } );
 
-       QUnit.test( '.using( .. ) Promise', 2, function ( assert ) {
+       QUnit.test( '.using( .. ) Promise', function ( assert ) {
                var isAwesomeDone;
 
                mw.loader.testCallback = function () {
                } );
        } );
 
-       QUnit.test( '.using() Error: Circular dependency', function ( assert ) {
+       // Covers mw.loader#sortDependencies (with native Set if available)
+       QUnit.test( '.using() Error: Circular dependency [StringSet default]', function ( assert ) {
                var done = assert.async();
 
                mw.loader.register( [
                .always( done );
        } );
 
+       // @covers mw.loader#sortDependencies (with fallback shim)
+       QUnit.test( '.using() Error: Circular dependency [StringSet shim]', function ( assert ) {
+               var done = assert.async();
+
+               if ( !window.Set ) {
+                       assert.expect( 0 );
+                       done();
+                       return;
+               }
+
+               this.nativeSet = window.Set;
+               window.Set = undefined;
+               mw.redefineFallbacksForTest();
+
+               mw.loader.register( [
+                       [ 'test.shim.circle1', '0', [ 'test.shim.circle2' ] ],
+                       [ 'test.shim.circle2', '0', [ 'test.shim.circle3' ] ],
+                       [ 'test.shim.circle3', '0', [ 'test.shim.circle1' ] ]
+               ] );
+               mw.loader.using( 'test.shim.circle3' ).then(
+                       function done() {
+                               assert.ok( false, 'Unexpected resolution, expected error.' );
+                       },
+                       function fail( e ) {
+                               assert.ok( /Circular/.test( String( e ) ), 'Detect circular dependency' );
+                       }
+               )
+               .always( done );
+       } );
+
        QUnit.test( '.load() - Error: Circular dependency', function ( assert ) {
                mw.loader.register( [
                        [ 'test.circleA', '0', [ 'test.circleB' ] ],
                ).always( done );
        } );
 
-       QUnit.test( '.load() - Error: Unregistered (ignored)', 0, function ( assert ) {
+       QUnit.test( '.load() - Error: Unregistered (ignored)', function ( assert ) {
+               assert.expect( 0 );
                mw.loader.load( 'test.using.unreg2' );
        } );
 
-       QUnit.test( '.implement( styles={ "css": [text, ..] } )', 2, function ( assert ) {
+       QUnit.test( '.implement( styles={ "css": [text, ..] } )', function ( assert ) {
                var $element = $( '<div class="mw-test-implement-a"></div>' ).appendTo( '#qunit-fixture' );
 
                assert.notEqual(
                return mw.loader.using( 'test.implement.a' );
        } );
 
-       QUnit.test( '.implement( styles={ "url": { <media>: [url, ..] } } )', 7, function ( assert ) {
+       QUnit.test( '.implement( styles={ "url": { <media>: [url, ..] } } )', function ( assert ) {
                var $element1 = $( '<div class="mw-test-implement-b1"></div>' ).appendTo( '#qunit-fixture' ),
                        $element2 = $( '<div class="mw-test-implement-b2"></div>' ).appendTo( '#qunit-fixture' ),
                        $element3 = $( '<div class="mw-test-implement-b3"></div>' ).appendTo( '#qunit-fixture' ),
                                url: {
                                        print: [ urlStyleTest( '.mw-test-implement-b1', 'text-align', 'center' ) ],
                                        screen: [
-                                               // bug 40834: Make sure it actually works with more than 1 stylesheet reference
+                                               // T42834: Make sure it actually works with more than 1 stylesheet reference
                                                urlStyleTest( '.mw-test-implement-b2', 'float', 'left' ),
                                                urlStyleTest( '.mw-test-implement-b3', 'float', 'right' )
                                        ]
        } );
 
        // Backwards compatibility
-       QUnit.test( '.implement( styles={ <media>: text } ) (back-compat)', 2, function ( assert ) {
+       QUnit.test( '.implement( styles={ <media>: text } ) (back-compat)', function ( assert ) {
                var $element = $( '<div class="mw-test-implement-c"></div>' ).appendTo( '#qunit-fixture' );
 
                assert.notEqual(
        } );
 
        // Backwards compatibility
-       QUnit.test( '.implement( styles={ <media>: [url, ..] } ) (back-compat)', 4, function ( assert ) {
+       QUnit.test( '.implement( styles={ <media>: [url, ..] } ) (back-compat)', function ( assert ) {
                var $element = $( '<div class="mw-test-implement-d"></div>' ).appendTo( '#qunit-fixture' ),
                        $element2 = $( '<div class="mw-test-implement-d2"></div>' ).appendTo( '#qunit-fixture' ),
                        done = assert.async();
                        'test.implement.d',
                        function () {
                                assertStyleAsync( assert, $element, 'float', 'right', function () {
-                                       assert.notEqual( $element2.css( 'text-align' ), 'center', 'print style is not applied (bug 40500)' );
+                                       assert.notEqual( $element2.css( 'text-align' ), 'center', 'print style is not applied (T42500)' );
                                        done();
                                } );
                        },
                mw.loader.load( 'test.implement.d' );
        } );
 
-       // @import (bug 31676)
-       QUnit.test( '.implement( styles has @import )', 7, function ( assert ) {
+       // @import (T33676)
+       QUnit.test( '.implement( styles has @import )', function ( assert ) {
                var isJsExecuted, $element,
                        done = assert.async();
 
                } );
        } );
 
-       QUnit.test( '.implement( dependency with styles )', 4, function ( assert ) {
+       QUnit.test( '.implement( dependency with styles )', function ( assert ) {
                var $element = $( '<div class="mw-test-implement-e"></div>' ).appendTo( '#qunit-fixture' ),
                        $element2 = $( '<div class="mw-test-implement-e2"></div>' ).appendTo( '#qunit-fixture' );
 
                return mw.loader.using( 'test.implement.e' );
        } );
 
-       QUnit.test( '.implement( only scripts )', 1, function ( assert ) {
+       QUnit.test( '.implement( only scripts )', function ( assert ) {
                mw.loader.implement( 'test.onlyscripts', function () {} );
                assert.strictEqual( mw.loader.getState( 'test.onlyscripts' ), 'ready' );
        } );
 
-       QUnit.test( '.implement( only messages )', 2, function ( assert ) {
-               assert.assertFalse( mw.messages.exists( 'bug_29107' ), 'Verify that the test message doesn\'t exist yet' );
+       QUnit.test( '.implement( only messages )', function ( assert ) {
+               assert.assertFalse( mw.messages.exists( 'T31107' ), 'Verify that the test message doesn\'t exist yet' );
 
-               // jscs: disable requireCamelCaseOrUpperCaseIdentifiers
-               mw.loader.implement( 'test.implement.msgs', [], {}, { bug_29107: 'loaded' } );
-               // jscs: enable requireCamelCaseOrUpperCaseIdentifiers
+               mw.loader.implement( 'test.implement.msgs', [], {}, { T31107: 'loaded' } );
 
                return mw.loader.using( 'test.implement.msgs', function () {
-                       assert.ok( mw.messages.exists( 'bug_29107' ), 'Bug 29107: messages-only module should implement ok' );
+                       assert.ok( mw.messages.exists( 'T31107' ), 'T31107: messages-only module should implement ok' );
                }, function () {
                        assert.ok( false, 'Error callback fired while implementing "test.implement.msgs" module' );
                } );
        } );
 
-       QUnit.test( '.implement( empty )', 1, function ( assert ) {
+       QUnit.test( '.implement( empty )', function ( assert ) {
                mw.loader.implement( 'test.empty' );
                assert.strictEqual( mw.loader.getState( 'test.empty' ), 'ready' );
        } );
 
-       QUnit.test( 'Broken indirect dependency', 4, function ( assert ) {
+       QUnit.test( 'Broken indirect dependency', function ( assert ) {
                // don't emit an error event
                this.sandbox.stub( mw, 'track' );
 
                assert.strictEqual( mw.track.callCount, 1 );
        } );
 
-       QUnit.test( 'Out-of-order implementation', 9, function ( assert ) {
+       QUnit.test( 'Out-of-order implementation', function ( assert ) {
                mw.loader.register( [
                        [ 'test.module4', '0' ],
                        [ 'test.module5', '0', [ 'test.module4' ] ],
                assert.strictEqual( mw.loader.getState( 'test.module6' ), 'ready', 'Expected "ready" state for test.module6' );
        } );
 
-       QUnit.test( 'Missing dependency', 13, function ( assert ) {
+       QUnit.test( 'Missing dependency', function ( assert ) {
                mw.loader.register( [
                        [ 'test.module7', '0' ],
                        [ 'test.module8', '0', [ 'test.module7' ] ],
                );
        } );
 
-       QUnit.test( 'Dependency handling', 5, function ( assert ) {
+       QUnit.test( 'Dependency handling', function ( assert ) {
                var done = assert.async();
                mw.loader.register( [
                        // [module, version, dependencies, group, source]
                );
        } );
 
-       QUnit.test( 'Skip-function handling', 5, function ( assert ) {
+       QUnit.test( 'Skip-function handling', function ( assert ) {
                mw.loader.register( [
                        // [module, version, dependencies, group, source, skip]
                        [ 'testSkipped', '1', [], null, 'testloader', 'return true;' ],
                );
        } );
 
-       QUnit.asyncTest( '.load( "//protocol-relative" ) - T32825', 2, function ( assert ) {
+       QUnit.asyncTest( '.load( "//protocol-relative" ) - T32825', function ( assert ) {
                // This bug was actually already fixed in 1.18 and later when discovered in 1.17.
                // Test is for regressions!
 
                mw.loader.load( target );
        } );
 
-       QUnit.asyncTest( '.load( "/absolute-path" )', 2, function ( assert ) {
+       QUnit.asyncTest( '.load( "/absolute-path" )', function ( assert ) {
                // Forge a URL to the test callback script
                var target = QUnit.fixurl(
                        mw.config.get( 'wgScriptPath' ) + '/tests/qunit/data/qunitOkCall.js'
                } );
        } );
 
-       QUnit.test( 'Executing race - T112232', 2, function ( assert ) {
+       QUnit.test( 'Executing race - T112232', function ( assert ) {
                var done = false;
 
                // The red herring schedules its CSS buffer first. In T112232, a bug in the
                        } );
        } );
 
-       QUnit.test( 'require()', 6, function ( assert ) {
+       QUnit.test( 'require()', function ( assert ) {
                mw.loader.register( [
                        [ 'test.require1', '0' ],
                        [ 'test.require2', '0' ],