|
16 | 16 | <script src="../../../polymer-test-tools/htmltest.js"></script>
|
17 | 17 |
|
18 | 18 | <link rel="import" href="../../core-ajax.html">
|
| 19 | + <link rel="import" href="../../../core-range/core-range.html"> |
19 | 20 |
|
20 | 21 | </head>
|
21 | 22 | <body>
|
22 | 23 |
|
23 | 24 | <polymer-element name="race-condition">
|
24 | 25 | <template>
|
25 | 26 | <!-- 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 | + --> |
27 | 34 | <core-ajax
|
28 |
| - auto url="http://httpbin.org/headers" |
29 |
| - params="{{ {numbytes: numbytes, duration:1} }}" |
| 35 | + auto url="http://httpbin.org/delay/1" |
30 | 36 | 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> |
32 | 45 | </template>
|
33 | 46 | <script>
|
34 | 47 | Polymer({
|
|
53 | 66 | // Shortly after the response is received we should settle into
|
54 | 67 | // the final consistent state for the element.
|
55 | 68 | 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.'); |
58 | 74 | if (this.progress && this.progress.lengthComputable) {
|
59 | 75 | chai.assert.equal(this.progress.total, this.progress.loaded);
|
60 | 76 | }
|
61 | 77 | this.assertConsistent();
|
62 | 78 | clearTimeout(this.finalTimeout);
|
63 | 79 | done();
|
64 |
| - }.bind(this), 100); |
| 80 | + }.bind(this), 300); |
65 | 81 | },
|
66 | 82 | assertConsistent: function() {
|
67 |
| - debugger; |
68 | 83 | if (this.progress && this.progress.lengthComputable) {
|
69 | 84 | chai.assert.isNumber(this.progress.total);
|
70 | 85 | chai.assert.isNumber(this.progress.loaded);
|
| 86 | + chai.assert.isNumber(this.ratio); |
71 | 87 | chai.assert(this.progress.loaded >= 0,
|
72 | 88 | '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 | + } |
73 | 94 | chai.assert(this.progress.loaded <= this.progress.total,
|
74 | 95 | 'Bytes loaded should be less than or equal the total.');
|
75 | 96 | if (this.previousLoaded !== null) {
|
|
86 | 107 | this.loadingFinished = true;
|
87 | 108 | }
|
88 | 109 | 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'); |
92 | 113 | }
|
93 | 114 | }
|
94 | 115 | });
|
|
0 commit comments