Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(309)

Unified Diff: polymer_1.0.4/bower_components/iron-ajax/test/iron-request.html

Issue 1205703007: Add polymer 1.0 to npm_modules (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Renamed folder to 1.0.4 Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: polymer_1.0.4/bower_components/iron-ajax/test/iron-request.html
diff --git a/polymer_1.0.4/bower_components/iron-ajax/test/iron-request.html b/polymer_1.0.4/bower_components/iron-ajax/test/iron-request.html
new file mode 100644
index 0000000000000000000000000000000000000000..8990facd744924c3f927de6e7eef450735142236
--- /dev/null
+++ b/polymer_1.0.4/bower_components/iron-ajax/test/iron-request.html
@@ -0,0 +1,175 @@
+<!doctype html>
+<!--
+Copyright (c) 2015 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>iron-request</title>
+
+ <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
+ <script src="../../web-component-tester/browser.js"></script>
+ <script src="../../test-fixture/test-fixture-mocha.js"></script>
+
+ <link rel="import" href="../../polymer/polymer.html">
+ <link rel="import" href="../../test-fixture/test-fixture.html">
+ <link rel="import" href="../iron-request.html">
+</head>
+<body>
+ <test-fixture id="TrivialRequest">
+ <template>
+ <iron-request></iron-request>
+ </template>
+ </test-fixture>
+ <script>
+ suite('<iron-request>', function () {
+ var jsonResponseHeaders;
+ var successfulRequestOptions;
+ var request;
+ var server;
+
+ setup(function () {
+ jsonResponseHeaders = {
+ 'Content-Type': 'application/json'
+ };
+ server = sinon.fakeServer.create();
+ server.respondWith('GET', '/responds_to_get_with_json', [
+ 200,
+ jsonResponseHeaders,
+ '{"success":true}'
+ ]);
+
+ server.respondWith('GET', '/responds_to_get_with_500', [
+ 500,
+ {},
+ ''
+ ]);
+
+ server.respondWith('GET', '/responds_to_get_with_100', [
+ 100,
+ {},
+ ''
+ ]);
+
+ server.respondWith('GET', '/responds_to_get_with_0', [
+ 0,
+ jsonResponseHeaders,
+ '{"success":true}'
+ ]);
+
+
+ request = fixture('TrivialRequest');
+ successfulRequestOptions = {
+ url: '/responds_to_get_with_json'
+ };
+ });
+
+ teardown(function () {
+ server.restore();
+ });
+
+ suite('basic usage', function () {
+ test('creates network requests, requiring only `url`', function () {
+ request.send(successfulRequestOptions);
+
+ server.respond();
+
+ expect(request.response).to.be.ok;
+ });
+
+ test('sets async to true by default', function () {
+ request.send(successfulRequestOptions);
+ expect(request.xhr.async).to.be.eql(true);
+ });
+
+ test('can be aborted', function (done) {
+ request.send(successfulRequestOptions);
+
+ request.abort();
+
+ server.respond();
+
+ request.completes.then(function () {
+ done(new Error('Request did not abort appropriately!'));
+ }).catch(function (e) {
+ expect(request.response).to.not.be.ok;
+ done();
+ });
+ });
+
+ test('default responseType is text', function (done) {
+
+ request.send(successfulRequestOptions);
+ server.respond();
+
+ request.completes.then(function() {
+ expect(request.response).to.be.an('string')
+ done();
+ }).catch(function(e) {
+ done(new Error('Response was not a Object'));
+ });
+
+ });
+
+ test('responseType can be configured via handleAs option', function (done) {
+
+ var options = Object.create(successfulRequestOptions);
+ options.handleAs = 'json';
+
+ request.send(options);
+ server.respond();
+
+ request.completes.then(function() {
+ expect(request.response).to.be.an('object');
+ done();
+ }).catch(function(e) {
+ done(new Error('Response was not type Object'));
+ });
+
+ });
+
+ });
+
+ suite('special cases', function() {
+ test('treats status code 0 as success, though the outcome is ambiguous', function() {
+ // Note: file:// status code will probably be 0 no matter what happened.
+ request.send({
+ url: '/responds_to_get_with_0'
+ });
+
+ server.respond();
+
+ expect(request.succeeded).to.be.equal(true);
+ });
+ });
+
+ suite('errors', function() {
+ test('treats status codes between 1 and 199 as errors', function() {
+ request.send({
+ url: '/responds_to_get_with_100'
+ });
+
+ server.respond();
+
+ expect(request.succeeded).to.be.equal(false);
+ });
+
+ test('treats status codes between 300 and ∞ as errors', function() {
+ request.send({
+ url: '/responds_to_get_with_500'
+ });
+
+ server.respond();
+
+ expect(request.succeeded).to.be.equal(false);
+ });
+ });
+ });
+ </script>
+
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698