Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

seperated test files into JS and HTML fixtures. Added Ruby test file …

…builder and test template.
  • Loading branch information...
commit 81de0e3a77b11c87955b9ca8001f22719693aebc 1 parent a1d89b4
@tobie tobie authored
Showing with 4,966 additions and 5,315 deletions.
  1. +8 −6 Rakefile
  2. +36 −0 test/lib/jstest.rb
  3. +33 −0 test/lib/template.erb
  4. BIN  test/unit/.DS_Store
  5. +0 −451 test/unit/ajax.html
  6. +422 −0 test/unit/ajax_test.js
  7. +0 −219 test/unit/array.html
  8. +189 −0 test/unit/array_test.js
  9. +2 −34 test/unit/{base.html → base_test.js}
  10. +0 −1,769 test/unit/dom.html
  11. +1,376 −0 test/unit/dom_test.js
  12. +0 −67 test/unit/element_mixins.html
  13. +35 −0 test/unit/element_mixins_test.js
  14. +0 −322 test/unit/enumerable.html
  15. +287 −0 test/unit/enumerable_test.js
  16. +0 −268 test/unit/event.html
  17. +231 −0 test/unit/event_test.js
  18. +2 −0  test/unit/fixtures/ajax.html
  19. +1 −0  test/unit/fixtures/array.html
  20. +6 −0 test/unit/fixtures/base.html
  21. +366 −0 test/unit/fixtures/dom.html
  22. +4 −0 test/unit/fixtures/element_mixins.html
  23. +8 −0 test/unit/fixtures/enumerable.html
  24. +4 −0 test/unit/fixtures/event.html
  25. +104 −0 test/unit/fixtures/form.html
  26. +9 −0 test/unit/fixtures/position.html
  27. +69 −0 test/unit/fixtures/selector.html
  28. +18 −0 test/unit/fixtures/unittest.html
  29. +0 −489 test/unit/form.html
  30. +357 −0 test/unit/form_test.js
  31. +0 −228 test/unit/hash.html
  32. +201 −0 test/unit/hash_test.js
  33. +0 −63 test/unit/number.html
  34. +34 −0 test/unit/number_test.js
  35. +0 −82 test/unit/position.html
  36. +44 −0 test/unit/position_test.js
  37. +0 −84 test/unit/range.html
  38. +58 −0 test/unit/range_test.js
  39. +0 −477 test/unit/selector.html
  40. +377 −0 test/unit/selector_test.js
  41. +0 −563 test/unit/string.html
  42. +537 −0 test/unit/string_test.js
  43. +0 −193 test/unit/unit_tests.html
  44. +148 −0 test/unit/unittest_test.js
View
14 Rakefile
@@ -46,7 +46,7 @@ Rake::PackageTask.new('prototype', PROTOTYPE_VERSION) do |package|
end
desc "Builds the distribution, runs the JavaScript unit tests and collects their results."
-task :test => [:dist, :test_units]
+task :test => [:build_tests, :dist, :test_units]
require 'test/lib/jstest'
desc "Runs all the JavaScript unit tests and collects the results"
@@ -58,9 +58,9 @@ JavaScriptTestTask.new(:test_units) do |t|
t.mount("/dist")
t.mount("/test")
- Dir["test/unit/*.html"].sort.each do |test_file|
+ Dir["test/unit/tmp/*_test.html"].sort.each do |test_file|
tests = testcases ? { :url => "/#{test_file}", :testcases => testcases } : "/#{test_file}"
- test_filename = test_file[/.*\/(.+?)\.html/, 1]
+ test_filename = test_file[/.*\/(.+?)_test\.html/, 1]
t.run(tests) unless tests_to_run && !tests_to_run.include?(test_filename)
end
@@ -69,6 +69,8 @@ JavaScriptTestTask.new(:test_units) do |t|
end
end
-task :clean_package_source do
- rm_rf File.join(PROTOTYPE_PKG_DIR, "prototype-#{PROTOTYPE_VERSION}")
-end
+task :build_tests do
+ Dir["test/unit/*_test.js"].each do |test_file|
+ TestBuilder.new(test_file).render
+ end
+end
View
36 test/lib/jstest.rb
@@ -3,6 +3,7 @@
require 'webrick'
require 'fileutils'
include FileUtils
+require 'erb'
class Browser
def supported?; true; end
@@ -380,3 +381,38 @@ def browser(browser)
@browsers<<browser
end
end
+
+class TestBuilder
+ UNITTEST_DIR = File.expand_path('test')
+ TEMPLATE = File.join(UNITTEST_DIR, 'lib', 'template.erb')
+ FIXTURES_EXTENSION = "html"
+ FIXTURES_DIR = File.join(UNITTEST_DIR, 'unit', 'fixtures')
+
+ def initialize(filename)
+ @filename = filename
+ @js_filename = File.basename(@filename)
+ @basename = @js_filename.sub("_test.js", "")
+ @fixtures_filename = "#{@basename}.#{FIXTURES_EXTENSION}"
+ @title = @basename.gsub("_", " ").strip.capitalize
+ end
+
+ def find_fixtures
+ @fixtures = ""
+ file = File.join(FIXTURES_DIR, @fixtures_filename)
+ if File.exists?(file)
+ File.open(file).each { |line| @fixtures << line }
+ end
+ end
+
+ def render
+ find_fixtures
+ File.open(destination, "w+") do |file|
+ file << ERB.new(IO.read(TEMPLATE), nil, "%").result(binding)
+ end
+ end
+
+ def destination
+ basename = File.basename(@filename, ".js")
+ File.join(UNITTEST_DIR, 'unit', 'tmp', "#{basename}.html")
+ end
+end
View
33 test/lib/template.erb
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <title>Prototype Unit test file | <%= @title %></title>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <script type="text/javascript" charset="utf-8">
+ var eventResults = {};
+ var originalElement = Element;
+ </script>
+ <script src="../../../dist/prototype.js" type="text/javascript"></script>
+ <script src="../../lib/unittest.js" type="text/javascript"></script>
+ <script src="../<%= @js_filename %>" type="text/javascript"></script>
+
+ <link rel="stylesheet" href="../../test.css" type="text/css" />
+</head>
+<body>
+<h1>Prototype Unit test file</h1>
+<h2><%= @title %></h2>
+
+<!-- This file is programmatically generated. Do not attempt to modify it. Instead, modify <%= @fixtures_filename %> -->
+
+<!-- Log output -->
+<div id="testlog"></div>
+
+<!-- Fixtures start -->
+<%= @fixtures %>
+<!-- Fixtures end -->
+</body>
+</html>
+<script type="text/javascript" charset="utf-8">
+ eventResults.endOfDocument = true;
+</script>
View
BIN  test/unit/.DS_Store
Binary file not shown
View
451 test/unit/ajax.html
@@ -1,451 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <title>Prototype Unit test file</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <script src="../../dist/prototype.js" type="text/javascript"></script>
- <script src="../lib/unittest.js" type="text/javascript"></script>
- <link rel="stylesheet" href="../test.css" type="text/css" />
-</head>
-<body>
-<h1>Prototype Unit test file</h1>
-<p>
- Test of utility functions in ajax.js
-</p>
-
-<!-- Log output -->
-<div id="testlog"> </div>
-<div id="content"></div>
-<div id="content2" style="color:red"></div>
-
-<!-- Tests follow -->
-<script type="text/javascript" language="javascript" charset="utf-8">
-// <![CDATA[
-
- var Fixtures = {
- js: {
- responseBody: '$("content").update("<H2>Hello world!</H2>");',
- 'Content-Type': ' text/javascript '
- },
-
- html: {
- responseBody: "Pack my box with <em>five dozen</em> liquor jugs! " +
- "Oh, how <strong>quickly</strong> daft jumping zebras vex..."
- },
-
- xml: {
- responseBody: '<?xml version="1.0" encoding="UTF-8" ?><name attr="foo">bar</name>',
- 'Content-Type': 'application/xml'
- },
-
- json: {
- responseBody: '{\n\r"test": 123}',
- 'Content-Type': 'application/json'
- },
-
- jsonWithoutContentType: {
- responseBody: '{"test": 123}'
- },
-
- invalidJson: {
- responseBody: '{});window.attacked = true;({}',
- 'Content-Type': 'application/json'
- },
-
- headerJson: {
- 'X-JSON': '{"test": "hello #éà"}'
- }
- };
-
- var extendDefault = function(options) {
- return Object.extend({
- asynchronous: false,
- method: 'get',
- onException: function(e) { throw e }
- }, options);
- };
-
- var responderCounter = 0;
-
- // lowercase comparison because of MSIE which presents HTML tags in uppercase
- var sentence = ("Pack my box with <em>five dozen</em> liquor jugs! " +
- "Oh, how <strong>quickly</strong> daft jumping zebras vex...").toLowerCase();
-
- var message = 'You must be running your tests from rake to test this feature.';
-
- new Test.Unit.Runner({
- setup: function() {
- $('content').update('');
- $('content2').update('');
- },
-
- teardown: function() {
- // hack to cleanup responders
- Ajax.Responders.responders = [Ajax.Responders.responders[0]];
- },
-
- testSynchronousRequest: function() {
- this.assertEqual("", $("content").innerHTML);
-
- this.assertEqual(0, Ajax.activeRequestCount);
- new Ajax.Request("fixtures/hello.js", {
- asynchronous: false,
- method: 'GET',
- evalJS: 'force'
- });
- this.assertEqual(0, Ajax.activeRequestCount);
-
- var h2 = $("content").firstChild;
- this.assertEqual("Hello world!", h2.innerHTML);
- },
-
- testAsynchronousRequest: function() {
- this.assertEqual("", $("content").innerHTML);
-
- new Ajax.Request("fixtures/hello.js", {
- asynchronous: true,
- method: 'get',
- evalJS: 'force'
- });
- this.wait(1000, function() {
- var h2 = $("content").firstChild;
- this.assertEqual("Hello world!", h2.innerHTML);
- });
- },
-
- testUpdater: function() {
- this.assertEqual("", $("content").innerHTML);
-
- new Ajax.Updater("content", "fixtures/content.html", { method:'get' });
-
- this.wait(1000, function() {
- this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
-
- $('content').update('');
- this.assertEqual("", $("content").innerHTML);
-
- new Ajax.Updater({ success:"content", failure:"content2" },
- "fixtures/content.html", { method:'get', parameters:{ pet:'monkey' } });
-
- new Ajax.Updater("", "fixtures/content.html", { method:'get', parameters:"pet=monkey" });
-
- this.wait(1000, function() {
- this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
- this.assertEqual("", $("content2").innerHTML);
- });
- });
- },
-
- testUpdaterWithInsertion: function() {
- $('content').update();
- new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: Insertion.Top });
- this.wait(1000, function() {
- this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
- $('content').update();
- new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'bottom' });
- this.wait(1000, function() {
- this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
-
- $('content').update();
- new Ajax.Updater("content", "fixtures/content.html", { method:'get', insertion: 'after' });
- this.wait(1000, function() {
- this.assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase());
- });
- });
- });
- },
-
- testUpdaterOptions: function() {
- var options = {
- method: 'get',
- asynchronous: false,
- evalJS: 'force',
- onComplete: Prototype.emptyFunction
- }
- var request = new Ajax.Updater("content", "fixtures/hello.js", options);
- request.options.onComplete = function() {};
- this.assertIdentical(Prototype.emptyFunction, options.onComplete);
- },
-
- testResponders: function(){
- // check for internal responder
- this.assertEqual(1, Ajax.Responders.responders.length);
-
- var dummyResponder = {
- onComplete: function(req) { /* dummy */ }
- };
-
- Ajax.Responders.register(dummyResponder);
- this.assertEqual(2, Ajax.Responders.responders.length);
-
- // don't add twice
- Ajax.Responders.register(dummyResponder);
- this.assertEqual(2, Ajax.Responders.responders.length);
-
- Ajax.Responders.unregister(dummyResponder);
- this.assertEqual(1, Ajax.Responders.responders.length);
-
- var responder = {
- onCreate: function(req){ responderCounter++ },
- onLoading: function(req){ responderCounter++ },
- onComplete: function(req){ responderCounter++ }
- };
- Ajax.Responders.register(responder);
-
- this.assertEqual(0, responderCounter);
- this.assertEqual(0, Ajax.activeRequestCount);
- new Ajax.Request("fixtures/content.html", { method:'get', parameters:"pet=monkey" });
- this.assertEqual(1, responderCounter);
- this.assertEqual(1, Ajax.activeRequestCount);
-
- this.wait(1000,function() {
- this.assertEqual(3, responderCounter);
- this.assertEqual(0, Ajax.activeRequestCount);
- });
- },
-
- testEvalResponseShouldBeCalledBeforeOnComplete: function() {
- if (this.isRunningFromRake) {
- this.assertEqual("", $("content").innerHTML);
-
- this.assertEqual(0, Ajax.activeRequestCount);
- new Ajax.Request("fixtures/hello.js", extendDefault({
- onComplete: function(response) { this.assertNotEqual("", $("content").innerHTML) }.bind(this)
- }));
- this.assertEqual(0, Ajax.activeRequestCount);
-
- var h2 = $("content").firstChild;
- this.assertEqual("Hello world!", h2.innerHTML);
- } else {
- this.info(message);
- }
- },
-
- testContentTypeSetForSimulatedVerbs: function() {
- if (this.isRunningFromRake) {
- new Ajax.Request('/inspect', extendDefault({
- method: 'put',
- contentType: 'application/bogus',
- onComplete: function(response) {
- this.assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']);
- }.bind(this)
- }));
- } else {
- this.info(message);
- }
- },
-
- testOnCreateCallback: function() {
- new Ajax.Request("fixtures/content.html", extendDefault({
- onCreate: function(transport) { this.assertEqual(0, transport.readyState) }.bind(this),
- onComplete: function(transport) { this.assertNotEqual(0, transport.readyState) }.bind(this)
- }));
- },
-
- testEvalJS: function() {
- if (this.isRunningFromRake) {
-
- $('content').update();
- new Ajax.Request("/response", extendDefault({
- parameters: Fixtures.js,
- onComplete: function(transport) {
- var h2 = $("content").firstChild;
- this.assertEqual("Hello world!", h2.innerHTML);
- }.bind(this)
- }));
-
- $('content').update();
- new Ajax.Request("/response", extendDefault({
- evalJS: false,
- parameters: Fixtures.js,
- onComplete: function(transport) {
- this.assertEqual("", $("content").innerHTML);
- }.bind(this)
- }));
- } else {
- this.info(message);
- }
-
- $('content').update();
- new Ajax.Request("fixtures/hello.js", extendDefault({
- evalJS: 'force',
- onComplete: function(transport) {
- var h2 = $("content").firstChild;
- this.assertEqual("Hello world!", h2.innerHTML);
- }.bind(this)
- }));
- },
-
- testCallbacks: function() {
- var options = extendDefault({
- onCreate: function(transport) { this.assertInstanceOf(Ajax.Response, transport) }.bind(this)
- });
-
- Ajax.Request.Events.each(function(state){
- options['on' + state] = options.onCreate;
- });
-
- new Ajax.Request("fixtures/content.html", options);
- },
-
- testResponseText: function() {
- new Ajax.Request("fixtures/empty.html", extendDefault({
- onComplete: function(transport) { this.assertEqual('', transport.responseText) }.bind(this)
- }));
-
- new Ajax.Request("fixtures/content.html", extendDefault({
- onComplete: function(transport) { this.assertEqual(sentence, transport.responseText.toLowerCase()) }.bind(this)
- }));
- },
-
- testResponseXML: function() {
- if (this.isRunningFromRake) {
- new Ajax.Request("/response", extendDefault({
- parameters: Fixtures.xml,
- onComplete: function(transport) {
- this.assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr'))
- }.bind(this)
- }));
- } else {
- this.info(message);
- }
- },
-
- testResponseJSON: function() {
- if (this.isRunningFromRake) {
- new Ajax.Request("/response", extendDefault({
- parameters: Fixtures.json,
- onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this)
- }));
-
- new Ajax.Request("/response", extendDefault({
- parameters: {
- 'Content-Length': 0,
- 'Content-Type': 'application/json'
- },
- onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
- }));
-
- new Ajax.Request("/response", extendDefault({
- evalJSON: false,
- parameters: Fixtures.json,
- onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
- }));
-
- new Ajax.Request("/response", extendDefault({
- parameters: Fixtures.jsonWithoutContentType,
- onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
- }));
-
- new Ajax.Request("/response", extendDefault({
- sanitizeJSON: true,
- parameters: Fixtures.invalidJson,
- onException: function(request, error) {
- this.assert(error.message.include('Badly formed JSON string'));
- this.assertInstanceOf(Ajax.Request, request);
- }.bind(this)
- }));
- } else {
- this.info(message);
- }
-
- new Ajax.Request("fixtures/data.json", extendDefault({
- evalJSON: 'force',
- onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this)
- }));
- },
-
- testHeaderJSON: function() {
- if (this.isRunningFromRake) {
- new Ajax.Request("/response", extendDefault({
- parameters: Fixtures.headerJson,
- onComplete: function(transport, json) {
- this.assertEqual('hello #éà', transport.headerJSON.test);
- this.assertEqual('hello #éà', json.test);
- }.bind(this)
- }));
-
- new Ajax.Request("/response", extendDefault({
- onComplete: function(transport, json) {
- this.assertNull(transport.headerJSON)
- this.assertNull(json)
- }.bind(this)
- }));
- } else {
- this.info(message);
- }
- },
-
- testGetHeader: function() {
- if (this.isRunningFromRake) {
- new Ajax.Request("/response", extendDefault({
- parameters: { 'X-TEST': 'some value' },
- onComplete: function(transport) {
- this.assertEqual('some value', transport.getHeader('X-Test'));
- this.assertNull(transport.getHeader('X-Inexistant'));
- }.bind(this)
- }));
- } else {
- this.info(message);
- }
- },
-
- testParametersCanBeHash: function() {
- if (this.isRunningFromRake) {
- new Ajax.Request("/response", extendDefault({
- parameters: $H({ "one": "two", "three": "four" }),
- onComplete: function(transport) {
- this.assertEqual("two", transport.getHeader("one"));
- this.assertEqual("four", transport.getHeader("three"));
- this.assertNull(transport.getHeader("toObject"));
- }.bind(this)
- }));
- } else {
- this.info(message);
- }
- },
-
- testIsSameOriginMethod: function() {
- var isSameOrigin = Ajax.Request.prototype.isSameOrigin;
- this.assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html');
- this.assert(isSameOrigin.call({ url: window.location.toString() }), window.location);
- this.assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com');
-
- if (this.isRunningFromRake) {
- Ajax.Request.prototype.isSameOrigin = function() {
- return false
- };
-
- $("content").update('same origin policy');
- new Ajax.Request("/response", extendDefault({
- parameters: Fixtures.js,
- onComplete: function(transport) {
- this.assertEqual("same origin policy", $("content").innerHTML);
- }.bind(this)
- }));
-
- new Ajax.Request("/response", extendDefault({
- parameters: Fixtures.invalidJson,
- onException: function(request, error) {
- this.assert(error.message.include('Badly formed JSON string'));
- }.bind(this)
- }));
-
- new Ajax.Request("/response", extendDefault({
- parameters: { 'X-JSON': '{});window.attacked = true;({}' },
- onException: function(request, error) {
- this.assert(error.message.include('Badly formed JSON string'));
- }.bind(this)
- }));
-
- Ajax.Request.prototype.isSameOrigin = isSameOrigin;
- } else {
- this.info(message);
- }
- }
- });
-// ]]>
-</script>
-</body>
-</html>
View
422 test/unit/ajax_test.js
@@ -0,0 +1,422 @@
+var Fixtures = {
+ js: {
+ responseBody: '$("content").update("<H2>Hello world!</H2>");',
+ 'Content-Type': ' text/javascript '
+ },
+
+ html: {
+ responseBody: "Pack my box with <em>five dozen</em> liquor jugs! " +
+ "Oh, how <strong>quickly</strong> daft jumping zebras vex..."
+ },
+
+ xml: {
+ responseBody: '<?xml version="1.0" encoding="UTF-8" ?><name attr="foo">bar</name>',
+ 'Content-Type': 'application/xml'
+ },
+
+ json: {
+ responseBody: '{\n\r"test": 123}',
+ 'Content-Type': 'application/json'
+ },
+
+ jsonWithoutContentType: {
+ responseBody: '{"test": 123}'
+ },
+
+ invalidJson: {
+ responseBody: '{});window.attacked = true;({}',
+ 'Content-Type': 'application/json'
+ },
+
+ headerJson: {
+ 'X-JSON': '{"test": "hello #éà"}'
+ }
+};
+
+var extendDefault = function(options) {
+ return Object.extend({
+ asynchronous: false,
+ method: 'get',
+ onException: function(e) { throw e }
+ }, options);
+};
+
+var responderCounter = 0;
+
+// lowercase comparison because of MSIE which presents HTML tags in uppercase
+var sentence = ("Pack my box with <em>five dozen</em> liquor jugs! " +
+"Oh, how <strong>quickly</strong> daft jumping zebras vex...").toLowerCase();
+
+var message = 'You must be running your tests from rake to test this feature.';
+
+new Test.Unit.Runner({
+ setup: function() {
+ $('content').update('');
+ $('content2').update('');
+ },
+
+ teardown: function() {
+ // hack to cleanup responders
+ Ajax.Responders.responders = [Ajax.Responders.responders[0]];
+ },
+
+ testSynchronousRequest: function() {
+ this.assertEqual("", $("content").innerHTML);
+
+ this.assertEqual(0, Ajax.activeRequestCount);
+ new Ajax.Request("../fixtures/hello.js", {
+ asynchronous: false,
+ method: 'GET',
+ evalJS: 'force'
+ });
+ this.assertEqual(0, Ajax.activeRequestCount);
+
+ var h2 = $("content").firstChild;
+ this.assertEqual("Hello world!", h2.innerHTML);
+ },
+
+ testAsynchronousRequest: function() {
+ this.assertEqual("", $("content").innerHTML);
+
+ new Ajax.Request("../fixtures/hello.js", {
+ asynchronous: true,
+ method: 'get',
+ evalJS: 'force'
+ });
+ this.wait(1000, function() {
+ var h2 = $("content").firstChild;
+ this.assertEqual("Hello world!", h2.innerHTML);
+ });
+ },
+
+ testUpdater: function() {
+ this.assertEqual("", $("content").innerHTML);
+
+ new Ajax.Updater("content", "../fixtures/content.html", { method:'get' });
+
+ this.wait(1000, function() {
+ this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
+
+ $('content').update('');
+ this.assertEqual("", $("content").innerHTML);
+
+ new Ajax.Updater({ success:"content", failure:"content2" },
+ "../fixtures/content.html", { method:'get', parameters:{ pet:'monkey' } });
+
+ new Ajax.Updater("", "../fixtures/content.html", { method:'get', parameters:"pet=monkey" });
+
+ this.wait(1000, function() {
+ this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
+ this.assertEqual("", $("content2").innerHTML);
+ });
+ });
+ },
+
+ testUpdaterWithInsertion: function() {
+ $('content').update();
+ new Ajax.Updater("content", "../fixtures/content.html", { method:'get', insertion: Insertion.Top });
+ this.wait(1000, function() {
+ this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
+ $('content').update();
+ new Ajax.Updater("content", "../fixtures/content.html", { method:'get', insertion: 'bottom' });
+ this.wait(1000, function() {
+ this.assertEqual(sentence, $("content").innerHTML.strip().toLowerCase());
+
+ $('content').update();
+ new Ajax.Updater("content", "../fixtures/content.html", { method:'get', insertion: 'after' });
+ this.wait(1000, function() {
+ this.assertEqual('five dozen', $("content").next().innerHTML.strip().toLowerCase());
+ });
+ });
+ });
+ },
+
+ testUpdaterOptions: function() {
+ var options = {
+ method: 'get',
+ asynchronous: false,
+ evalJS: 'force',
+ onComplete: Prototype.emptyFunction
+ }
+ var request = new Ajax.Updater("content", "../fixtures/hello.js", options);
+ request.options.onComplete = function() {};
+ this.assertIdentical(Prototype.emptyFunction, options.onComplete);
+ },
+
+ testResponders: function(){
+ // check for internal responder
+ this.assertEqual(1, Ajax.Responders.responders.length);
+
+ var dummyResponder = {
+ onComplete: function(req) { /* dummy */ }
+ };
+
+ Ajax.Responders.register(dummyResponder);
+ this.assertEqual(2, Ajax.Responders.responders.length);
+
+ // don't add twice
+ Ajax.Responders.register(dummyResponder);
+ this.assertEqual(2, Ajax.Responders.responders.length);
+
+ Ajax.Responders.unregister(dummyResponder);
+ this.assertEqual(1, Ajax.Responders.responders.length);
+
+ var responder = {
+ onCreate: function(req){ responderCounter++ },
+ onLoading: function(req){ responderCounter++ },
+ onComplete: function(req){ responderCounter++ }
+ };
+ Ajax.Responders.register(responder);
+
+ this.assertEqual(0, responderCounter);
+ this.assertEqual(0, Ajax.activeRequestCount);
+ new Ajax.Request("../fixtures/content.html", { method:'get', parameters:"pet=monkey" });
+ this.assertEqual(1, responderCounter);
+ this.assertEqual(1, Ajax.activeRequestCount);
+
+ this.wait(1000,function() {
+ this.assertEqual(3, responderCounter);
+ this.assertEqual(0, Ajax.activeRequestCount);
+ });
+ },
+
+ testEvalResponseShouldBeCalledBeforeOnComplete: function() {
+ if (this.isRunningFromRake) {
+ this.assertEqual("", $("content").innerHTML);
+
+ this.assertEqual(0, Ajax.activeRequestCount);
+ new Ajax.Request("../fixtures/hello.js", extendDefault({
+ onComplete: function(response) { this.assertNotEqual("", $("content").innerHTML) }.bind(this)
+ }));
+ this.assertEqual(0, Ajax.activeRequestCount);
+
+ var h2 = $("content").firstChild;
+ this.assertEqual("Hello world!", h2.innerHTML);
+ } else {
+ this.info(message);
+ }
+ },
+
+ testContentTypeSetForSimulatedVerbs: function() {
+ if (this.isRunningFromRake) {
+ new Ajax.Request('/inspect', extendDefault({
+ method: 'put',
+ contentType: 'application/bogus',
+ onComplete: function(response) {
+ this.assertEqual('application/bogus; charset=UTF-8', response.responseJSON.headers['content-type']);
+ }.bind(this)
+ }));
+ } else {
+ this.info(message);
+ }
+ },
+
+ testOnCreateCallback: function() {
+ new Ajax.Request("../fixtures/content.html", extendDefault({
+ onCreate: function(transport) { this.assertEqual(0, transport.readyState) }.bind(this),
+ onComplete: function(transport) { this.assertNotEqual(0, transport.readyState) }.bind(this)
+ }));
+ },
+
+ testEvalJS: function() {
+ if (this.isRunningFromRake) {
+
+ $('content').update();
+ new Ajax.Request("/response", extendDefault({
+ parameters: Fixtures.js,
+ onComplete: function(transport) {
+ var h2 = $("content").firstChild;
+ this.assertEqual("Hello world!", h2.innerHTML);
+ }.bind(this)
+ }));
+
+ $('content').update();
+ new Ajax.Request("/response", extendDefault({
+ evalJS: false,
+ parameters: Fixtures.js,
+ onComplete: function(transport) {
+ this.assertEqual("", $("content").innerHTML);
+ }.bind(this)
+ }));
+ } else {
+ this.info(message);
+ }
+
+ $('content').update();
+ new Ajax.Request("../fixtures/hello.js", extendDefault({
+ evalJS: 'force',
+ onComplete: function(transport) {
+ var h2 = $("content").firstChild;
+ this.assertEqual("Hello world!", h2.innerHTML);
+ }.bind(this)
+ }));
+ },
+
+ testCallbacks: function() {
+ var options = extendDefault({
+ onCreate: function(transport) { this.assertInstanceOf(Ajax.Response, transport) }.bind(this)
+ });
+
+ Ajax.Request.Events.each(function(state){
+ options['on' + state] = options.onCreate;
+ });
+
+ new Ajax.Request("../fixtures/content.html", options);
+ },
+
+ testResponseText: function() {
+ new Ajax.Request("../fixtures/empty.html", extendDefault({
+ onComplete: function(transport) { this.assertEqual('', transport.responseText) }.bind(this)
+ }));
+
+ new Ajax.Request("../fixtures/content.html", extendDefault({
+ onComplete: function(transport) { this.assertEqual(sentence, transport.responseText.toLowerCase()) }.bind(this)
+ }));
+ },
+
+ testResponseXML: function() {
+ if (this.isRunningFromRake) {
+ new Ajax.Request("/response", extendDefault({
+ parameters: Fixtures.xml,
+ onComplete: function(transport) {
+ this.assertEqual('foo', transport.responseXML.getElementsByTagName('name')[0].getAttribute('attr'))
+ }.bind(this)
+ }));
+ } else {
+ this.info(message);
+ }
+ },
+
+ testResponseJSON: function() {
+ if (this.isRunningFromRake) {
+ new Ajax.Request("/response", extendDefault({
+ parameters: Fixtures.json,
+ onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this)
+ }));
+
+ new Ajax.Request("/response", extendDefault({
+ parameters: {
+ 'Content-Length': 0,
+ 'Content-Type': 'application/json'
+ },
+ onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
+ }));
+
+ new Ajax.Request("/response", extendDefault({
+ evalJSON: false,
+ parameters: Fixtures.json,
+ onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
+ }));
+
+ new Ajax.Request("/response", extendDefault({
+ parameters: Fixtures.jsonWithoutContentType,
+ onComplete: function(transport) { this.assertNull(transport.responseJSON) }.bind(this)
+ }));
+
+ new Ajax.Request("/response", extendDefault({
+ sanitizeJSON: true,
+ parameters: Fixtures.invalidJson,
+ onException: function(request, error) {
+ this.assert(error.message.include('Badly formed JSON string'));
+ this.assertInstanceOf(Ajax.Request, request);
+ }.bind(this)
+ }));
+ } else {
+ this.info(message);
+ }
+
+ new Ajax.Request("../fixtures/data.json", extendDefault({
+ evalJSON: 'force',
+ onComplete: function(transport) { this.assertEqual(123, transport.responseJSON.test) }.bind(this)
+ }));
+ },
+
+ testHeaderJSON: function() {
+ if (this.isRunningFromRake) {
+ new Ajax.Request("/response", extendDefault({
+ parameters: Fixtures.headerJson,
+ onComplete: function(transport, json) {
+ this.assertEqual('hello #éà', transport.headerJSON.test);
+ this.assertEqual('hello #éà', json.test);
+ }.bind(this)
+ }));
+
+ new Ajax.Request("/response", extendDefault({
+ onComplete: function(transport, json) {
+ this.assertNull(transport.headerJSON)
+ this.assertNull(json)
+ }.bind(this)
+ }));
+ } else {
+ this.info(message);
+ }
+ },
+
+ testGetHeader: function() {
+ if (this.isRunningFromRake) {
+ new Ajax.Request("/response", extendDefault({
+ parameters: { 'X-TEST': 'some value' },
+ onComplete: function(transport) {
+ this.assertEqual('some value', transport.getHeader('X-Test'));
+ this.assertNull(transport.getHeader('X-Inexistant'));
+ }.bind(this)
+ }));
+ } else {
+ this.info(message);
+ }
+ },
+
+ testParametersCanBeHash: function() {
+ if (this.isRunningFromRake) {
+ new Ajax.Request("/response", extendDefault({
+ parameters: $H({ "one": "two", "three": "four" }),
+ onComplete: function(transport) {
+ this.assertEqual("two", transport.getHeader("one"));
+ this.assertEqual("four", transport.getHeader("three"));
+ this.assertNull(transport.getHeader("toObject"));
+ }.bind(this)
+ }));
+ } else {
+ this.info(message);
+ }
+ },
+
+ testIsSameOriginMethod: function() {
+ var isSameOrigin = Ajax.Request.prototype.isSameOrigin;
+ this.assert(isSameOrigin.call({ url: '/foo/bar.html' }), '/foo/bar.html');
+ this.assert(isSameOrigin.call({ url: window.location.toString() }), window.location);
+ this.assert(!isSameOrigin.call({ url: 'http://example.com' }), 'http://example.com');
+
+ if (this.isRunningFromRake) {
+ Ajax.Request.prototype.isSameOrigin = function() {
+ return false
+ };
+
+ $("content").update('same origin policy');
+ new Ajax.Request("/response", extendDefault({
+ parameters: Fixtures.js,
+ onComplete: function(transport) {
+ this.assertEqual("same origin policy", $("content").innerHTML);
+ }.bind(this)
+ }));
+
+ new Ajax.Request("/response", extendDefault({
+ parameters: Fixtures.invalidJson,
+ onException: function(request, error) {
+ this.assert(error.message.include('Badly formed JSON string'));
+ }.bind(this)
+ }));
+
+ new Ajax.Request("/response", extendDefault({
+ parameters: { 'X-JSON': '{});window.attacked = true;({}' },
+ onException: function(request, error) {
+ this.assert(error.message.include('Badly formed JSON string'));
+ }.bind(this)
+ }));
+
+ Ajax.Request.prototype.isSameOrigin = isSameOrigin;
+ } else {
+ this.info(message);
+ }
+ }
+});
View
219 test/unit/array.html
@@ -1,219 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <title>Prototype Unit test file</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <script src="../../dist/prototype.js" type="text/javascript"></script>
- <script src="../lib/unittest.js" type="text/javascript"></script>
- <link rel="stylesheet" href="../test.css" type="text/css" />
-</head>
-<body>
-<h1>Prototype Unit test file</h1>
-<p>
- Test of the Array.prototype extensions
-</p>
-
-<!-- Log output -->
-<div id="testlog"> </div>
-
-<div id="test_node">22<span id="span_1"></span><span id="span_2"></span></div>
-
-<!-- Tests follow -->
-<script type="text/javascript" language="javascript" charset="utf-8">
-// <![CDATA[
-
- var globalArgsTest = 'nothing to see here';
-
- new Test.Unit.Runner({
- test$A: function(){
- this.assertEnumEqual([], $A({}));
- },
-
- testToArrayOnArguments: function(){
- function toArrayOnArguments(){
- globalArgsTest = $A(arguments);
- }
- toArrayOnArguments();
- this.assertEnumEqual([], globalArgsTest);
- toArrayOnArguments('foo');
- this.assertEnumEqual(['foo'], globalArgsTest);
- toArrayOnArguments('foo','bar');
- this.assertEnumEqual(['foo','bar'], globalArgsTest);
- },
-
- testToArrayOnNodeList: function(){
- // direct HTML
- this.assertEqual(3, $A($('test_node').childNodes).length);
-
- // DOM
- var element = document.createElement('div');
- element.appendChild(document.createTextNode('22'));
- (2).times(function(){ element.appendChild(document.createElement('span')) });
- this.assertEqual(3, $A(element.childNodes).length);
-
- // HTML String
- element = document.createElement('div');
- $(element).update('22<span></span><span></span');
- this.assertEqual(3, $A(element.childNodes).length);
- },
-
- testClear: function(){
- this.assertEnumEqual([], [].clear());
- this.assertEnumEqual([], [1].clear());
- this.assertEnumEqual([], [1,2].clear());
- },
-
- testClone: function(){
- this.assertEnumEqual([], [].clone());
- this.assertEnumEqual([1], [1].clone());
- this.assertEnumEqual([1,2], [1,2].clone());
- this.assertEnumEqual([0,1,2], [0,1,2].clone());
- var a = [0,1,2];
- var b = a;
- this.assertIdentical(a, b);
- b = a.clone();
- this.assertNotIdentical(a, b);
- },
-
- testFirst: function(){
- this.assertUndefined([].first());
- this.assertEqual(1, [1].first());
- this.assertEqual(1, [1,2].first());
- },
-
- testLast: function(){
- this.assertUndefined([].last());
- this.assertEqual(1, [1].last());
- this.assertEqual(2, [1,2].last());
- },
-
- testCompact: function(){
- this.assertEnumEqual([], [].compact());
- this.assertEnumEqual([1,2,3], [1,2,3].compact());
- this.assertEnumEqual([0,1,2,3], [0,null,1,2,undefined,3].compact());
- this.assertEnumEqual([1,2,3], [null,1,2,3,null].compact());
- },
-
- testFlatten: function(){
- this.assertEnumEqual([], [].flatten());
- this.assertEnumEqual([1,2,3], [1,2,3].flatten());
- this.assertEnumEqual([1,2,3], [1,[[[2,3]]]].flatten());
- this.assertEnumEqual([1,2,3], [[1],[2],[3]].flatten());
- this.assertEnumEqual([1,2,3], [[[[[[[1]]]]]],2,3].flatten());
- },
-
- testIndexOf: function(){
- this.assertEqual(-1, [].indexOf(1));
- this.assertEqual(-1, [0].indexOf(1));
- this.assertEqual(0, [1].indexOf(1));
- this.assertEqual(1, [0,1,2].indexOf(1));
- this.assertEqual(0, [1,2,1].indexOf(1));
- this.assertEqual(2, [1,2,1].indexOf(1, -1));
- this.assertEqual(1, [undefined,null].indexOf(null));
- },
-
- testLastIndexOf: function(){
- this.assertEqual(-1,[].lastIndexOf(1));
- this.assertEqual(-1, [0].lastIndexOf(1));
- this.assertEqual(0, [1].lastIndexOf(1));
- this.assertEqual(2, [0,2,4,6].lastIndexOf(4));
- this.assertEqual(3, [4,4,2,4,6].lastIndexOf(4));
- this.assertEqual(3, [0,2,4,6].lastIndexOf(6,3));
- this.assertEqual(-1, [0,2,4,6].lastIndexOf(6,2));
- this.assertEqual(0, [6,2,4,6].lastIndexOf(6,2));
-
- var fixture = [1,2,3,4,3];
- this.assertEqual(4, fixture.lastIndexOf(3));
- this.assertEnumEqual([1,2,3,4,3],fixture);
-
- //tests from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:lastIndexOf
- var array = [2, 5, 9, 2];
- this.assertEqual(3,array.lastIndexOf(2));
- this.assertEqual(-1,array.lastIndexOf(7));
- this.assertEqual(3,array.lastIndexOf(2,3));
- this.assertEqual(0,array.lastIndexOf(2,2));
- this.assertEqual(0,array.lastIndexOf(2,-2));
- this.assertEqual(3,array.lastIndexOf(2,-1));
- },
-
- testInspect: function(){
- this.assertEqual('[]',[].inspect());
- this.assertEqual('[1]',[1].inspect());
- this.assertEqual('[\'a\']',['a'].inspect());
- this.assertEqual('[\'a\', 1]',['a',1].inspect());
- },
-
- testIntersect: function(){
- this.assertEnumEqual([1,3], [1,1,3,5].intersect([1,2,3]));
- this.assertEnumEqual([1], [1,1].intersect([1,1]));
- this.assertEnumEqual([], [1,1,3,5].intersect([4]));
- this.assertEnumEqual([], [1].intersect(['1']));
-
- this.assertEnumEqual(
- ['B','C','D'],
- $R('A','Z').toArray().intersect($R('B','D').toArray())
- );
- },
-
- testToJSON: function(){
- this.assertEqual('[]', [].toJSON());
- this.assertEqual('[\"a\"]', ['a'].toJSON());
- this.assertEqual('[\"a\", 1]', ['a', 1].toJSON());
- this.assertEqual('[\"a\", {\"b\": null}]', ['a', {'b': null}].toJSON());
- },
-
- testReduce: function(){
- this.assertUndefined([].reduce());
- this.assertNull([null].reduce());
- this.assertEqual(1, [1].reduce());
- this.assertEnumEqual([1,2,3], [1,2,3].reduce());
- this.assertEnumEqual([1,null,3], [1,null,3].reduce());
- },
-
- testReverse: function(){
- this.assertEnumEqual([], [].reverse());
- this.assertEnumEqual([1], [1].reverse());
- this.assertEnumEqual([2,1], [1,2].reverse());
- this.assertEnumEqual([3,2,1], [1,2,3].reverse());
- },
-
- testSize: function(){
- this.assertEqual(4, [0, 1, 2, 3].size());
- this.assertEqual(0, [].size());
- },
-
- testUniq: function(){
- this.assertEnumEqual([1], [1, 1, 1].uniq());
- this.assertEnumEqual([1], [1].uniq());
- this.assertEnumEqual([], [].uniq());
- this.assertEnumEqual([0, 1, 2, 3], [0, 1, 2, 2, 3, 0, 2].uniq());
- this.assertEnumEqual([0, 1, 2, 3], [0, 0, 1, 1, 2, 3, 3, 3].uniq(true));
- },
-
- testWithout: function(){
- this.assertEnumEqual([], [].without(0));
- this.assertEnumEqual([], [0].without(0));
- this.assertEnumEqual([1], [0,1].without(0));
- this.assertEnumEqual([1,2], [0,1,2].without(0));
- },
-
- test$w: function(){
- this.assertEnumEqual(['a', 'b', 'c', 'd'], $w('a b c d'));
- this.assertEnumEqual([], $w(' '));
- this.assertEnumEqual([], $w(''));
- this.assertEnumEqual([], $w(null));
- this.assertEnumEqual([], $w(undefined));
- this.assertEnumEqual([], $w());
- this.assertEnumEqual([], $w(10));
- this.assertEnumEqual(['a'], $w('a'));
- this.assertEnumEqual(['a'], $w('a '));
- this.assertEnumEqual(['a'], $w(' a'));
- this.assertEnumEqual(['a', 'b', 'c', 'd'], $w(' a b\nc\t\nd\n'));
- }
-
- });
-// ]]>
-</script>
-</body>
-</html>
View
189 test/unit/array_test.js
@@ -0,0 +1,189 @@
+var globalArgsTest = 'nothing to see here';
+
+new Test.Unit.Runner({
+ test$A: function(){
+ this.assertEnumEqual([], $A({}));
+ },
+
+ testToArrayOnArguments: function(){
+ function toArrayOnArguments(){
+ globalArgsTest = $A(arguments);
+ }
+ toArrayOnArguments();
+ this.assertEnumEqual([], globalArgsTest);
+ toArrayOnArguments('foo');
+ this.assertEnumEqual(['foo'], globalArgsTest);
+ toArrayOnArguments('foo','bar');
+ this.assertEnumEqual(['foo','bar'], globalArgsTest);
+ },
+
+ testToArrayOnNodeList: function(){
+ // direct HTML
+ this.assertEqual(3, $A($('test_node').childNodes).length);
+
+ // DOM
+ var element = document.createElement('div');
+ element.appendChild(document.createTextNode('22'));
+ (2).times(function(){ element.appendChild(document.createElement('span')) });
+ this.assertEqual(3, $A(element.childNodes).length);
+
+ // HTML String
+ element = document.createElement('div');
+ $(element).update('22<span></span><span></span');
+ this.assertEqual(3, $A(element.childNodes).length);
+ },
+
+ testClear: function(){
+ this.assertEnumEqual([], [].clear());
+ this.assertEnumEqual([], [1].clear());
+ this.assertEnumEqual([], [1,2].clear());
+ },
+
+ testClone: function(){
+ this.assertEnumEqual([], [].clone());
+ this.assertEnumEqual([1], [1].clone());
+ this.assertEnumEqual([1,2], [1,2].clone());
+ this.assertEnumEqual([0,1,2], [0,1,2].clone());
+ var a = [0,1,2];
+ var b = a;
+ this.assertIdentical(a, b);
+ b = a.clone();
+ this.assertNotIdentical(a, b);
+ },
+
+ testFirst: function(){
+ this.assertUndefined([].first());
+ this.assertEqual(1, [1].first());
+ this.assertEqual(1, [1,2].first());
+ },
+
+ testLast: function(){
+ this.assertUndefined([].last());
+ this.assertEqual(1, [1].last());
+ this.assertEqual(2, [1,2].last());
+ },
+
+ testCompact: function(){
+ this.assertEnumEqual([], [].compact());
+ this.assertEnumEqual([1,2,3], [1,2,3].compact());
+ this.assertEnumEqual([0,1,2,3], [0,null,1,2,undefined,3].compact());
+ this.assertEnumEqual([1,2,3], [null,1,2,3,null].compact());
+ },
+
+ testFlatten: function(){
+ this.assertEnumEqual([], [].flatten());
+ this.assertEnumEqual([1,2,3], [1,2,3].flatten());
+ this.assertEnumEqual([1,2,3], [1,[[[2,3]]]].flatten());
+ this.assertEnumEqual([1,2,3], [[1],[2],[3]].flatten());
+ this.assertEnumEqual([1,2,3], [[[[[[[1]]]]]],2,3].flatten());
+ },
+
+ testIndexOf: function(){
+ this.assertEqual(-1, [].indexOf(1));
+ this.assertEqual(-1, [0].indexOf(1));
+ this.assertEqual(0, [1].indexOf(1));
+ this.assertEqual(1, [0,1,2].indexOf(1));
+ this.assertEqual(0, [1,2,1].indexOf(1));
+ this.assertEqual(2, [1,2,1].indexOf(1, -1));
+ this.assertEqual(1, [undefined,null].indexOf(null));
+ },
+
+ testLastIndexOf: function(){
+ this.assertEqual(-1,[].lastIndexOf(1));
+ this.assertEqual(-1, [0].lastIndexOf(1));
+ this.assertEqual(0, [1].lastIndexOf(1));
+ this.assertEqual(2, [0,2,4,6].lastIndexOf(4));
+ this.assertEqual(3, [4,4,2,4,6].lastIndexOf(4));
+ this.assertEqual(3, [0,2,4,6].lastIndexOf(6,3));
+ this.assertEqual(-1, [0,2,4,6].lastIndexOf(6,2));
+ this.assertEqual(0, [6,2,4,6].lastIndexOf(6,2));
+
+ var fixture = [1,2,3,4,3];
+ this.assertEqual(4, fixture.lastIndexOf(3));
+ this.assertEnumEqual([1,2,3,4,3],fixture);
+
+ //tests from http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:Array:lastIndexOf
+ var array = [2, 5, 9, 2];
+ this.assertEqual(3,array.lastIndexOf(2));
+ this.assertEqual(-1,array.lastIndexOf(7));
+ this.assertEqual(3,array.lastIndexOf(2,3));
+ this.assertEqual(0,array.lastIndexOf(2,2));
+ this.assertEqual(0,array.lastIndexOf(2,-2));
+ this.assertEqual(3,array.lastIndexOf(2,-1));
+ },
+
+ testInspect: function(){
+ this.assertEqual('[]',[].inspect());
+ this.assertEqual('[1]',[1].inspect());
+ this.assertEqual('[\'a\']',['a'].inspect());
+ this.assertEqual('[\'a\', 1]',['a',1].inspect());
+ },
+
+ testIntersect: function(){
+ this.assertEnumEqual([1,3], [1,1,3,5].intersect([1,2,3]));
+ this.assertEnumEqual([1], [1,1].intersect([1,1]));
+ this.assertEnumEqual([], [1,1,3,5].intersect([4]));
+ this.assertEnumEqual([], [1].intersect(['1']));
+
+ this.assertEnumEqual(
+ ['B','C','D'],
+ $R('A','Z').toArray().intersect($R('B','D').toArray())
+ );
+ },
+
+ testToJSON: function(){
+ this.assertEqual('[]', [].toJSON());
+ this.assertEqual('[\"a\"]', ['a'].toJSON());
+ this.assertEqual('[\"a\", 1]', ['a', 1].toJSON());
+ this.assertEqual('[\"a\", {\"b\": null}]', ['a', {'b': null}].toJSON());
+ },
+
+ testReduce: function(){
+ this.assertUndefined([].reduce());
+ this.assertNull([null].reduce());
+ this.assertEqual(1, [1].reduce());
+ this.assertEnumEqual([1,2,3], [1,2,3].reduce());
+ this.assertEnumEqual([1,null,3], [1,null,3].reduce());
+ },
+
+ testReverse: function(){
+ this.assertEnumEqual([], [].reverse());
+ this.assertEnumEqual([1], [1].reverse());
+ this.assertEnumEqual([2,1], [1,2].reverse());
+ this.assertEnumEqual([3,2,1], [1,2,3].reverse());
+ },
+
+ testSize: function(){
+ this.assertEqual(4, [0, 1, 2, 3].size());
+ this.assertEqual(0, [].size());
+ },
+
+ testUniq: function(){
+ this.assertEnumEqual([1], [1, 1, 1].uniq());
+ this.assertEnumEqual([1], [1].uniq());
+ this.assertEnumEqual([], [].uniq());
+ this.assertEnumEqual([0, 1, 2, 3], [0, 1, 2, 2, 3, 0, 2].uniq());
+ this.assertEnumEqual([0, 1, 2, 3], [0, 0, 1, 1, 2, 3, 3, 3].uniq(true));
+ },
+
+ testWithout: function(){
+ this.assertEnumEqual([], [].without(0));
+ this.assertEnumEqual([], [0].without(0));
+ this.assertEnumEqual([1], [0,1].without(0));
+ this.assertEnumEqual([1,2], [0,1,2].without(0));
+ },
+
+ test$w: function(){
+ this.assertEnumEqual(['a', 'b', 'c', 'd'], $w('a b c d'));
+ this.assertEnumEqual([], $w(' '));
+ this.assertEnumEqual([], $w(''));
+ this.assertEnumEqual([], $w(null));
+ this.assertEnumEqual([], $w(undefined));
+ this.assertEnumEqual([], $w());
+ this.assertEnumEqual([], $w(10));
+ this.assertEnumEqual(['a'], $w('a'));
+ this.assertEnumEqual(['a'], $w('a '));
+ this.assertEnumEqual(['a'], $w(' a'));
+ this.assertEnumEqual(['a', 'b', 'c', 'd'], $w(' a b\nc\t\nd\n'));
+ }
+});
View
36 test/unit/base.html → test/unit/base_test.js
@@ -1,31 +1,4 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <title>Prototype Unit test file</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <script src="../../dist/prototype.js" type="text/javascript"></script>
- <script src="../lib/unittest.js" type="text/javascript"></script>
- <link rel="stylesheet" href="../test.css" type="text/css" />
-</head>
-<body>
-<h1>Prototype Unit test file</h1>
-<p>
- Test of utility functions in base.js
-</p>
-
-<!-- Log output -->
-<div id="testlog"> </div>
-<div id="test"></div>
-<ul id="list">
- <li></li>
- <li></li>
- <li></li>
-</ul>
-<!-- Tests follow -->
-<script type="text/javascript" language="javascript" charset="utf-8">
-// <![CDATA[
- var Person = function(name){
+var Person = function(name){
this.name = name;
};
@@ -627,9 +600,4 @@
this.assertEqual("toString", new Foo().toString());
this.assertEqual("valueOf", new Foo().valueOf());
}
- });
-
-// ]]>
-</script>
-</body>
-</html>
+ });
View
1,769 test/unit/dom.html
@@ -1,1769 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <title>Prototype Unit test file</title>
- <meta http-equiv="content-type" content="text/html; charset=utf-8" />
- <script type="text/javascript" charset="utf-8">
- var originalElement = Element;
- </script>
- <script src="../../dist/prototype.js" type="text/javascript"></script>
- <script src="../lib/unittest.js" type="text/javascript"></script>
- <link rel="stylesheet" href="../test.css" type="text/css" />
- <style type="text/css" media="screen">
- /* <![CDATA[ */
- #style_test_1 { cursor: pointer; font-size:12px;}
- div.style-test { margin-left: 1px }
-
- #style_test_dimensions_container {
- position: absolute;
- top: 0;
- left: 500px;
- width: 20px;
- height: 30px;
- margin: 10px;
- padding: 10px;
- border: 3px solid red;
- }
-
- #not_floating_style { float: none }
- #floating_style { float: left }
- #op2 { opacity:0.5;filter:alpha(opacity=50)progid:DXImageTransform.Microsoft.Blur(strength=10);}
-
- #scroll_test_1 {
- margin: 10px;
- padding: 10px;
- position: relative;
- }
-
- #scroll_test_2 {
- position: absolute;
- left: 10px;
- top: 10px;
- }
-
- #dimensions-visible,
- #dimensions-display-none,
- #dimensions-visible-pos-rel,
- #dimensions-display-none-pos-rel,
- #dimensions-visible-pos-abs,
- #dimensions-display-none-pos-abs {
- font-size: 10px;
- height: 10em;
- width: 20em;
- }
-
- #dimensions-visible-pos-abs,
- #dimensions-display-none-pos-abs {
- position: absolute;
- top: 15px;
- left: 15px;
- }
-
- #dimensions-visible-pos-rel,
- #dimensions-display-none-pos-rel {
- position: relative;
- top: 15px;
- left: 15px;
- }
-
- #dimensions-display-none, #imensions-display-none-pos-rel, #dimensions-display-none-pos-abs {
- display: none;
- }
-
- #dimensions-table, #dimensions-tbody, #dimensions-tr, #dimensions-td {
- font-size: 10px;
- margin: 0;
- padding: 0;
- border: 0;
- border-spacing: 0;
- height: 10em;
- width: 20em;
- }
-
- #notInlineAbsoluted { position: absolute; }
-
- #elementToViewportDimensions {
- position: absolute;
- top: 0;
- left: 0;
- height: 10px;
- width: 10px;
- background: #000;
- }
-
- /* for scroll test on really big screens */
- body {
- height: 40000px;
- }
- /* ]]> */
- </style>
-</head>
-<body>
-<h1>Prototype Unit test file</h1>
-<p>
- Test of functions in dom.js
-</p>
-
-<!-- Log output -->
-<div id="scroll_test_1">
- <p id="scroll_test_2">Scroll test</p>
-</div>
-
-<div id="testlog"> </div>
-
-<div id="test-visible">visible</div>
-<div id="test-hidden" style="display:none;">hidden</div>
-<div id="test-toggle-visible">visible</div>
-<div id="test-toggle-hidden" style="display:none;">hidden</div>
-<div id="test-hide-visible">visible</div>
-<div id="test-hide-hidden" style="display:none;">hidden</div>
-<div id="test-show-visible">visible</div>
-<div id="test-show-hidden" style="display:none;">hidden</div>
-<div id="removable-container"><div id="removable"></div></div>
-
-<div>
- <table>
- <tbody id="table">
- <tr>
- <td>Data</td>
- </tr>
- <tr>
- <td id="a_cell">First Row</td>
- </tr>
- <tr id="second_row">
- <td>Second Row</td>
- </tr>
- </tbody>
- </table>
-</div>
-
-<div id="table-container-to-replace">
- <table>
- <tbody id="table-to-replace">
- <tr>
- <td>Data</td>
- </tr>
- <tr>
- <td id="a_cell-to-replace">First Row</td>
- </tr>
- <tr id="second_row-to-replace">
- <td>Second Row</td>
- </tr>
- </tbody>
- </table>
-</div>
-
-<p class="test">Test paragraph outside of container</p>
-
-<div id="container">
- <p class="test" id="intended">Test paragraph 1 inside of container</p>
- <p class="test">Test paragraph 2 inside of container</p>
- <p class="test">Test paragraph 3 inside of container</p>
- <p class="test">Test paragraph 4 inside of container</p>
-</div>
-
-<div id="testdiv">to be updated</div>
-<div id="testdiv-replace-container-1"><div id="testdiv-replace-1"></div></div>
-<div id="testdiv-replace-container-2"><div id="testdiv-replace-2"></div></div>
-<div id="testdiv-replace-container-3"><div id="testdiv-replace-3"></div></div>
-<div id="testdiv-replace-container-4"><div id="testdiv-replace-4"></div></div>
-<div id="testdiv-replace-container-5"><div id="testdiv-replace-5"></div></div>
-<div id="testdiv-replace-container-element"><div id="testdiv-replace-element"></div></div>
-<div id="testdiv-replace-container-toelement"><div id="testdiv-replace-toelement"></div></div>
-<div id="testdiv-replace-container-tohtml"><div id="testdiv-replace-tohtml"></div></div>
-<div id="testtable-replace-container"><table id="testtable-replace"></table></div>
-<table id="testrow-replace-container"><tr id="testrow-replace"></tr></table>
-<select id="testoption-replace-container"><option id="testoption-replace"></option><option>stays</option></select>
-<div id="testform-replace-container"><p>some text</p><form id="testform-replace"><input id="testinput-replace" type="text" /></form><p>some text</p></div>
-
-<div id="element_with_visible_overflow" style="overflow:visible">V</div>
-<div id="element_with_hidden_overflow" style="overflow:hidden">H</div>
-<div id="element_with_scroll_overflow" style="overflow:scroll">S</div>
-
-<div id="element_extend_test"> </div>
-
-<div id="element_reextend_test"><div id="discard_1"></div></div>
-
-<div id="test_whitespace"> <span> </span>
-
-
-<div><div></div> </div><span> </span>
-</div>
-
-
-<div id="nav_tests_isolator">
- <div id="nav_test_first_sibling"></div>
- <div></div>
- <p id="nav_test_p" class="test"></p>
- <span id="nav_test_prev_sibling"></span>
-
- <ul id="navigation_test" style="display: none">
- <!-- comment node to screw things up -->
- <li class="first"><em>A</em></li>
- <li><em class="dim">B</em></li>
- <li id="navigation_test_c">
- <em>C</em>
- <ul>
- <li><em class="dim">E</em></li>
- <li id="navigation_test_f"><em>F</em></li>
- </ul>
- </li>
- <li class="last"><em>D</em></li>
- </ul>
-
- <div id="navigation_test_next_sibling">
- <!-- -->
- </div>
-
- <p></p>
-</div>
-
-<div id="class_names">
- <p class="A"></p>
- <ul class="A B" id="class_names_ul">
- <li class="C"></li>
- <li class="A C"></li>
- <li class="1"></li>
- </ul>
- <div class="B C D"></div>
- <div id="unextended"></div>
-</div>
-
-<div id="style_test_1" style="display:none;"></div>
-<div id="style_test_2" class="style-test" style="font-size:11px;"></div>
-
-<div id="style_test_3">blah</div>
-<span id="style_test_4">blah</span>
-<span id="style_test_5">blah</span>
-
-<div id="style_test_dimensions_container">
- <div id="style_test_dimensions" style="background:#ddd;padding:1px;margin:1px;border:1px solid #00f"><div style="height:5px;background:#eee;width:5px;padding:2px;margin:2px;border:2px solid #0f0"> </div>
- </div>
-</div>
-
-<div id="test_csstext_1">test_csstext_1</div>
-<div id="test_csstext_2">test_csstext_2</div>
-<div id="test_csstext_3" style="border: 1px solid red">test_csstext_3</div>
-<div id="test_csstext_4" style="font-size: 20px">test_csstext_4</div>
-<div id="test_csstext_5">test_csstext_5</div>
-
-<div id="custom_attributes">
- <div foo="1" bar="2"></div>
- <div foo="2"></div>
-</div>
-
-<div id="cloned_element_attributes_issue" foo="original"></div>
-<a id="attributes_with_issues_1" href="test.html" accesskey="L" tabindex="50" title="a link" onclick="alert('hello world');"></a>
-<a id="attributes_with_issues_2" href="" accesskey="" tabindex="" title=""></a>
-<a id="attributes_with_issues_3"></a>
-<form id="attributes_with_issues_form" method="post" action="blah">
- <input type="checkbox" id="attributes_with_issues_checked" name="a" checked="checked"/>
- <input type="checkbox" id="attributes_with_issues_disabled" name="b" checked="checked" disabled="disabled"/>
- <input type="text" id="attributes_with_issues_readonly" name="c" readonly="readonly" value="blech"/>
- <input type="date" id="attributes_with_issues_type" value="blech" />
- <select id="attributes_with_issues_multiple" name="e" multiple="multiple">
- <option>blech</option>
- <option>blah</option>
- </select>
-</form>
-
-<!-- writeAttributes -->
-<p id="write_attribute_para"></a>
-<a id="write_attribute_link" href="test.html"></a>
-<form action="/dev/null" id="write_attribute_form" method="get" accept-charset="utf-8">
- <label id="write_attribute_label"></label>
- <input type="checkbox" name="write_attribute_checkbox" value="" id="write_attribute_checkbox">
- <input type="checkbox" checked="checked" name="write_attribute_checked_checkbox" value="" id="write_attribute_checked_checkbox">
- <input type="text" name="write_attribute_input" value="" id="write_attribute_input">
- <select id="write_attribute_select">
- <option>Cat</option>
- <option>Dog</option>
- </select>
-</form>
-
-<table id="write_attribute_table" cellpadding="6" cellspacing="4">
- <tr><td id="write_attribute_td">A</td><td>B</td></tr>
- <tr><td>C</td></tr>
- <tr><td>D</td><td>E</td><td>F</td></tr>
-</table>
-
-<div id="dom_attribute_precedence">
- <form action="blech" method="post">
- <input type="submit" id="update" />
- </form>
-</div>
-
-<div id="not_floating_none">NFN</div>
-<div id="not_floating_inline" style="float:none">NFI</div>
-<div id="not_floating_style">NFS</div>
-
-<div id="floating_inline" style="float:left">FI</div>
-<div id="floating_style">FS</div>
-<!-- Test Element opacity functions -->
-<img id="op1" alt="op2" src="fixtures/logo.gif" style="opacity:0.5;filter:alpha(opacity=50)" />
-<img id="op2" alt="op2" src="fixtures/logo.gif"/>
-<img id="op3" alt="op3" src="fixtures/logo.gif"/>
-<img id="op4-ie" alt="op3" src="fixtures/logo.gif" style="filter:alpha(opacity=30)" />
-<div id="dimensions-visible"></div>
-<div id="dimensions-display-none"></div>
-<div id="dimensions-visible-pos-rel"></div>
-<div id="dimensions-display-none-pos-rel"></div>
-<div id="dimensions-visible-pos-abs"></div>
-<div id="dimensions-display-none-pos-abs"></div>
-<table border="0" cellspacing="0" cellpadding="0" id="dimensions-table">
- <tbody id="dimensions-tbody">
- <tr id="dimensions-tr">
- <td id="dimensions-td">Data</td>
- </tr>
- </tbody>
-</table>
-
-<div id="dimensions-nester" style="width: 500px;">
- <div id="dimensions-nestee" style="display: none">This is a nested DIV. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
-</div>
-
-
-<p id="test-empty"></p>
-<p id="test-empty-but-contains-whitespace">
-
-
-</p>
-<p id="test-full">content</p>
-<div id="ancestor">
- <div id="child">
- <div id="grand-child">
- <div id="great-grand-child"></div>
- </div></div><!-- intentional formatting; don't change this line -->
- <div id="sibling"><div id="grand-sibling"></div></div>
-</div>
-<div id="not-in-the-family"></div>
-
-<div id="insertions-container"><div id="insertions-main"><p>some content.</p></div></div>
-<div id="insertions-node-container"><div id="insertions-node-main"><p>some content.</p></div></div>
-<div id="element-insertions-container"><div id="element-insertions-main"><p>some content.</p></div></div>
-<div id="element-insertions-multiple-container"><div id="element-insertions-multiple-main"><p>some content.</p></div></div>
-<table id="table_for_insertions"></table>
-<table id="table_for_row_insertions"><tr id="row_1"></tr></table>
-<form method="post" action="blah">
- <select id="select_for_update" name="select_for_update">
- <option>option 1</option>
- <option>option 2</option>
- </select>
- <select id="select_for_insert_bottom" name="select_for_insert_bottom">
- <option>option 1</option>
- <option>option 2</option>
- </select>
- <select id="select_for_insert_top" name="select_for_insert_top">
- <option>option 1</option>
- <option>option 2</option>
- </select>
-</form>
-<div id="wrap-container"><p id="wrap"></p></div>
-
-<!-- Positioning methods bench -->
-<div id="body_absolute" style="position: absolute; top: 10px; left: 10px">
- <div id="absolute_absolute" style="position: absolute; top: 10px; left:10px"> </div>
- <div id="absolute_relative" style="position: relative; top: 10px; left:10px">
- <div style="height:10px;font-size:2px">test<span id="inline">test</span></div>
- <div id="absolute_relative_undefined">XYZ</div>
- </div>
- <div id="absolute_fixed" style="position: fixed; top: 10px; left: 10px">
- <span id="absolute_fixed_absolute" style="position: absolute; top: 10px; left: 10px">foo</span>
- <span id="absolute_fixed_undefined" style="display:block">bar</span>
- </div></div>
-<div id="notInlineAbsoluted"></div>
-<div id="inlineAbsoluted" style="position: absolute"></div>
-
-<div id="unextended"></div>
-<div id="identification">
- <div id="predefined_id"></div>
- <div></div>
- <div></div>
- <div></div>
- <div id="anonymous_element_3"></div>
-</div>
-
-<div id='elementToViewportDimensions' style='display: none'></div>
-
-<!-- Tests follow -->
-<script type="text/javascript" language="javascript" charset="utf-8">
-// <![CDATA[
-
- var testVar = 'to be updated', testVar2 = '';
- var getInnerHTML = function(id) {
- return $(id).innerHTML.toString().toLowerCase().gsub(/[\r\n\t]/, '');
- };
- var createParagraph = function(text) {
- var p = document.createElement('p');
- p.appendChild(document.createTextNode(text));
- return p;
- }
- Element.addMethods({
- hashBrowns: function(element) { return 'hash browns'; }
- });
-
- Element.addMethods("LI", {
- pancakes: function(element) { return "pancakes"; }
- });
-
- Element.addMethods("DIV", {
- waffles: function(element) { return "waffles"; }
- });
-
- Element.addMethods($w("li div"), {
- orangeJuice: function(element) { return "orange juice"; }
- });
-
- // Based on properties check from http://www.quirksmode.org/viewport/compatibility.html
- var documentViewportProperties = {
- properties : [
- 'self.pageXOffset', 'self.pageYOffset',
- 'self.screenX', 'self.screenY',
- 'self.innerHeight', 'self.innerWidth',
- 'self.outerHeight', 'self.outerWidth',
- 'self.screen.height', 'self.screen.width',
- 'self.screen.availHeight', 'self.screen.availWidth',
- 'self.screen.availTop', 'self.screen.availLeft',
- 'self.screen.Top', 'self.screen.Left',
- 'self.screenTop', 'self.screenLeft',
- 'document.body.clientHeight', 'document.body.clientWidth',
- 'document.body.scrollHeight', 'document.body.scrollWidth',
- 'document.body.scrollLeft', 'document.body.scrollTop',
- 'document.body.offsetHeight', 'document.body.offsetWidth',
- 'document.body.offsetTop', 'document.body.offsetLeft'
- ].inject([], function(properties, prop) {
- if(!self.screen && prop.include('self.screen')) return;
- if (!document.body && prop.include('document.body')) return;
- properties.push(prop);
- if (prop.include('.body') && document.documentElement)
- properties.push(prop.sub('.body', '.documentElement'));
- return properties;
- }),
-
- inspect : function() {
- var props = [];
- this.properties.each(function(prop) {
- if (eval(prop)) props[prop] = eval(prop);
- }, this);
- return props;
- }
- };
-
- new Test.Unit.Runner({
-
- testDollarFunction: function() {
- this.assertUndefined($());
-
- this.assertNull(document.getElementById('noWayThisIDExists'));
- this.assertNull($('noWayThisIDExists'));
-
- this.assertIdentical(document.getElementById('testdiv'), $('testdiv'));
- this.assertEnumEqual([ $('testdiv'), $('container') ], $('testdiv', 'container'));
- this.assertEnumEqual([ $('testdiv'), undefined, $('container') ],
- $('testdiv', 'noWayThisIDExists', 'container'));
- var elt = $('testdiv');
- this.assertIdentical(elt, $(elt));
- this.assertRespondsTo('hide', elt);
- this.assertRespondsTo('childOf', elt);
- },
-
- testGetElementsByClassName: function() {
- if (document.getElementsByClassName.toString().include('[native code]')) {
- this.info("browser uses native getElementsByClassName; skipping tests");
- return;
- }
-
-
- var div = $('class_names'), list = $('class_names_ul');
-
- this.assertElementsMatch(document.getElementsByClassName('A'), 'p.A', 'ul#class_names_ul.A', 'li.A.C');
-
- if (Prototype.Browser.IE)
- this.assertUndefined(document.getElementById('unextended').show);
-
- this.assertElementsMatch(div.getElementsByClassName('B'), 'ul#class_names_ul.A.B', 'div.B.C.D');
- this.assertElementsMatch(div.getElementsByClassName('D C B'), 'div.B.C.D');
- this.assertElementsMatch(div.getElementsByClassName(' D\nC\tB '), 'div.B.C.D');
- this.assertElementsMatch(div.getElementsByClassName($w('D C B')));
- this.assertElementsMatch(list.getElementsByClassName('A'), 'li.A.C');
- this.assertElementsMatch(list.getElementsByClassName(' A '), 'li.A.C');
- this.assertElementsMatch(list.getElementsByClassName('C A'), 'li.A.C');
- this.assertElementsMatch(list.getElementsByClassName("C\nA "), 'li.A.C');
- this.assertElementsMatch(list.getElementsByClassName('B'));
- this.assertElementsMatch(list.getElementsByClassName('1'), 'li.1');
- this.assertElementsMatch(list.getElementsByClassName([1]), 'li.1');
- this.assertElementsMatch(list.getElementsByClassName(['1 junk']));
- this.assertElementsMatch(list.getElementsByClassName(''));
- this.assertElementsMatch(list.getElementsByClassName(' '));
- this.assertElementsMatch(list.getElementsByClassName(['']));
- this.assertElementsMatch(list.getElementsByClassName([' ', '']));
- this.assertElementsMatch(list.getElementsByClassName({}));
-
- // those lookups shouldn't have extended all nodes in document
- if (Prototype.Browser.IE) this.assertUndefined(document.getElementById('unextended')['show']);
- },
-
- testElementInsertWithHTML: function() {
- Element.insert('insertions-main', {before:'<p><em>before</em> text</p><p>more testing</p>'});
- this.assert(getInnerHTML('insertions-container').startsWith('<p><em>before</em> text</p><p>more testing</p>'));
- Element.insert('insertions-main', {after:'<p><em>after</em> text</p><p>more testing</p>'});
- this.assert(getInnerHTML('insertions-container').endsWith('<p><em>after</em> text</p><p>more testing</p>'));
- Element.insert('insertions-main', {top:'<p><em>top</em> text.</p><p>more testing</p>'});
- this.assert(getInnerHTML('insertions-main').startsWith('<p><em>top</em> text.</p><p>more testing</p>'));
- Element.insert('insertions-main', {bottom:'<p><em>bottom</em> text.</p><p>more testing</p>'});
- this.assert(getInnerHTML('insertions-main').endsWith('<p><em>bottom</em> text.</p><p>more testing</p>'));
- },
-
- testElementInsertWithDOMNode: function() {
- Element.insert('insertions-node-main', {before: createParagraph('node before')});
- this.assert(getInnerHTML('insertions-node-container').startsWith('<p>node before</p>'));
- Element.insert('insertions-node-main', {after: createParagraph('node after')});
- this.assert(getInnerHTML('insertions-node-container').endsWith('<p>node after</p>'));
- Element.insert('insertions-node-main', {top:createParagraph('node top')});
- this.assert(getInnerHTML('insertions-node-main').startsWith('<p>node top</p>'));
- Element.insert('insertions-node-main', {bottom:createParagraph('node bottom')});
- this.assert(getInnerHTML('insertions-node-main').endsWith('<p>node bottom</p>'));
- this.assertEqual($('insertions-node-main'), $('insertions-node-main').insert(document.createElement('p')));
- },
-
- testElementInsertWithToElementMethod: function() {
- Element.insert('insertions-node-main', {toElement: createParagraph.curry('toElement') });
- this.assert(getInnerHTML('insertions-node-main').endsWith('<p>toelement</p>'));
- Element.insert('insertions-node-main', {bottom: {toElement: createParagraph.curry('bottom toElement') }});
- this.assert(getInnerHTML('insertions-node-main').endsWith('<p>bottom toelement</p>'));
- },
-
- testElementInsertWithToHTMLMethod: function() {
- Element.insert('insertions-node-main', {toHTML: function() { return '<p>toHTML</p>'} });
- this.assert(getInnerHTML('insertions-node-main').endsWith('<p>tohtml</p>'));
- Element.insert('insertions-node-main', {bottom: {toHTML: function() { return '<p>bottom toHTML</p>'} }});
- this.assert(getInnerHTML('insertions-node-main').endsWith('<p>bottom tohtml</p>'));
- },
-
- testElementInsertWithNonString: function() {
- Element.insert('insertions-main', {bottom:3});
- this.assert(getInnerHTML('insertions-main').endsWith('3'));
- },
-
- testElementInsertInTables: function() {
- Element.insert('second_row', {after:'<tr id="third_row"><td>Third Row</td></tr>'});
- this.assert($('second_row').descendantOf('table'));
-
- $('a_cell').insert({top:'hello world'});
- this.assert($('a_cell').innerHTML.startsWith('hello world'));
- $('a_cell').insert({after:'<td>hi planet</td>'});
- this.assertEqual('hi planet', $('a_cell').next().innerHTML);
- $('table_for_insertions').insert('<tr><td>a cell!</td></tr>');
- this.assert($('table_for_insertions').innerHTML.gsub('\r\n', '').toLowerCase().include('<tr><td>a cell!</td></tr>'));
- $('row_1').insert({after:'<tr></tr><tr></tr><tr><td>last</td></tr>'});
- this.assertEqual('last', $A($('table_for_row_insertions').getElementsByTagName('tr')).last().lastChild.innerHTML);
- },
-
- testElementInsertInSelect: function() {
- var selectTop = $('select_for_insert_top'), selectBottom = $('select_for_insert_bottom');
- selectBottom.insert('<option value="33">option 33</option><option selected="selected">option 45</option>');
- this.assertEqual('option 45', selectBottom.getValue());
- selectTop.insert({top:'<option value="A">option A</option><option value="B" selected="selected">option B</option>'});
- this.assertEqual(4, selectTop.options.length);
- },
-
- testElementMethodInsert: function() {
- $('element-insertions-main').insert({before:'some text before'});
- this.assert(getInnerHTML('element-insertions-container').startsWith('some text before'));
- $('element-insertions-main').insert({after:'some text after'});
- this.assert(getInnerHTML('element-insertions-container').endsWith('some text after'));
- $('element-insertions-main').insert({top:'some text top'});
- this.assert(getInnerHTML('element-insertions-main').startsWith('some text top'));
- $('element-insertions-main').insert({bottom:'some text bottom'});
- this.assert(getInnerHTML('element-insertions-main').endsWith('some text bottom'));
-
- $('element-insertions-main').insert('some more text at the bottom');
- this.assert(getInnerHTML('element-insertions-main').endsWith('some more text at the bottom'));
-
- $('element-insertions-main').insert({TOP:'some text uppercase top'});
- this.assert(getInnerHTML('element-insertions-main').startsWith('some text uppercase top'));
-
- $('element-insertions-multiple-main').insert({
- top:'1', bottom:2, before: new Element('p').update('3'), after:'4'
- });
- this.assert(getInnerHTML('element-insertions-multiple-main').startsWith('1'));
- this.assert(getInnerHTML('element-insertions-multiple-main').endsWith('2'));
- this.assert(getInnerHTML('element-insertions-multiple-container').startsWith('<p>3</p>'));
- this.assert(getInnerHTML('element-insertions-multiple-container').endsWith('4'));
-
- $('element-insertions-main').update('test');
- $('element-insertions-main').insert(null);
- $('element-insertions-main').insert({bottom:null});
- this.assertEqual('test', getInnerHTML('element-insertions-main'));
- $('element-insertions-main').insert(1337);
- this.assertEqual('test1337', getInnerHTML('element-insertions-main'));
- },
-
- testNewElementInsert: function() {
- var container = new Element('div');
- element = new Element('div');
- container.insert(element);
-
- element.insert({ before: '<p>a paragraph</p>' });
- this.assertEqual('<p>a paragraph</p><div></div>', getInnerHTML(container));
- element.insert({ after: 'some text' });
- this.assertEqual('<p>a paragraph</p><div></div>some text', getInnerHTML(container));
-
- element.insert({ top: '<p>a paragraph</p>' });
- this.assertEqual('<p>a paragraph</p>', getInnerHTML(element));
- element.insert('some text');
- this.assertEqual('<p>a paragraph</p>some text', getInnerHTML(element));
- },
-
- testInsertionBackwardsCompatibility: function() {
- new Insertion.Before('element-insertions-main', 'some backward-compatibility testing before');
- this.assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing before'));
- new Insertion.After('element-insertions-main', 'some backward-compatibility testing after');
- this.assert(getInnerHTML('element-insertions-container').include('some backward-compatibility testing after'));
- new Insertion.Top('element-insertions-main', 'some backward-compatibility testing top');
- this.assert(getInnerHTML('element-insertions-main').startsWith('some backward-compatibility testing top'));
- new Insertion.Bottom('element-insertions-main', 'some backward-compatibility testing bottom');
- this.assert(getInnerHTML('element-insertions-main').endsWith('some backward-compatibility testing bottom'));
- },
-
- testElementWrap: function() {
- var element = $('wrap'), parent = document.createElement('div');
- element.wrap();
- this.assert(getInnerHTML('wrap-container').startsWith('<div><p'));
- element.wrap('div');
- this.assert(getInnerHTML('wrap-container').startsWith('<div><div><p'));
-
- element.wrap(parent);
- this.assert(Object.isFunction(parent.setStyle));
- this.assert(getInnerHTML('wrap-container').startsWith('<div><div><div><p'));
-
- element.wrap('div', {className: 'wrapper'});
- this.assert(element.up().hasClassName('wrapper'));
- element.wrap({className: 'other-wrapper'});
- this.assert(element.up().hasClassName('other-wrapper'));
- element.wrap(new Element('div'), {className: 'yet-other-wrapper'});
- this.assert(element.up().hasClassName('yet-other-wrapper'));
-
- var orphan = new Element('p'), div = new Element('div');
- orphan.wrap(div);
- this.assertEqual(orphan.parentNode, div);
- },
-
- testElementWrapReturnsWrapper: function() {
- var element = new Element("div");
- var wrapper = element.wrap("div");
- this.assertNotEqual(element, wrapper);
- this.assertEqual(element.up(), wrapper);
- },
-
- testElementVisible: function(){
- this.assertNotEqual('none', $('test-visible').style.display);
- this.assertEqual('none', $('test-hidden').style.display);
- },
-
- testElementToggle: function(){
- $('test-toggle-visible').toggle();
- this.assert(!$('test-toggle-visible').visible());
- $('test-toggle-visible').toggle();
- this.assert($('test-toggle-visible').visible());
- $('test-toggle-hidden').toggle();
- this.assert($('test-toggle-hidden').visible());
- $('test-toggle-hidden').toggle();
- this.assert(!$('test-toggle-hidden').visible());
- },
-
- testElementShow: function(){
- $('test-show-visible').show();
- this.assert($('test-show-visible').visible());
- $('test-show-hidden').show();
- this.assert($('test-show-hidden').visible());
- },
-
- testElementHide: function(){
- $('test-hide-visible').hide();
- this.assert(!$('test-hide-visible').visible());
- $('test-hide-hidden').hide();
- this.assert(!$('test-hide-hidden').visible());
- },
-
- testElementRemove: function(){
- $('removable').remove();
- this.assert($('removable-container').empty());
- },
-
- testElementUpdate: function() {
- $('testdiv').update('hello from div!');
- this.assertEqual('hello from div!', $('testdiv').innerHTML);
-
- Element.update('testdiv', 'another hello from div!');
- this.assertEqual('another hello from div!', $('testdiv').innerHTML);
-
- Element.update('testdiv', 123);
- this.assertEqual('123', $('testdiv').innerHTML);
-
- Element.update('testdiv');
- this.assertEqual('', $('testdiv').innerHTML);
-
- Element.update('testdiv', '&nbsp;');
- this.assert(!$('testdiv').innerHTML.empty());
- },
-
- testElementUpdateWithScript: function() {
- $('testdiv').update('hello from div!<script>\ntestVar="hello!";\n</'+'script>');
- this.assertEqual('hello from div!',$('testdiv').innerHTML);
- this.wait(100,function(){
- this.assertEqual('hello!',testVar);
-
- Element.update('testdiv','another hello from div!\n<script>testVar="another hello!"</'+'script>\nhere it goes');
-
- // note: IE normalizes whitespace (like line breaks) to single spaces, thus the match test
- this.assertMatch(/^another hello from div!\s+here it goes$/,$('testdiv').innerHTML);
- this.wait(100,function(){
- this.assertEqual('another hello!',testVar);
-
- Element.update('testdiv','a\n<script>testVar="a"\ntestVar="b"</'+'script>');
<