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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-responseText-exception.html
diff --git a/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-responseText-exception.html b/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-responseText-exception.html
index a7020f6d9ad15fb04f8e5ad88744b5daebfd0fd5..1bb1bb41c73e0e86db5b17229c0ba0d37ba4c8f6 100644
--- a/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-responseText-exception.html
+++ b/LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-responseText-exception.html
@@ -1,62 +1,43 @@
-<html><head></head><body>
-
-<p>Test bug 12914 : Trying to access XMLHttpRequest.responseText or
-responseXML when they are not available should raise an exception </p>
-<p>Should see "PASS" four times:</p>
-<div id="ans"></div>
-
+<!doctype html>
+<script src="/js-test-resources/js-test.js"></script>
<script type="text/javascript">
-function log(message) {
- document.getElementById("ans").appendChild(document.createTextNode(message));
- document.getElementById("ans").appendChild(document.createElement("br"));
-}
-
-function test(num)
-{
+window.jsTestIsAsync = true;
+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
+function test(readyState) {
var xhr;
-
- if (window.XMLHttpRequest) {
+ return new Promise(function(resolve, reject) {
xhr = new XMLHttpRequest();
- } else {
- try {
- xhr = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (ex) {
- xhr = new ActiveXObject("Microsoft.XMLHTTP");
- }
- }
-
- xhr.onreadystatechange = function () {
- if (this.readyState == num) {
- ++finishedTests;
+ xhr.onreadystatechange = function() {
try {
- // force the evaluation for Opera
- var response = this.responseText;
- log("PASS");
- } catch (e) {
- log("FAILED");
+ if (this.readyState === readyState) {
+ // We evaluate responseText because we want to make sure
+ // doing that doesn't throw.
+ var response = xhr.responseText;
+ resolve(response);
+ }
+ } catch(e) {
+ reject(e);
}
}
-
- if (finishedTests == 4 && window.testRunner)
- testRunner.notifyDone();
- }
-
- xhr.open("GET", "resources/1251.html", true);
- if (num != 1)
- xhr.send(null);
+ xhr.onerror = reject;
+ xhr.open('GET', 'resources/1251.html');
+ if (readyState !== 1) {
+ xhr.send();
+ }
+ }).then(function() {
+ testPassed('readyState = ' + readyState);
+ xhr.abort();
+ }, function(e) {
+ testFailed('readyState = ' + readyState, + ', ' + e);
+ });
}
-if (window.testRunner) {
- testRunner.dumpAsText();
- testRunner.waitUntilDone();
+var promise = Promise.resolve();
+for (var readyState = 1; readyState <= 4; ++readyState) {
+ promise = promise.then(test.bind(undefined, readyState));
}
-
-var finishedTests = 0;
-
-for (i = 1; i < 5; i++) {
- test(i);
-}
-
+promise.then(finishJSTest, function(e) {
+ testFailed(e);
+ finishJSTest();
+});
</script>
-
-</body></html>
« 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