diff options
author | Oleg Gaidarenko <markelog@gmail.com> | 2015-12-22 18:16:52 +0300 |
---|---|---|
committer | Oleg Gaidarenko <markelog@gmail.com> | 2015-12-22 18:16:52 +0300 |
commit | c9546c6be5303a7e17cf78b92d904e6575466864 (patch) | |
tree | ca74b756e9a014a4de0a013070dfaff0a679aacd /test | |
parent | e5256a65788ec9ee9cedfd07af7b77148df69dd6 (diff) | |
download | jquery-c9546c6be5303a7e17cf78b92d904e6575466864.tar.gz jquery-c9546c6be5303a7e17cf78b92d904e6575466864.zip |
Revert "Ajax: Always use script injection in globalEval"
This reverts commit 37f0f7f42cd158e36665066d88708ca4aa0713ac.
Diffstat (limited to 'test')
-rw-r--r-- | test/data/event/longLoadScript.php (renamed from test/data/longLoadScript.php) | 0 | ||||
-rw-r--r-- | test/data/event/syncReady.html | 4 | ||||
-rw-r--r-- | test/unit/ajax.js | 42 | ||||
-rw-r--r-- | test/unit/core.js | 26 | ||||
-rw-r--r-- | test/unit/manipulation.js | 50 |
5 files changed, 52 insertions, 70 deletions
diff --git a/test/data/longLoadScript.php b/test/data/event/longLoadScript.php index ba47168b4..ba47168b4 100644 --- a/test/data/longLoadScript.php +++ b/test/data/event/longLoadScript.php diff --git a/test/data/event/syncReady.html b/test/data/event/syncReady.html index 0d2f8fdad..e0885707e 100644 --- a/test/data/event/syncReady.html +++ b/test/data/event/syncReady.html @@ -8,7 +8,7 @@ <body> <script type="text/javascript"> -jQuery( document ).ready(function() { +jQuery( document ).ready(function () { window.parent.iframeCallback( jQuery('#container').length === 1 ); }); </script> @@ -17,7 +17,7 @@ jQuery( document ).ready(function() { oldIE into thinking the dom is ready, but it's not... leaving this check here for future trailblazers to attempt fixing this...--> -<script type="text/javascript" src="../longLoadScript.php?sleep=1"></script> +<script type="text/javascript" src="longLoadScript.php?sleep=1"></script> <div id="container" style="height: 300px"></div> </body> </html> diff --git a/test/unit/ajax.js b/test/unit/ajax.js index 6a9a587c1..e7f38024f 100644 --- a/test/unit/ajax.js +++ b/test/unit/ajax.js @@ -1417,29 +1417,25 @@ QUnit.module( "ajax", { }; } ); - QUnit.asyncTest( "#11743 - jQuery.ajax() - script, throws exception", 1, function( assert ) { - - // Support: Android 2.3 only - // Android 2.3 doesn't fire the window.onerror handler, just accept the reality there. - if ( /android 2\.3/i.test( navigator.userAgent ) ) { - assert.ok( true, "Test skipped, Android 2.3 doesn't fire window.onerror for " + - "errors in dynamically included scripts" ); - QUnit.start(); - return; - } - - var onerror = window.onerror; - window.onerror = function() { - assert.ok( true, "Exception thrown" ); - window.onerror = onerror; - QUnit.start(); - }; - jQuery.ajax( { - url: "data/badjson.js", - dataType: "script", - throws: true - } ); - } ); + test( "#11743 - jQuery.ajax() - script, throws exception", 1, function() { + throws(function() { + jQuery.ajax({ + url: "data/badjson.js", + dataType: "script", + "throws": true, + // TODO find a way to test this asynchronously, too + async: false, + // Global events get confused by the exception + global: false, + success: function() { + ok( false, "Success." ); + }, + error: function() { + ok( false, "Error." ); + } + }); + }, "exception bubbled" ); + }); jQuery.each( [ "method", "type" ], function( _, globalOption ) { function request( assert, option ) { diff --git a/test/unit/core.js b/test/unit/core.js index ab5c11d34..10143408f 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -209,20 +209,26 @@ QUnit.test( "globalEval", function( assert ) { assert.equal( window.globalEvalTest, 3, "Test context (this) is the window object" ); } ); -QUnit.test( "globalEval execution after script injection (#7862)", function( assert ) { - assert.expect( 1 ); +if ( jQuery.noConflict ) { + QUnit.test( "noConflict", function( assert ) { + assert.expect( 7 ); - var now, - script = document.createElement( "script" ); + var $$ = jQuery; + + assert.strictEqual( jQuery, jQuery.noConflict(), "noConflict returned the jQuery object" ); + assert.strictEqual( window[ "jQuery" ], $$, "Make sure jQuery wasn't touched." ); + assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." ); - script.src = "data/longLoadScript.php?sleep=2"; + jQuery = $ = $$; - now = jQuery.now(); - document.body.appendChild( script ); + assert.strictEqual( jQuery.noConflict( true ), $$, "noConflict returned the jQuery object" ); + assert.strictEqual( window[ "jQuery" ], originaljQuery, "Make sure jQuery was reverted." ); + assert.strictEqual( window[ "$" ], original$, "Make sure $ was reverted." ); + assert.ok( $$().pushStack( [] ), "Make sure that jQuery still works." ); - jQuery.globalEval( "var strictEvalTest = " + jQuery.now() + ";" ); - assert.ok( window.strictEvalTest - now < 500, "Code executed synchronously" ); -} ); + window[ "jQuery" ] = jQuery = $$; + } ); +} // This is not run in AMD mode if ( jQuery.noConflict ) { diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 6e805aebe..fb9c454fb 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -2348,45 +2348,25 @@ QUnit.test( "Ensure oldIE creates a new set on appendTo (#8894)", function( asse assert.strictEqual( jQuery( "<p/>" ).appendTo( "<div/>" ).end().length, jQuery( "<p>test</p>" ).appendTo( "<div/>" ).end().length, "Elements created with createElement and with createDocumentFragment should be treated alike" ); } ); -QUnit.asyncTest( "html() - script exceptions bubble (#11743)", 2, function( assert ) { - // Support: Android 2.3 only - // Android 2.3 doesn't fire the window.onerror handler, just accept the reality there. - if ( /android 2\.3/i.test( navigator.userAgent ) ) { - assert.ok( true, "Test skipped, Android 2.3 doesn't fire window.onerror for " + - "errors in dynamically included scripts" ); - assert.ok( true, "Test skipped, Android 2.3 doesn't fire window.onerror for " + - "errors in dynamically included scripts" ); - QUnit.start(); - return; - } - - var onerror = window.onerror; - - setTimeout( function() { - window.onerror = onerror; - - QUnit.start(); - }, 1000 ); +test( "html() - script exceptions bubble (#11743)", function() { - window.onerror = function() { - assert.ok( true, "Exception thrown" ); + expect( 2 ); - if ( jQuery.ajax ) { - window.onerror = function() { - assert.ok( true, "Exception thrown in remote script" ); - }; + throws(function() { + jQuery("#qunit-fixture").html("<script>undefined(); ok( false, 'Exception not thrown' );</script>"); + ok( false, "Exception ignored" ); + }, "Exception bubbled from inline script" ); - jQuery( "#qunit-fixture" ).html( "<script src='data/badcall.js'></script>" ); - assert.ok( true, "Exception ignored" ); - } else { - assert.ok( true, "No jQuery.ajax" ); - assert.ok( true, "No jQuery.ajax" ); - } - }; - - jQuery( "#qunit-fixture" ).html( "<script>undefined();</script>" ); -} ); + if ( jQuery.ajax ) { + throws(function() { + jQuery("#qunit-fixture").html("<script src='data/badcall.js'></script>"); + ok( false, "Exception ignored" ); + }, "Exception thrown in remote script" ); + } else { + ok( true, "No jQuery.ajax" ); + } +}); QUnit.test( "checked state is cloned with clone()", function( assert ) { |