Added Polymer

This commit is contained in:
Thaum
2014-11-26 10:18:35 +00:00
parent 5eea4714b2
commit 3408ba9e8d
1210 changed files with 394645 additions and 47 deletions

View File

@@ -0,0 +1,108 @@
<!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="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../core-ajax.html">
</head>
<body>
<core-ajax
handleAs="json"
auto></core-ajax>
<!--
Test consistency of core-ajax's loading properties.
-->
<script>
test('progress', function(done) {
var ajax = document.querySelector("core-ajax");
var xhr = sinon.useFakeXMLHttpRequest();
var headers = {
"Content-Type": "text/json"
};
var body = '{"content": "plentiful"}'
var requests = this.requests = [];
xhr.onCreate = function (xhr) {
requests.push(xhr);
// Polymer inspects the xhr object for the precense of onprogress to determine
// whether to attach an event listener.
xhr['onprogress'] = null;
};
var progressEvent = function(lengthComputable, loaded, total) {
var progress = new ProgressEvent('progress', {
lengthComputable: lengthComputable,
loaded: loaded,
total: total
});
return progress;
}
// Fake a file download by sending multiple progress events.
async.series([
function(cb) {
ajax.url="http://example.org/downloadLargeFile"
cb();
},
flush,
animationFrameFlush,
function(cb) {
requests[0].dispatchEvent(progressEvent(true, 10, 100));
cb();
},
flush,
animationFrameFlush,
function(cb) {
assert(ajax.loading === true,
"Request partially complete, but loading property was false.");
var progress = ajax.progress;
assert(progress.lengthComputable, "Progress should be computable");
assert(progress.loaded == 10, "Expected 10 bytes loaded, got " + progress.loaded);
assert(progress.total == 100, "Expected 100 bytes total, got " + progress.total);
cb();
},
animationFrameFlush,
function(cb) {
requests[0].dispatchEvent(progressEvent(true, 100, 100));
cb();
},
animationFrameFlush,
function(cb) {
assert(ajax.loading === true,
"Request partially complete, but loading property was false.");
var progress = ajax.progress;
assert(progress.lengthComputable, "Progress should be computable");
assert(progress.loaded == 100, "Expected 10 bytes loaded, got " + progress.loaded);
assert(progress.total == 100, "Expected 100 bytes total, got " + progress.total);
cb();
},
function(cb) {
requests[0].respond(200, headers, body);
cb();
},
animationFrameFlush,
function(cb) {
assert(ajax.loading === false,
"Request complete, but loading property was true.");
assert(ajax.response.content === "plentiful", "response not parsed");
cb();
}
], done);
});
</script>
</body>
</html>

View File

@@ -0,0 +1,81 @@
<!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="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../core-ajax.html">
</head>
<body>
<core-ajax
handleAs="json"
auto></core-ajax>
<!--
Test that when core-ajax fires multiple times as requests are updated,
only the response from the most recent request is used to update the response
object.
-->
<script>
test('race-condition', function(done) {
var ajax = document.querySelector("core-ajax");
var xhr = sinon.useFakeXMLHttpRequest();
var headers = {
"Content-Type": "text/json"
};
var body = function(url) {
return '{"url": "' + url + '"}';
};
var requests = [];
xhr.onCreate = function (xhr) {
requests.push(xhr);
};
// Make request1, then request2. request2 returns first, followed by request1.
async.series([
function(cb) {
ajax.url="http://example.org/request1"
cb();
},
animationFrameFlush,
function(cb) {
ajax.url="http://example.org/request2"
cb();
},
animationFrameFlush,
function(cb) {
requests[0].respond(200, headers, body("http://example.org/request2"));
cb();
},
flush,
function(cb) {
requests[1].respond(200, headers, body("http://example.org/request1"));
cb();
},
flush,
function(cb) {
assert(ajax.response.url.match('request1'),
"Race condition detected. An earlier request's delayed response " +
"caused the more recent request's response to be overwritten.");
done();
cb();
}
], function(){});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,287 @@
<!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="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../core-ajax.html">
</head>
<body>
<core-ajax></core-ajax>
<script>
suite('core-ajax', function() {
var xhr, requests, ajax;
suiteSetup(function() {
xhr = sinon.useFakeXMLHttpRequest();
ajax = document.querySelector("core-ajax");
xhr.onCreate = function (xhr) {
requests.push(xhr);
};
// Reset the core-ajax element before each test.
ajax.auto = false;
ajax.url = '';
ajax.params = '';
ajax.handleAs = 'text';
ajax.body = '';
});
setup(function() {
requests = [];
});
suite('handleAs', function() {
suite('text', function(){
var headers = {
"Content-Type": "text/plain"
};
setup(function(done){
async.series([
function(cb){
ajax.handleAs = 'text';
ajax.url = "http://example.com/text"
ajax.auto = true;
cb();
},
animationFrameFlush,
function(cb){
requests[0].respond(200, headers, "test text");
cb();
}
], done);
});
test('Raw text should pass through', function(){
assert.equal(ajax.response, "test text")
});
});
suite('xml', function(){
var headers = {
"Content-Type": "text/xml"
};
setup(function(done){
async.series([
function(cb){
ajax.handleAs = 'xml';
ajax.url = "http://example.com/xml"
ajax.auto = true;
cb();
},
animationFrameFlush,
function(cb){
requests[0].respond(200, headers,
"<note>" +
"<to>AJ</to>" +
"<from>Dog</from>" +
"<subject>Reminder</subject>" +
"<body><q>Feed me!</q></body>" +
"</note>");
cb();
}
], done);
});
test('XML should be returned with queryable structure', function(){
var q = ajax.response.querySelector("note body q");
assert.equal(q.childNodes[0].textContent, "Feed me!");
var to = ajax.response.querySelector("to");
assert.equal(to.childNodes[0].textContent, "AJ");
})});
suite('json', function(){
var headers = {
"Content-Type": "text/json"
};
setup(function(done){
async.series([
function(cb){
ajax.handleAs = 'json';
ajax.url = "http://example.com/json"
ajax.auto = true;
cb();
},
animationFrameFlush,
function(cb){
requests[0].respond(200, headers,
'{"object" : {"list" : [2, 3, {"key": "value"}]}}');
cb();
}
], done);
});
test('JSON should be returned as an Object', function(){
var r = ajax.response;
assert.equal(r.object.list[1], 3);
assert.equal(r.object.list[2].key, "value");
});
});
suite('arraybuffer', function(){
var headers = {
"Content-Type": "text/plain"
};
setup(function(done){
async.series([
function(cb){
ajax.handleAs = 'arraybuffer';
ajax.url = "http://example.com/data"
ajax.auto = true;
cb();
},
animationFrameFlush,
function(cb){
var buf = new ArrayBuffer(8*4);
var resp = new Int32Array(buf);
resp[3] = 12;
resp[6] = 21;
requests[0].response = buf;
requests[0].respond(200, headers, 'blahblahblah');
cb();
}
], done);
});
test('arraybuffer response should be passed through', function(){
var r = ajax.response;
var ints = new Int32Array(r);
assert.equal(ints[3], 12);
assert.equal(ints[6], 21);
});
});
suite('blob', function(){});
suite('document', function(){});
});
suite('auto', function() {
suiteSetup(function(){
ajax.url = "http://example.com/"
ajax.auto = true;
});
test('url change should trigger request', function(done){
async.series([
function(cb){
ajax.url = "http://example.com/auto";
cb();
},
animationFrameFlush,
function(cb){
assert.equal(requests.length, 1);
cb();
}
], done);
});
test('params change should trigger request', function(done){
async.series([
function(cb){
ajax.params = {param: "value"};
cb();
},
animationFrameFlush,
function(cb){
assert.equal(requests.length, 1);
cb();
}
], done);
});
test('body change should trigger request', function(done){
async.series([
function(cb){
ajax.method = "POST";
ajax.body = "bodystuff";
cb();
},
animationFrameFlush,
function(cb){
assert.equal(requests.length, 1);
cb();
}
], done);
});
});
suite('events', function(){
var headers = {
"Content-Type": "text/plain"
};
var body = "somebodytext";
var responded;
setup(function(done){
async.series([
function(cb){
ajax.auto = false;
cb();
},
animationFrameFlush,
function(cb){;
ajax.handleAs = 'text';
ajax.url = "http://example.com/text"
ajax.auto = true;
cb();
},
animationFrameFlush,
], done);
responded = false;
});
suite('core-response', function(){
test('core-response should be fired on success', function(done){
window.addEventListener('core-response', function(response, xhr){
responded = true;
});
requests[0].respond(200, headers, body);
assert.isTrue(responded);
done();
});
test('core-response should not be fired on failure', function(done){
window.addEventListener('core-response', function(response, xhr){
responded = true;
});
requests[0].respond(404, headers, body);
assert.isFalse(responded);
done();
});
});
suite('core-error', function(){
test('core-error should be fired on failure', function(done){
window.addEventListener('core-error', function(response, xhr){
responded = true;
});
requests[0].respond(404, headers, body);
assert.isTrue(responded);
done();
});
test('core-error should not be fired on success', function(done){
var responded = false;
window.addEventListener('core-error', function(response, xhr){
responded = true;
});
requests[0].respond(200, headers, body);
assert.isFalse(responded);
done();
});
});
suite('core-complete', function(){
test('core-complete should be fired on success', function(done){
window.addEventListener('core-complete', function(response, xhr){
responded = true;
});
requests[0].respond(200, headers, body);
assert.isTrue(responded);
done();
});
test('core-complete should be fired on failure', function(done){
var responded = false;
window.addEventListener('core-complete', function(response, xhr){
responded = true;
});
requests[0].respond(404, headers, body);
assert.isTrue(responded);
done();
});
});
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
</head>
<body>
<script>
WCT.loadSuites([
'core-ajax-progress.html',
'core-ajax-race.html',
'core-ajax.html'
]);
</script>
</body>
</html>