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

Commit 9494529

Browse files
committed
Address comments; improve reliability of progress test.
* changed single-quoted attributes to double quoted * use a slower network request to more reliably assert about the request while it is loading * add a core-range to the progress test in order to catch the assignment to read-only property bug
1 parent 76bde89 commit 9494529

File tree

3 files changed

+43
-16
lines changed

3 files changed

+43
-16
lines changed

core-ajax.html

+4
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@
217217
*/
218218
xhrArgs: null,
219219

220+
created: function() {
221+
this.progress = {};
222+
},
223+
220224
ready: function() {
221225
this.xhr = document.createElement('core-xhr');
222226
},

demo-progress.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<polymer-element name="progress-test">
1212
<template>
1313
<core-ajax
14-
id='ajax' auto
14+
id="ajax" auto
1515
url="http://httpbin.org/drip"
1616
params="{{ {numbytes: numbytes, duration:5} }}"
1717
response="{{response}}"
@@ -23,17 +23,19 @@
2323
Ordinarily you'd gate on progress.lengthComputable, but we know the
2424
length in this case (and httpbin sadly doesn't return a
2525
Content-Length header for this requesthere).
26+
27+
https://github.com/kennethreitz/httpbin/pull/160
2628
-->
2729
<div>
28-
<button on-click='{{restart}}'>Restart</button>
29-
<template if='{{loading}}'>
30+
<button on-click="{{restart}}">Restart</button>
31+
<template if="{{loading}}">
3032
Loading...
3133
</template>
32-
<template if='{{!loading}}'>
34+
<template if="{{!loading}}">
3335
Loaded!
3436
</template>
3537
</div>
36-
<template if='{{loading && progress.loaded}}'>
38+
<template if="{{loading && progress.loaded}}">
3739
<paper-progress
3840
value="{{progress.loaded}}"
3941
min="0"

tests/html/core-ajax-progress-and-loading.html

+32-11
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,32 @@
1616
<script src="../../../polymer-test-tools/htmltest.js"></script>
1717

1818
<link rel="import" href="../../core-ajax.html">
19+
<link rel="import" href="../../../core-range/core-range.html">
1920

2021
</head>
2122
<body>
2223

2324
<polymer-element name="race-condition">
2425
<template>
2526
<!-- TODO: change this from /headers to /drip if we can get httpbin to
26-
send a Content-Length with their /drip response. -->
27+
send a Content-Length with their /drip response.
28+
The delay is needed so that we can make assertions about
29+
the intermediate state in browsers that are slow to
30+
notice attribute changes.
31+
32+
https://github.com/kennethreitz/httpbin/pull/160
33+
-->
2734
<core-ajax
28-
auto url="http://httpbin.org/headers"
29-
params="{{ {numbytes: numbytes, duration:1} }}"
35+
auto url="http://httpbin.org/delay/1"
3036
loading="{{loading}}" progress="{{progress}}"
31-
on-core-response='{{responseReceived}}'></core-ajax>
37+
on-core-response="{{responseReceived}}"></core-ajax>
38+
<core-range
39+
id="range"
40+
value="{{progress.loaded}}"
41+
min="0"
42+
max="{{progress.total}}"
43+
ratio="{{ratio}}">
44+
</core-range>
3245
</template>
3346
<script>
3447
Polymer({
@@ -53,23 +66,31 @@
5366
// Shortly after the response is received we should settle into
5467
// the final consistent state for the element.
5568
setTimeout(function() {
56-
chai.assert.equal(this.loading, false);
57-
chai.assert.equal(this.loadingWasTrue, true);
69+
chai.assert.equal(this.loading, false,
70+
'Should no longer be loading');
71+
chai.assert.equal(
72+
this.loadingWasTrue, true,
73+
'For a little while, we should have been loading.');
5874
if (this.progress && this.progress.lengthComputable) {
5975
chai.assert.equal(this.progress.total, this.progress.loaded);
6076
}
6177
this.assertConsistent();
6278
clearTimeout(this.finalTimeout);
6379
done();
64-
}.bind(this), 100);
80+
}.bind(this), 300);
6581
},
6682
assertConsistent: function() {
67-
debugger;
6883
if (this.progress && this.progress.lengthComputable) {
6984
chai.assert.isNumber(this.progress.total);
7085
chai.assert.isNumber(this.progress.loaded);
86+
chai.assert.isNumber(this.ratio);
7187
chai.assert(this.progress.loaded >= 0,
7288
'Bytes loaded should not be negative.');
89+
if (this.progress.loaded > 0) {
90+
this.$.range.update();
91+
chai.assert(this.ratio > 0,
92+
'If bytes loaded is >0, % loaded must be >0.');
93+
}
7394
chai.assert(this.progress.loaded <= this.progress.total,
7495
'Bytes loaded should be less than or equal the total.');
7596
if (this.previousLoaded !== null) {
@@ -86,9 +107,9 @@
86107
this.loadingFinished = true;
87108
}
88109
if (this.loadingFinished) {
89-
chai.assert.equal(
90-
this.loading, false,
91-
'Once loaded, the request should stay that way');
110+
chai.assert.equal(
111+
this.loading, false,
112+
'Once loaded, the request should stay that way');
92113
}
93114
}
94115
});

0 commit comments

Comments
 (0)