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

Side by Side Diff: LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-responseText-exception.html

Issue 950063004: Fix a XHR layout test that may cause a falkiness of other tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-responseText-exception-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <html><head></head><body> 1 <!doctype html>
2 2 <script src="/js-test-resources/js-test.js"></script>
3 <p>Test bug 12914 : Trying to access XMLHttpRequest.responseText or
4 responseXML when they are not available should raise an exception </p>
5 <p>Should see "PASS" four times:</p>
6 <div id="ans"></div>
7
8 <script type="text/javascript"> 3 <script type="text/javascript">
9 function log(message) { 4 window.jsTestIsAsync = true;
10 document.getElementById("ans").appendChild(document.createTextNode(message)) ; 5 description('XMLHttpRequest.responseText should not throw even when not (loading or done).');
yhirano 2015/02/24 02:13:36 I changed this description because it was wrong: r
11 document.getElementById("ans").appendChild(document.createElement("br")); 6 function test(readyState) {
7 var xhr;
8 return new Promise(function(resolve, reject) {
9 xhr = new XMLHttpRequest();
10 xhr.onreadystatechange = function() {
11 try {
12 if (this.readyState === readyState) {
13 // We evaluate responseText because we want to make sure
14 // doing that doesn't throw.
15 var response = xhr.responseText;
16 resolve(response);
17 }
18 } catch(e) {
19 reject(e);
20 }
21 }
22 xhr.onerror = reject;
23 xhr.open('GET', 'resources/1251.html');
24 if (readyState !== 1) {
25 xhr.send();
26 }
27 }).then(function() {
28 testPassed('readyState = ' + readyState);
29 xhr.abort();
30 }, function(e) {
31 testFailed('readyState = ' + readyState, + ', ' + e);
32 });
12 } 33 }
13 34
14 function test(num) 35 var promise = Promise.resolve();
15 { 36 for (var readyState = 1; readyState <= 4; ++readyState) {
16 var xhr; 37 promise = promise.then(test.bind(undefined, readyState));
17
18 if (window.XMLHttpRequest) {
19 xhr = new XMLHttpRequest();
20 } else {
21 try {
22 xhr = new ActiveXObject("Msxml2.XMLHTTP");
23 } catch (ex) {
24 xhr = new ActiveXObject("Microsoft.XMLHTTP");
25 }
26 }
27
28 xhr.onreadystatechange = function () {
29 if (this.readyState == num) {
30 ++finishedTests;
31 try {
32 // force the evaluation for Opera
33 var response = this.responseText;
34 log("PASS");
35 } catch (e) {
36 log("FAILED");
37 }
38 }
39
40 if (finishedTests == 4 && window.testRunner)
41 testRunner.notifyDone();
42 }
43
44 xhr.open("GET", "resources/1251.html", true);
45 if (num != 1)
46 xhr.send(null);
47 } 38 }
48 39 promise.then(finishJSTest, function(e) {
49 if (window.testRunner) { 40 testFailed(e);
50 testRunner.dumpAsText(); 41 finishJSTest();
51 testRunner.waitUntilDone(); 42 });
52 }
53
54 var finishedTests = 0;
55
56 for (i = 1; i < 5; i++) {
57 test(i);
58 }
59
60 </script> 43 </script>
61
62 </body></html>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-responseText-exception-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698