Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit e5c2f8e

Browse files
committed
2 parents 509ef7c + 0898920 commit e5c2f8e

File tree

7 files changed

+98
-3
lines changed

7 files changed

+98
-3
lines changed

bower.json

+3
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"private": true,
44
"dependencies": {
55
"polymer": "Polymer/polymer#master"
6+
},
7+
"devDependencies": {
8+
"polymer-test-tools": "Polymer/polymer-test-tools#master"
69
}
710
}

core-ajax.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
try {
255255
return JSON.parse(r);
256256
} catch (x) {
257-
console.warn('core-ajax caught an exception trying to parse reponse as JSON:');
257+
console.warn('core-ajax caught an exception trying to parse response as JSON:');
258258
console.warn('url:', this.url);
259259
console.warn(x);
260260
return r;
@@ -319,8 +319,11 @@
319319
if (args.headers && typeof(args.headers) == 'string') {
320320
args.headers = JSON.parse(args.headers);
321321
}
322-
if (this.contentType) {
323-
args.headers['content-type'] = this.contentType;
322+
var hasContentType = Object.keys(args.headers).some(function (header) {
323+
return header.toLowerCase() === 'content-type';
324+
});
325+
if (!hasContentType && this.contentType) {
326+
args.headers['Content-Type'] = this.contentType;
324327
}
325328
if (this.handleAs === 'arraybuffer' || this.handleAs === 'blob' ||
326329
this.handleAs === 'document') {

metadata.html

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!--
2+
@license
3+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
Code distributed by Google as part of the polymer project is also
8+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
-->
10+
<x-meta id="core-ajax" label="Ajax" group="Core">
11+
12+
<property name="handleAs" kind="select" options="json,text,xml,arraybuffer,blob,document"></property>
13+
<property name="method" kind="select" options="GET,POST,PUT,DELETE"></property>
14+
15+
<template>
16+
<core-ajax handleAs="json" method="GET"></core-ajax>
17+
</template>
18+
19+
<template id="imports">
20+
<link rel="import" href="core-ajax.html">
21+
</template>
22+
23+
</x-meta>

tests/html/core-ajax.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!doctype html>
2+
<!--
3+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7+
Code distributed by Google as part of the polymer project is also
8+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9+
-->
10+
<html>
11+
<head>
12+
<title>core-ajax</title>
13+
14+
<script src="../../../platform/platform.js"></script>
15+
<script src="../../../polymer-test-tools/chai/chai.js"></script>
16+
<script src="../../../polymer-test-tools/htmltest.js"></script>
17+
18+
<link rel="import" href="../../core-ajax.html">
19+
20+
</head>
21+
<body>
22+
23+
<core-ajax
24+
url="http://gdata.youtube.com/feeds/api/videos/"
25+
params='{"alt":"json", "q":"chrome"}'
26+
handleAs="json"
27+
auto></core-ajax>
28+
29+
<script>
30+
31+
document.addEventListener('polymer-ready', function() {
32+
var assert = chai.assert;
33+
var ajax = document.querySelector('core-ajax');
34+
ajax.addEventListener("core-response", function(event) {
35+
assert.isTrue(event.detail.response.feed.entry.length > 0);
36+
done();
37+
});
38+
});
39+
40+
</script>
41+
42+
</body>
43+
</html>

tests/js/htmltests.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
htmlSuite('core-ajax', function() {
2+
htmlTest('html/core-ajax.html');
3+
});

tests/runner.html

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype htmlz>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
6+
<title>Web Component Test Runner</title>
7+
<script src="../../polymer-test-tools/ci-support.js"></script>
8+
</head>
9+
<body>
10+
<script>
11+
runTests('tests.json');
12+
</script>
13+
</body>
14+
</html>

tests/tests.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"tools": ["chai", "mocha-tdd"],
3+
"tests": [
4+
"js/htmltests.js"
5+
]
6+
}

0 commit comments

Comments
 (0)