diff options
| author | Caitlin Potter | 2014-02-18 15:16:38 -0500 |
|---|---|---|
| committer | Caitlin Potter | 2014-02-18 18:43:59 -0500 |
| commit | 05fbed5710b702c111c1425a9e241c40d13b0a54 (patch) | |
| tree | 35b140ec5fb4cee2a5dfe069d535ea6311281117 | |
| parent | 21dac2a3daae528471d5e767072b10e1491f2106 (diff) | |
| download | angular.js-05fbed5710b702c111c1425a9e241c40d13b0a54.tar.bz2 | |
fix(jqLite): make jqLite('<iframe src="someurl">').contents() return iframe document, as in jQuery
This is a very tiny change to make behaviour consistent with jQuery.
Closes #6320
Closes #6323
| -rw-r--r-- | karma-jqlite.conf.js | 7 | ||||
| -rw-r--r-- | karma-jquery.conf.js | 7 | ||||
| -rw-r--r-- | src/jqLite.js | 2 | ||||
| -rw-r--r-- | test/fixtures/iframe.html | 9 | ||||
| -rw-r--r-- | test/jqLiteSpec.js | 27 |
5 files changed, 49 insertions, 3 deletions
diff --git a/karma-jqlite.conf.js b/karma-jqlite.conf.js index 267e952f..7b511720 100644 --- a/karma-jqlite.conf.js +++ b/karma-jqlite.conf.js @@ -5,7 +5,12 @@ module.exports = function(config) { sharedConfig(config, {testName: 'AngularJS: jqLite', logFile: 'karma-jqlite.log'}); config.set({ - files: angularFiles.mergeFilesFor('karma'), + files: angularFiles.mergeFilesFor('karma').concat({ + pattern: "test/fixtures/**/*.html", + served: true, + watched: true, + included: false + }), exclude: angularFiles.mergeFilesFor('karmaExclude'), junitReporter: { diff --git a/karma-jquery.conf.js b/karma-jquery.conf.js index 4af9508d..6a592d6a 100644 --- a/karma-jquery.conf.js +++ b/karma-jquery.conf.js @@ -5,7 +5,12 @@ module.exports = function(config) { sharedConfig(config, {testName: 'AngularJS: jQuery', logFile: 'karma-jquery.log'}); config.set({ - files: angularFiles.mergeFilesFor('karmaJquery'), + files: angularFiles.mergeFilesFor('karmaJquery').concat({ + pattern: "test/fixtures/**/*.html", + served: true, + watched: true, + included: false + }), exclude: angularFiles.mergeFilesFor('karmaJqueryExclude'), junitReporter: { diff --git a/src/jqLite.js b/src/jqLite.js index 664ba7b7..b820f5e7 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -793,7 +793,7 @@ forEach({ }, contents: function(element) { - return element.childNodes || []; + return element.contentDocument || element.childNodes || []; }, append: function(element, node) { diff --git a/test/fixtures/iframe.html b/test/fixtures/iframe.html new file mode 100644 index 00000000..7b37d91d --- /dev/null +++ b/test/fixtures/iframe.html @@ -0,0 +1,9 @@ +<!DOCTYPE html> +<html> + <head> + <title>Iframe Test</title> + </head> + <body> + <span>Text</span> + </body> +</html> diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 82db95b6..1f3be1b2 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -1299,6 +1299,33 @@ describe('jqLite', function() { expect(contents[0].data).toEqual(' some comment '); 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); + + // This test is potentially flaky on CI cloud instances, so there is a generous + // wait period... + waitsFor(function() { return tested; }, 2000); + }); + } }); |
