From 99f74b526a492b8183d17b7ac29d78f4a6a491b7 Mon Sep 17 00:00:00 2001
From: Tobie Langel <tobie.langel@gmail.com>
Date: Fri, 12 Dec 2008 13:55:28 +0100
Subject: [PATCH] Add caja_builder for optional cajoled tests.

---
 .gitmodules                                |  3 ++
 Rakefile                                   | 30 ++++++++++++
 test/unit/caja_whitelists/html_attrib.json | 53 ++++++++++++++++++++++
 vendor/caja_builder                        |  1 +
 4 files changed, 87 insertions(+)
 create mode 100644 test/unit/caja_whitelists/html_attrib.json
 create mode 160000 vendor/caja_builder

diff --git a/.gitmodules b/.gitmodules
index c3a50f6..e013bb3 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,6 @@
 [submodule "vendor/unittest_js"]
 	path = vendor/unittest_js
 	url = git://github.com/tobie/unittest_js.git
+[submodule "vendor/caja_builder"]
+	path = vendor/caja_builder
+	url = git://github.com/tobie/unittest_js_caja_builder.git
diff --git a/Rakefile b/Rakefile
index 29d1a15..19b08d8 100755
--- a/Rakefile
+++ b/Rakefile
@@ -116,3 +116,33 @@ end
 task :clean_tmp do
   puts '"rake clean_tmp" is deprecated. Please use "rake test:clean" instead.'
 end
+
+namespace :caja do
+  task :test => ['test:build', 'test:run']
+  
+  namespace :test do
+    task :run => ['rake:test:run']
+
+    task :build => [:require, 'rake:test:clean', :dist] do 
+      builder = UnittestJS::CajaBuilder::SuiteBuilder.new({
+        :input_dir          => PROTOTYPE_TEST_UNIT_DIR,
+        :assets_dir         => PROTOTYPE_DIST_DIR,
+        :whitelist_dir      => File.join(PROTOTYPE_TEST_DIR, 'unit', 'caja_whitelists'),
+        :html_attrib_schema => 'html_attrib.json'
+      })
+      selected_tests = (ENV['TESTS'] || '').split(',')
+      builder.collect(*selected_tests)
+      builder.render
+    end
+  end
+  task :require => ['rake:test:require'] do
+    lib = 'vendor/caja_builder/lib/caja_builder'
+    unless File.exists?(lib)
+      puts "\nYou'll need UnittestJS to run the tests. Just run:\n\n"
+      puts "  $ git submodule init"
+      puts "  $ git submodule update"
+      puts "\nand you should be all set.\n\n"
+    end
+    require lib
+  end
+end
\ No newline at end of file
diff --git a/test/unit/caja_whitelists/html_attrib.json b/test/unit/caja_whitelists/html_attrib.json
new file mode 100644
index 0000000..3b025ed
--- /dev/null
+++ b/test/unit/caja_whitelists/html_attrib.json
@@ -0,0 +1,53 @@
+{
+  "description": "Extends the default HTML attribute whiteList for Prototype testing purposes.",
+ 
+  "inherits": [
+    {
+      "src": "resource:///html4-attributes.json"
+    }
+  ],
+ 
+  "allowed": [
+    "FORM:ACCEPT-CHARSET",
+    "DIV:FOO",
+    "DIV:BAR",
+    "A:ACCESSKEY"
+  ],
+ 
+  "types": [
+    {
+      "key": "A:ACCESSKEY",
+      "description": "Allow the A:ACCESSKEY accessibility key character",
+      "pattern": ".?",
+      "optional": true
+    },
+    
+    {
+      "key": "INPUT:TYPE",
+      "description": "Overwrite INPUT:TYPE rule to allow for DATE value.",
+      "pattern": "TEXT|PASSWORD|CHECKBOX|RADIO|SUBMIT|RESET|FILE|HIDDEN|IMAGE|BUTTON|DATE",
+      "optional": true
+    },
+    
+    {
+      "key": "A:TABINDEX",
+      "description": "Overwrite A:TABINDEX to allow for an empty value",
+      "pattern": ".*",
+      "optional": true
+    },
+    
+    {
+      "key": "DIV:FOO",
+      "description": "Custom BAR attribute.",
+      "pattern": ".*",
+      "optional": true
+    },
+    
+    {
+      "key": "DIV:BAR",
+      "description": "Custom FOO attribute",
+      "pattern": ".*",
+      "optional": true
+    }
+  ]
+}
diff --git a/vendor/caja_builder b/vendor/caja_builder
new file mode 160000
index 0000000..aeda517
--- /dev/null
+++ b/vendor/caja_builder
@@ -0,0 +1 @@
+Subproject commit aeda517c2e82db92bc88d56ed68fa4ce05f487a9