<commit_before>module("baidu.ajax.post");

test("正确url和正确data", function() {
	stop();
	expect(1);
	var asyncDelay = 10000;
	var urlstring = upath + "post.php";
	var arg = "var1=baidu&var2=tangram";
	var xhr = baidu.ajax.post(urlstring, arg);
	var check = function() {
    // IE下面遇到了"完成该操作所需的数据还不可使用。"的错误
		return xhr.responseText && xhr.responseText.length > 0;
	}, onsuccess = function() {
		equals(xhr.responseText, "baidutangram", "xhr return");
		start();
	}, onfail = function() {
		fail('timeout wait for reponse text in 10 seconds');
		start();
	};
	ua.delayhelper(check, onsuccess, onfail);
});

test("onsuccess", function() {
	stop();
	expect(2);
	var asyncDelay = 200;
	var urlstring = upath + "post.php";
	var arg = "var1=baidu&var2=tangram";
	function successAction(xhr, text) {
		equals(text, "baidutangram", "check text");
		equals(xhr.responseText, "baidutangram", "check xhr response text");
		start();
	}
	var xhr = baidu.ajax.post(urlstring, arg, successAction);
});

test("输入不存在url以及设定onsuccess事件", function() {
	stop();
	var asyncDelay = 2000;
	var urlstring = upath + "notexsistpage.php";
	var arg = "var1=baidu&var2=tangram";
	var xhr = baidu.ajax.post(urlstring, arg, function() {
		fail('success should not be call');
	});
	ua.delayhelper(function() {
		return xhr.responseText.length > 0;
	}, function() {
		ok(xhr.responseText.indexOf('404') >= 0, 'response text contain 404!');
		start();
	});
});

test('测试失败处理情况',function(){
	ok(false,'baidu.ajax.onfailure');
});

//参数错误引发的服务器端异常，设计用例无意义
//test("输入正确url以及错误data，设定onsuccess事件", function() {
//	stop();
//	expect(1);
//	var urlstring = upath + "post.php";
//	var arg = "var1=baidu&var9=tangram";
//	var xhr = baidu.ajax.post(urlstring, arg, function() {
//		fail('success should not be call');
//	});
//	ua.delayhelper(function() {
//		return xhr.responseText.length > 0;
//	}, function() {
//		console.log(xhr.responseText);
//		ok(xhr.responseText.indexOf('404') >= 0, 'response text contain 404!');
//		start();
//	});
//});<commit_msg>udpate case<commit_after>module("baidu.ajax.post");

test("正确url和正确data", function() {
	stop();
	expect(1);
	var asyncDelay = 10000;
	var urlstring = upath + "post.php";
	var arg = "var1=baidu&var2=tangram";
	var xhr = baidu.ajax.post(urlstring, arg);
	var check = function() {
		// IE下面遇到了"完成该操作所需的数据还不可使用。"的错误
		return xhr.responseText && xhr.responseText.length > 0;
	}, onsuccess = function() {
		equals(xhr.responseText, "baidutangram", "xhr return");
		start();
	}, onfail = function() {
		fail('timeout wait for reponse text in 10 seconds');
		start();
	};
	ua.delayhelper(check, onsuccess, onfail);
});

test("onsuccess", function() {
	stop();
	expect(2);
	var asyncDelay = 200;
	var urlstring = upath + "post.php";
	var arg = "var1=baidu&var2=tangram";
	function successAction(xhr, text) {
		equals(text, "baidutangram", "check text");
		equals(xhr.responseText, "baidutangram", "check xhr response text");
		start();
	}
	var xhr = baidu.ajax.post(urlstring, arg, successAction);
});

test("输入不存在url以及设定onsuccess事件", function() {
	stop();
	var urlstring = upath + "notexsistpage.php";
	var arg = "var1=baidu&var2=tangram";
	baidu.ajax.onfailure = function() {
		ok(true, '失败时应该调用这个函数');
		start();
	};
	var xhr = baidu.ajax.post(urlstring, arg, function() {
		fail('success should not be call');
		start();
	});
});
{'fraction_non_alphanumeric': 0.18701376421304608, 'fraction_numerical': 0.018252543387193298, 'mean_word_length': 4.7243150684931505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4477141', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1389, 'n_words': 261}