Merge "xhprof: Guard against division by 0 when computing percentages"
[lhc/web/wiklou.git] / tests / qunit / suites / resources / mediawiki / mediawiki.Uri.test.js
index 9913f5e..ba36655 100644 (file)
@@ -1,3 +1,4 @@
+/*jshint -W024 */
 ( function ( mw, $ ) {
        QUnit.module( 'mediawiki.Uri', QUnit.newMwEnvironment( {
                setup: function () {
 
                assert.throws(
                        function () {
-                               return new mw.Uri( 'foo.com/bar/baz', {
+                               return new mw.Uri( 'example.com/bar/baz', {
                                        strictMode: true
                                } );
                        },
                        'throw error on URI without protocol or // or leading / in strict mode'
                );
 
-               uri = new mw.Uri( 'foo.com/bar/baz', {
+               uri = new mw.Uri( 'example.com/bar/baz', {
                        strictMode: false
                } );
-               assert.equal( uri.toString(), 'http://foo.com/bar/baz', 'normalize URI without protocol or // in loose mode' );
+               assert.equal( uri.toString(), 'http://example.com/bar/baz', 'normalize URI without protocol or // in loose mode' );
        } );
 
        QUnit.test( 'Constructor( Object )', 3, function ( assert ) {
        } );
 
        QUnit.test( '.getQueryString()', 2, function ( assert ) {
-               var uri = new mw.Uri( 'http://www.google.com/?q=uri' );
+               var uri = new mw.Uri( 'http://search.example.com/?q=uri' );
 
                assert.deepEqual(
                        {
                        },
                        {
                                protocol: 'http',
-                               host: 'www.google.com',
+                               host: 'search.example.com',
                                port: undefined,
                                path: '/',
                                query: { q: 'uri' },
                        'basic object properties'
                );
 
-               uri = new mw.Uri( 'https://example.org/mw/index.php?title=Sandbox/7&other=Sandbox/7&foo' );
+               uri = new mw.Uri( 'https://example.com/mw/index.php?title=Sandbox/7&other=Sandbox/7&foo' );
                assert.equal(
                        uri.getQueryString(),
                        'title=Sandbox/7&other=Sandbox%2F7&foo',
                assert.equal( uri.toString(), 'http://www.example.com/dir/', 'empty array value is ommitted' );
        } );
 
+       QUnit.test( 'Variable defaultUri', 2, function ( assert ) {
+               var uri,
+                       href = 'http://example.org/w/index.php#here',
+                       UriClass = mw.UriRelative( function () {
+                               return href;
+                       } );
+
+               uri = new UriClass();
+               assert.deepEqual(
+                       {
+                               protocol: uri.protocol,
+                               user: uri.user,
+                               password: uri.password,
+                               host: uri.host,
+                               port: uri.port,
+                               path: uri.path,
+                               query: uri.query,
+                               fragment: uri.fragment
+                       },
+                       {
+                               protocol: 'http',
+                               user: undefined,
+                               password: undefined,
+                               host: 'example.org',
+                               port: undefined,
+                               path: '/w/index.php',
+                               query: {},
+                               fragment: 'here'
+                       },
+                       'basic object properties'
+               );
+
+               // Default URI may change, e.g. via history.replaceState, pushState or location.hash (T74334)
+               href = 'https://example.com/wiki/Foo?v=2';
+               uri = new UriClass();
+               assert.deepEqual(
+                       {
+                               protocol: uri.protocol,
+                               user: uri.user,
+                               password: uri.password,
+                               host: uri.host,
+                               port: uri.port,
+                               path: uri.path,
+                               query: uri.query,
+                               fragment: uri.fragment
+                       },
+                       {
+                               protocol: 'https',
+                               user: undefined,
+                               password: undefined,
+                               host: 'example.com',
+                               port: undefined,
+                               path: '/wiki/Foo',
+                               query: { 'v': '2' },
+                               fragment: undefined
+                       },
+                       'basic object properties'
+               );
+       } );
+
        QUnit.test( 'Advanced URL', 11, function ( assert ) {
                var uri, queryString, relativePath;
 
                uri = new UriClass( testPath );
                href = uri.toString();
                assert.equal( href, testProtocol + testServer + ':' + testPort + testPath, 'Root-relative URL gets host, protocol, and port supplied' );
-
        } );
 }( mediaWiki, jQuery ) );