From d7b3aa9ae6d03bc04734b0bf1440144ee40269b5 Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Fri, 11 Jul 2014 15:53:54 -0400 Subject: [PATCH] test(jqLite): make iframe contents() test less flaky Closes #8157 --- karma-jqlite.conf.js | 7 +---- karma-jquery.conf.js | 7 +---- test/fixtures/iframe.html | 9 ------- test/jqLiteSpec.js | 55 +++++++++++++++++++++------------------ 4 files changed, 32 insertions(+), 46 deletions(-) delete mode 100644 test/fixtures/iframe.html diff --git a/karma-jqlite.conf.js b/karma-jqlite.conf.js index f198ab41616d..1e7416bf1622 100644 --- a/karma-jqlite.conf.js +++ b/karma-jqlite.conf.js @@ -7,12 +7,7 @@ module.exports = function(config) { sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'}); config.set({ - files: angularFiles.mergeFilesFor('karma').concat({ - pattern: "test/fixtures/**/*.html", - served: true, - watched: true, - included: false - }), + files: angularFiles.mergeFilesFor('karma'), exclude: angularFiles.mergeFilesFor('karmaExclude'), junitReporter: { diff --git a/karma-jquery.conf.js b/karma-jquery.conf.js index 319fd297cc0a..c7db1c25255a 100644 --- a/karma-jquery.conf.js +++ b/karma-jquery.conf.js @@ -7,12 +7,7 @@ module.exports = function(config) { sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'}); config.set({ - files: angularFiles.mergeFilesFor('karmaJquery').concat({ - pattern: "test/fixtures/**/*.html", - served: true, - watched: true, - included: false - }), + files: angularFiles.mergeFilesFor('karmaJquery'), exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'), junitReporter: { diff --git a/test/fixtures/iframe.html b/test/fixtures/iframe.html deleted file mode 100644 index 7b37d91d62c1..000000000000 --- a/test/fixtures/iframe.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - Iframe Test - - - Text - - diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 6da7df899b54..b15b9b9d58e6 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1444,32 +1444,37 @@ describe('jqLite', function() { expect(contents[1].data).toEqual('before-'); }); - // IE8 does not like this test, although the functionality may still work there. - if (!msie || msie > 8) { - it('should select all types iframe contents', function() { - var iframe_ = document.createElement('iframe'), tested, - iframe = jqLite(iframe_); - function test() { - var contents = iframe.contents(); - expect(contents[0]).toBeTruthy(); - expect(contents.length).toBe(1); - expect(contents.prop('nodeType')).toBe(9); - expect(contents[0].body).toBeTruthy(); - expect(jqLite(contents[0].body).contents().length).toBe(3); - iframe.remove(); - tested = true; - } - iframe_.onload = iframe_.onreadystatechange = function() { - if (iframe_.contentDocument) test(); - }; - iframe_.src = "/base/test/fixtures/iframe.html"; - jqLite(document).find('body').append(iframe); + it('should select all types iframe contents', function() { + // IE8 does not like this test, although the functionality may still work there. + if (msie < 9) return; + var iframe_ = document.createElement('iframe'); + var tested = false; + var iframe = jqLite(iframe_); + function test() { + var doc = iframe_.contentDocument || iframe_.contentWindow.document; + doc.body.innerHTML = '\nText\n'; + + var contents = iframe.contents(); + expect(contents[0]).toBeTruthy(); + expect(contents.length).toBe(1); + expect(contents.prop('nodeType')).toBe(9); + expect(contents[0].body).toBeTruthy(); + expect(jqLite(contents[0].body).contents().length).toBe(3); + iframe.remove(); + doc = null; + tested = true; + } + iframe_.onload = iframe_.onreadystatechange = function() { + if (iframe_.contentDocument) test(); + }; + /* jshint scripturl:true */ + iframe_.src = 'javascript:false'; + jqLite(document).find('body').append(iframe); - // This test is potentially flaky on CI cloud instances, so there is a generous - // wait period... - waitsFor(function() { return tested; }, 'iframe to load', 5000); - }); - } + // This test is potentially flaky on CI cloud instances, so there is a generous + // wait period... + waitsFor(function() { return tested; }, 'iframe to load', 5000); + }); });