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

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
rictic committed Sep 14, 2014
2 parents 509ef7c + 0898920 commit e5c2f8e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 3 deletions.
3 changes: 3 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"private": true,
"dependencies": {
"polymer": "Polymer/polymer#master"
},
"devDependencies": {
"polymer-test-tools": "Polymer/polymer-test-tools#master"
}
}
9 changes: 6 additions & 3 deletions core-ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
try {
return JSON.parse(r);
} catch (x) {
console.warn('core-ajax caught an exception trying to parse reponse as JSON:');
console.warn('core-ajax caught an exception trying to parse response as JSON:');
console.warn('url:', this.url);
console.warn(x);
return r;
Expand Down Expand Up @@ -319,8 +319,11 @@
if (args.headers && typeof(args.headers) == 'string') {
args.headers = JSON.parse(args.headers);
}
if (this.contentType) {
args.headers['content-type'] = this.contentType;
var hasContentType = Object.keys(args.headers).some(function (header) {
return header.toLowerCase() === 'content-type';
});
if (!hasContentType && this.contentType) {
args.headers['Content-Type'] = this.contentType;
}
if (this.handleAs === 'arraybuffer' || this.handleAs === 'blob' ||
this.handleAs === 'document') {
Expand Down
23 changes: 23 additions & 0 deletions metadata.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
@license
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<x-meta id="core-ajax" label="Ajax" group="Core">

<property name="handleAs" kind="select" options="json,text,xml,arraybuffer,blob,document"></property>
<property name="method" kind="select" options="GET,POST,PUT,DELETE"></property>

<template>
<core-ajax handleAs="json" method="GET"></core-ajax>
</template>

<template id="imports">
<link rel="import" href="core-ajax.html">
</template>

</x-meta>
43 changes: 43 additions & 0 deletions tests/html/core-ajax.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>core-ajax</title>

<script src="../../../platform/platform.js"></script>
<script src="../../../polymer-test-tools/chai/chai.js"></script>
<script src="../../../polymer-test-tools/htmltest.js"></script>

<link rel="import" href="../../core-ajax.html">

</head>
<body>

<core-ajax
url="http://gdata.youtube.com/feeds/api/videos/"
params='{"alt":"json", "q":"chrome"}'
handleAs="json"
auto></core-ajax>

<script>

document.addEventListener('polymer-ready', function() {
var assert = chai.assert;
var ajax = document.querySelector('core-ajax');
ajax.addEventListener("core-response", function(event) {
assert.isTrue(event.detail.response.feed.entry.length > 0);
done();
});
});

</script>

</body>
</html>
3 changes: 3 additions & 0 deletions tests/js/htmltests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
htmlSuite('core-ajax', function() {
htmlTest('html/core-ajax.html');
});
14 changes: 14 additions & 0 deletions tests/runner.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype htmlz>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>Web Component Test Runner</title>
<script src="../../polymer-test-tools/ci-support.js"></script>
</head>
<body>
<script>
runTests('tests.json');
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions tests/tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tools": ["chai", "mocha-tdd"],
"tests": [
"js/htmltests.js"
]
}

0 comments on commit e5c2f8e

Please sign in to comment.