<commit_before><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>mOxie: Test Runtime</title>

<!-- qunit -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>

<!-- testrunner -->
<script src="../js/reporter.js"></script>
<script src="../moxie_loader.js"></script>

<script type="text/javascript">

QUnit.config.reorder = false;
QUnit.config.testTimeout = 10000;

o.Env.swf_url = "../../bin/flash/Moxie.swf";
o.Env.xap_url = "../../bin/silverlight/Moxie.xap";

module("Runtime", {
	setup: function() {

		o.extend(this, {

			XHR: o.XMLHttpRequest,

			DOM: jQuery('#qunit-fixture'),

			runtimeOptions: {
				container: "qunit-fixture",
				swf_url: "../../bin/flash/Moxie.swf",
				xap_url: "../../bin/silverlight/Moxie.xap"
			},

			runtimeOrder: "html5,flash,silverlight,html4"
		});
	},

	teardown: function() {
	}
});


test('Prerequisites', function() {
	var rt = new o.RuntimeTarget();

	equal(typeof rt.bind, 'function', "RuntimeTarget is EventTarget.");
	equal(typeof rt.connectRuntime, 'function', "RuntimeTarget is RuntimeClient.");
});


o.each("html5,flash,silverlight,html4".split(','), function(runtime) {
	test('Initialization and destruction: ' + runtime, function() {
		var rt = new o.RuntimeTarget();

		rt.bind('RuntimeInit', function(e, runtimeObj) {
			start();
			ok(true, "RuntimeInit fired.");
			equal(runtimeObj.type, runtime, runtime + " initialized.");

			runtimeObj.getShimContainer(); // force html structure

			ok($('#qunit-fixture').find('.moxie-shim').length, "HTML structure inserted.");
			equal(runtimeObj.clients, 1, "Runtime has one client.");

			rt.disconnectRuntime();
			ok(true, "Initiate deconstruction.");
			equal(runtimeObj.clients, 0, "Runtime has no clients.");
			ok(!rt.hasEventListener('RuntimeInit'), "Event listeners unbined.");
			ok(!$('#qunit-fixture').find('.moxie-shim').length, "Runtime automatically deconstructed, HTML structure removed.");
		});

		rt.bind('RuntimeError', function() {
			start();
			ok(false, "Runtime cannot be initialized.");
		});

		stop();
		rt.connectRuntime(o.extend({}, this.runtimeOptions,  {
			runtime_order: runtime
		}));
	});
});


o.each("html5,flash,silverlight,html4".split(','), function(runtime) {
	test('Destruction without initialization: ' + runtime, function() {		
		var constructor = o.Runtime.getConstructor(runtime);
		var r = new constructor();

		ok(o.Runtime.getRuntime(r.uid), "Runtime instantiated.");
		r.destroy();
		ok(!o.Runtime.getRuntime(r.uid), "Runtime destroyed.");
	});
});



test('Fallback to the next runtime in the list due to required capability', function() {
	var rt = new o.RuntimeTarget();

	rt.bind('RuntimeInit', function(e, runtimeObj) {
		start();
		equal(runtimeObj.type, 'flash', "RuntimeTarget successfully fell back to flash.");
		rt.disconnectRuntime();
	});

	rt.bind('RuntimeError', function() {
		start();
		ok(false, "Runtime cannot be initialized.");
	});

	stop();
	rt.connectRuntime(o.extend({}, this.runtimeOptions,  {
		required_caps: {
			access_image_binary: true
		},
		runtime_order: "html4,flash"
	}));
});

test('Check what happens if capability cannot be fulfilled', function() {
	var rt = new o.RuntimeTarget();

	rt.bind('RuntimeInit', function(e, runtimeObj) {
		start();
		ok(false, "Unexpected result.");
	});

	rt.bind('RuntimeError', function() {
		start();
		ok(true, "RuntimeError fired.");
		ok(true, "Runtime cannot be initialized.");
	});

	stop();
	rt.connectRuntime(o.extend({}, this.runtimeOptions,  {
		required_caps: {
			required_capability: true
		},
		runtime_order: "html5,flash,silverlight,html4"
	}));
});

o.each("html5,flash,silverlight,html4".split(','), function(runtime) {
	test('Test can(): ' + runtime, function() {
		
		var constructor = o.Runtime.getConstructor(runtime);
		var r = new constructor();

		ok(r.can('send_multipart'), "Sending of multipart/form-data is possible.");
		r.destroy();
	});
});


// test operational modes
(function() {
	var rt;

	function initRuntimeTarget(runtime, requiredCaps, cb) {
		rt = new o.RuntimeTarget();

		rt.bind('RuntimeInit', function(e, runtimeObj) {
			start();
			cb(runtimeObj.mode);
		});

		rt.bind('RuntimeError', function() {
			start();
			cb(false);
		});

		stop();
		rt.connectRuntime(o.extend({}, this.runtimeOptions,  {
			required_caps: requiredCaps,
			runtime_order: runtime
		}));
	}

	test("Operational mode: html5", function() {
		initRuntimeTarget.call(this, "html5", {
		}, function(mode) {
			equal(mode, "browser", "For html5 runtime operational mode is always: browser");
		});
	});

	test("Operational mode: html4", function() {
		initRuntimeTarget.call(this, "html4", {
		}, function(mode) {
			equal(mode, "browser", "For html4 runtime operational mode is always: browser");
		});
	});

	test("Operational mode: flash", function() {
		initRuntimeTarget.call(this, "flash", {
			send_binary_string: true
		}, function(mode) {
			if (!mode) {
				ok(false, "Operational mode cannot be set.");
			} else {
				equal(mode, "browser", "{ send_binary_string: true } requires mode: browser");
			}
		});

		initRuntimeTarget.call(this, "flash", {
			upload_filesize: '2gb'
		}, function(mode) {
			if (!mode) {
				ok(false, "Operational mode cannot be set.");
			} else {
				equal(mode, "client", "{ upload_filesize: '2gb' } requires mode: client");
			}
		});
		
		initRuntimeTarget.call(this, "flash", {
			send_binary_string: true,
			upload_filesize: '2gb'
		}, function(mode) {
			equal(mode, false, "Operational mode cannot be set: conflicting capabilities requested.");
		});


		initRuntimeTarget.call(this, "flash", {
			drag_and_drop: true,
		}, function(mode) {
			equal(mode, false, "Operational mode cannot be set: capability either unsupported or unsupported state requested.");
		});

		initRuntimeTarget.call(this, "flash", {
			report_upload_progress: false,
		}, function(mode) {
			equal(mode, "client", "Operational mode set to default: client.");
		});
	});

}());

test('Runtime.can()', function() {
	ok(o.Runtime.can('html5', 'upload_filesize'), "html5 can upload_filesize");
});

test('Runtime.thatCan()', function() {
	var type = o.Runtime.thatCan({
		upload_filesize: '3gb',
		select_multiple: true,
		send_browser_cookies: true
	}, 'flash,html4,silverlight,html5');

	equal(type, 'silverlight', "Usable Runtime figured out by capability (" + type + ").");
});

test('Runtime.capTrue(), Runtime.capFalse(), Runtime.capTest()', function() {

	deepEqual(o.Runtime.capTrue(false), true, "Whatever the argument Runtime.capTrue() always results in true.");
	deepEqual(o.Runtime.capFalse(true), false, "Whatever the argument Runtime.capFalse() always results in false.");

	var resultFn = o.Runtime.capTest(4 - 4);
	equal(typeof resultFn, 'function', "Return value of Runtime.capTest() is a function.");
	deepEqual(resultFn(), false, "Return value of Runtime.capTest() evaluates to a result of the expression that was passed into Runtime.capTest() and then casted to boolean.");

	var caps = {
		only_true: true,
		only_false: false,
		always_true: o.Runtime.capTrue,
		always_false: o.Runtime.capFalse,
		eval_always_true: o.Runtime.capTest('false'),
		eval_always_false: o.Runtime.capTest(4 - 4)	
	}
	, runtime = new o.Runtime({}, 'test', caps)
	;

	deepEqual([
		runtime.can('only_true', true), 
		runtime.can('only_true', false),
		runtime.can('only_true', 'true')
	], [
		true,
		false,
		false
	], "cap: true - becomes true only when value to check is - true.");

	deepEqual([
		runtime.can('only_false', true), 
		runtime.can('only_false', false),
		runtime.can('only_false', 'true')
	], [
		false,
		true,
		false
	], "cap: false - becomes true only when value to check is - false.");

	deepEqual([
		runtime.can('always_true', true), 
		runtime.can('always_true', false),
		runtime.can('always_true', 'true')
	], [
		true,
		true,
		true
	], "cap: o.Runtime.capTrue(...) - is always true, whatever the value to check.");

	deepEqual([
		runtime.can('always_false', true), 
		runtime.can('always_false', false),
		runtime.can('always_false', 'true')
	], [
		false,
		false,
		false
	], "cap: o.Runtime.capFalse(...) - is always false, whatever the value to check.");

	deepEqual([
		runtime.can('eval_always_true', true), 
		runtime.can('eval_always_true', false),
		runtime.can('eval_always_true', 'true')
	], [
		true,
		true,
		true
	], "cap: o.Runtime.capTest(truthy) - is always true, whatever the value to check.");

	deepEqual([
		runtime.can('eval_always_false', true), 
		runtime.can('eval_always_false', false),
		runtime.can('eval_always_false', 'true')
	], [
		false,
		false,
		false
	], "cap: o.Runtime.capTest(falsy) - is always false, whatever the value to check.");
});

</script>
</head>
<body>
	<h1 id="qunit-header">mOxie Test Suite</h1>
	<h2 id="qunit-banner"></h2>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests">
	</ol>
    <div id="qunit-fixture" style="position: relative; top: 0 !important; left: 0 !important; width: 100%; height: 9px;"></div>
</body>
</html><commit_msg>Tests, Runtime: Remove test for can() method.<commit_after><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>mOxie: Test Runtime</title>

<!-- qunit -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css" type="text/css" />
<script src="http://code.jquery.com/qunit/qunit-git.js"></script>

<!-- testrunner -->
<script src="../js/reporter.js"></script>
<script src="../moxie_loader.js"></script>

<script type="text/javascript">

QUnit.config.reorder = false;
QUnit.config.testTimeout = 10000;

o.Env.swf_url = "../../bin/flash/Moxie.swf";
o.Env.xap_url = "../../bin/silverlight/Moxie.xap";

module("Runtime", {
	setup: function() {

		o.extend(this, {

			XHR: o.XMLHttpRequest,

			DOM: jQuery('#qunit-fixture'),

			runtimeOptions: {
				container: "qunit-fixture",
				swf_url: "../../bin/flash/Moxie.swf",
				xap_url: "../../bin/silverlight/Moxie.xap"
			},

			runtimeOrder: "html5,flash,silverlight,html4"
		});
	},

	teardown: function() {
	}
});


test('Prerequisites', function() {
	var rt = new o.RuntimeTarget();

	equal(typeof rt.bind, 'function', "RuntimeTarget is EventTarget.");
	equal(typeof rt.connectRuntime, 'function', "RuntimeTarget is RuntimeClient.");
});


o.each("html5,flash,silverlight,html4".split(','), function(runtime) {
	test('Initialization and destruction: ' + runtime, function() {
		var rt = new o.RuntimeTarget();

		rt.bind('RuntimeInit', function(e, runtimeObj) {
			start();
			ok(true, "RuntimeInit fired.");
			equal(runtimeObj.type, runtime, runtime + " initialized.");

			runtimeObj.getShimContainer(); // force html structure

			ok($('#qunit-fixture').find('.moxie-shim').length, "HTML structure inserted.");
			equal(runtimeObj.clients, 1, "Runtime has one client.");

			rt.disconnectRuntime();
			ok(true, "Initiate deconstruction.");
			equal(runtimeObj.clients, 0, "Runtime has no clients.");
			ok(!rt.hasEventListener('RuntimeInit'), "Event listeners unbined.");
			ok(!$('#qunit-fixture').find('.moxie-shim').length, "Runtime automatically deconstructed, HTML structure removed.");
		});

		rt.bind('RuntimeError', function() {
			start();
			ok(false, "Runtime cannot be initialized.");
		});

		stop();
		rt.connectRuntime(o.extend({}, this.runtimeOptions,  {
			runtime_order: runtime
		}));
	});
});


o.each("html5,flash,silverlight,html4".split(','), function(runtime) {
	test('Destruction without initialization: ' + runtime, function() {		
		var constructor = o.Runtime.getConstructor(runtime);
		var r = new constructor();

		ok(o.Runtime.getRuntime(r.uid), "Runtime instantiated.");
		r.destroy();
		ok(!o.Runtime.getRuntime(r.uid), "Runtime destroyed.");
	});
});



test('Fallback to the next runtime in the list due to required capability', function() {
	var rt = new o.RuntimeTarget();

	rt.bind('RuntimeInit', function(e, runtimeObj) {
		start();
		equal(runtimeObj.type, 'flash', "RuntimeTarget successfully fell back to flash.");
		rt.disconnectRuntime();
	});

	rt.bind('RuntimeError', function() {
		start();
		ok(false, "Runtime cannot be initialized.");
	});

	stop();
	rt.connectRuntime(o.extend({}, this.runtimeOptions,  {
		required_caps: {
			access_image_binary: true
		},
		runtime_order: "html4,flash"
	}));
});

test('Check what happens if capability cannot be fulfilled', function() {
	var rt = new o.RuntimeTarget();

	rt.bind('RuntimeInit', function(e, runtimeObj) {
		start();
		ok(false, "Unexpected result.");
	});

	rt.bind('RuntimeError', function() {
		start();
		ok(true, "RuntimeError fired.");
		ok(true, "Runtime cannot be initialized.");
	});

	stop();
	rt.connectRuntime(o.extend({}, this.runtimeOptions,  {
		required_caps: {
			required_capability: true
		},
		runtime_order: "html5,flash,silverlight,html4"
	}));
});



// test operational modes
(function() {
	var rt;

	function initRuntimeTarget(runtime, requiredCaps, cb) {
		rt = new o.RuntimeTarget();

		rt.bind('RuntimeInit', function(e, runtimeObj) {
			start();
			cb(runtimeObj.mode);
		});

		rt.bind('RuntimeError', function() {
			start();
			cb(false);
		});

		stop();
		rt.connectRuntime(o.extend({}, this.runtimeOptions,  {
			required_caps: requiredCaps,
			runtime_order: runtime
		}));
	}

	test("Operational mode: html5", function() {
		initRuntimeTarget.call(this, "html5", {
		}, function(mode) {
			equal(mode, "browser", "For html5 runtime operational mode is always: browser");
		});
	});

	test("Operational mode: html4", function() {
		initRuntimeTarget.call(this, "html4", {
		}, function(mode) {
			equal(mode, "browser", "For html4 runtime operational mode is always: browser");
		});
	});

	test("Operational mode: flash", function() {
		initRuntimeTarget.call(this, "flash", {
			send_binary_string: true
		}, function(mode) {
			if (!mode) {
				ok(false, "Operational mode cannot be set.");
			} else {
				equal(mode, "browser", "{ send_binary_string: true } requires mode: browser");
			}
		});

		initRuntimeTarget.call(this, "flash", {
			upload_filesize: '2gb'
		}, function(mode) {
			if (!mode) {
				ok(false, "Operational mode cannot be set.");
			} else {
				equal(mode, "client", "{ upload_filesize: '2gb' } requires mode: client");
			}
		});
		
		initRuntimeTarget.call(this, "flash", {
			send_binary_string: true,
			upload_filesize: '2gb'
		}, function(mode) {
			equal(mode, false, "Operational mode cannot be set: conflicting capabilities requested.");
		});


		initRuntimeTarget.call(this, "flash", {
			drag_and_drop: true,
		}, function(mode) {
			equal(mode, false, "Operational mode cannot be set: capability either unsupported or unsupported state requested.");
		});

		initRuntimeTarget.call(this, "flash", {
			report_upload_progress: false,
		}, function(mode) {
			equal(mode, "client", "Operational mode set to default: client.");
		});
	});

}());

test('Runtime.can()', function() {
	ok(o.Runtime.can('html5', 'upload_filesize'), "html5 can upload_filesize");
});

test('Runtime.thatCan()', function() {
	var type = o.Runtime.thatCan({
		upload_filesize: '3gb',
		select_multiple: true,
		send_browser_cookies: true
	}, 'flash,html4,silverlight,html5');

	equal(type, 'silverlight', "Usable Runtime figured out by capability (" + type + ").");
});

test('Runtime.capTrue(), Runtime.capFalse(), Runtime.capTest()', function() {

	deepEqual(o.Runtime.capTrue(false), true, "Whatever the argument Runtime.capTrue() always results in true.");
	deepEqual(o.Runtime.capFalse(true), false, "Whatever the argument Runtime.capFalse() always results in false.");

	var resultFn = o.Runtime.capTest(4 - 4);
	equal(typeof resultFn, 'function', "Return value of Runtime.capTest() is a function.");
	deepEqual(resultFn(), false, "Return value of Runtime.capTest() evaluates to a result of the expression that was passed into Runtime.capTest() and then casted to boolean.");

	var caps = {
		only_true: true,
		only_false: false,
		always_true: o.Runtime.capTrue,
		always_false: o.Runtime.capFalse,
		eval_always_true: o.Runtime.capTest('false'),
		eval_always_false: o.Runtime.capTest(4 - 4)	
	}
	, runtime = new o.Runtime({}, 'test', caps)
	;

	deepEqual([
		runtime.can('only_true', true), 
		runtime.can('only_true', false),
		runtime.can('only_true', 'true')
	], [
		true,
		false,
		false
	], "cap: true - becomes true only when value to check is - true.");

	deepEqual([
		runtime.can('only_false', true), 
		runtime.can('only_false', false),
		runtime.can('only_false', 'true')
	], [
		false,
		true,
		false
	], "cap: false - becomes true only when value to check is - false.");

	deepEqual([
		runtime.can('always_true', true), 
		runtime.can('always_true', false),
		runtime.can('always_true', 'true')
	], [
		true,
		true,
		true
	], "cap: o.Runtime.capTrue(...) - is always true, whatever the value to check.");

	deepEqual([
		runtime.can('always_false', true), 
		runtime.can('always_false', false),
		runtime.can('always_false', 'true')
	], [
		false,
		false,
		false
	], "cap: o.Runtime.capFalse(...) - is always false, whatever the value to check.");

	deepEqual([
		runtime.can('eval_always_true', true), 
		runtime.can('eval_always_true', false),
		runtime.can('eval_always_true', 'true')
	], [
		true,
		true,
		true
	], "cap: o.Runtime.capTest(truthy) - is always true, whatever the value to check.");

	deepEqual([
		runtime.can('eval_always_false', true), 
		runtime.can('eval_always_false', false),
		runtime.can('eval_always_false', 'true')
	], [
		false,
		false,
		false
	], "cap: o.Runtime.capTest(falsy) - is always false, whatever the value to check.");
});

</script>
</head>
<body>
	<h1 id="qunit-header">mOxie Test Suite</h1>
	<h2 id="qunit-banner"></h2>
	<h2 id="qunit-userAgent"></h2>
	<ol id="qunit-tests">
	</ol>
    <div id="qunit-fixture" style="position: relative; top: 0 !important; left: 0 !important; width: 100%; height: 9px;"></div>
</body>
</html>
{'fraction_non_alphanumeric': 0.18158271795437012, 'fraction_numerical': 0.005621073514824204, 'mean_word_length': 4.373704471424341, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, 'https://': 2, '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': '2230903', 'n_tokens_mistral': 6614, 'n_tokens_neox': 6008, 'n_words': 1373}