diff --git a/mk/check.mk b/mk/check.mk index 8c348d02b32..5ee706d38db 100644 --- a/mk/check.mk +++ b/mk/check.mk @@ -20,7 +20,10 @@ $(eval $(call DEF_SUBMODULE_TEST_RULES,$(submodule)))) servo-test: $(DEPS_servo) $(CFG_RUSTC) $(RFLAGS_servo) --test -o $@ $< -reftest: src/reftest/reftest.rs servo +reftest: $(S)src/reftest/reftest.rs servo + $(CFG_RUSTC) $(RFLAGS_servo) -o $@ $< -L . + +contenttest: $(S)src/contenttest/contenttest.rs servo $(CFG_RUSTC) $(RFLAGS_servo) -o $@ $< -L . .PHONY: check $(DEPS_CHECK) @@ -31,5 +34,7 @@ check-servo: servo-test ./servo-test $(TESTNAME) check-ref: reftest - ./reftest --source-dir=$(VPATH)/src/test/ref --work-dir=src/test/ref $(TESTNAME) + ./reftest --source-dir=$(VPATH)/test/ref --work-dir=src/test/ref $(TESTNAME) +check-content: contenttest + ./contenttest --source-dir=$(VPATH)/test/content $(TESTNAME) diff --git a/src/contenttest/contenttest.rs b/src/contenttest/contenttest.rs new file mode 100644 index 00000000000..6ffc18a8a05 --- /dev/null +++ b/src/contenttest/contenttest.rs @@ -0,0 +1,73 @@ +extern mod std; + +use std::test::{TestOpts, run_tests_console, TestDesc}; +use std::getopts::{getopts, reqopt, opt_str, fail_str}; +use os::list_dir_path; + +struct Config { + source_dir: ~str, + filter: Option<~str> +} + +fn main(args: ~[~str]) { + let config = parse_config(args); + let opts = test_options(config); + let tests = find_tests(config); + run_tests_console(&opts, tests); +} + +fn parse_config(args: ~[~str]) -> Config { + let args = args.tail(); + let opts = ~[reqopt(~"source-dir")]; + let matches = match getopts(args, opts) { + Ok(m) => m, + Err(f) => fail fail_str(f) + }; + + Config { + source_dir: opt_str(matches, ~"source-dir"), + filter: if matches.free.is_empty() { + None + } else { + Some(matches.free.head()) + } + } +} + +fn test_options(config: Config) -> TestOpts { + { + filter: config.filter, + run_ignored: false, + logfile: None + } +} + +fn find_tests(config: Config) -> ~[TestDesc] { + let all_files = list_dir_path(&Path(config.source_dir)); + let html_files = all_files.filter( |file| file.to_str().ends_with(".html") ); + return html_files.map(|file| make_test(config, (*file).to_str()) ); +} + +fn make_test(config: Config, file: ~str) -> TestDesc { + { + name: file, + testfn: fn~() { run_test(config, file) }, + ignore: false, + should_fail: false + } +} + +fn run_test(config: Config, file: ~str) { + let infile = ~"file://" + os::make_absolute(&Path(file)).to_str(); + let res = run::program_output("./servo", ~[infile]); + io::print(res.out); + do str::split_char_each(res.out, '\n') |line| { + if line.contains("TEST-UNEXPECTED-FAIL") { + fail str::from_slice(line); + } + true + } +} + +fn render_servo(config: Config, file: ~str) { +} diff --git a/src/servo/content/content_task.rs b/src/servo/content/content_task.rs index 67019edc29b..d55e1f082e1 100644 --- a/src/servo/content/content_task.rs +++ b/src/servo/content/content_task.rs @@ -51,7 +51,7 @@ use ptr::null; enum ControlMsg { ParseMsg(Url), ExecuteMsg(Url), - Timer(~dom::base::TimerData), + Timer(~dom::window::TimerData), ExitMsg } diff --git a/src/servo/dom/bindings/window.rs b/src/servo/dom/bindings/window.rs index edb81aa418a..6effce5dd60 100644 --- a/src/servo/dom/bindings/window.rs +++ b/src/servo/dom/bindings/window.rs @@ -45,6 +45,12 @@ extern fn setTimeout(cx: *JSContext, argc: c_uint, vp: *jsval) -> JSBool unsafe return 1; } +extern fn close(cx: *JSContext, argc: c_uint, vp: *jsval) -> JSBool unsafe { + (*unwrap(JS_THIS_OBJECT(cx, vp))).payload.close(); + JS_SET_RVAL(cx, vp, JSVAL_NULL); + return 1; +} + unsafe fn unwrap(obj: *JSObject) -> *rust_box { let val = JS_GetReservedSlot(obj, 0); cast::reinterpret_cast(&RUST_JSVAL_TO_PRIVATE(val)) @@ -76,6 +82,11 @@ fn init(compartment: bare_compartment, win: @Window) { call: {op: setTimeout, info: null()}, nargs: 2, flags: 0, + selfHostedName: null()}, + {name: compartment.add_name(~"close"), + call: {op: close, info: null()}, + nargs: 2, + flags: 0, selfHostedName: null()}]; vec::as_imm_buf(methods, |fns, _len| { diff --git a/src/servo/dom/window.rs b/src/servo/dom/window.rs index ac37628af9b..6bc74913ad8 100644 --- a/src/servo/dom/window.rs +++ b/src/servo/dom/window.rs @@ -1,9 +1,12 @@ use comm::{Port, Chan}; -use content::content_task::{ControlMsg, Timer}; +use content::content_task::{ControlMsg, Timer, ExitMsg}; +use js::jsapi::jsval; +use dvec::DVec; enum TimerControlMsg { TimerMessage_Fire(~TimerData), - TimerMessage_Close + TimerMessage_Close, + TimerMessage_TriggerExit //XXXjdm this is just a quick hack to talk to the content task } struct Window { @@ -43,6 +46,10 @@ impl Window { io::println(#fmt("ALERT: %s", s)); } + fn close() { + self.timer_chan.send(TimerMessage_TriggerExit); + } + fn setTimeout(&self, timeout: int, argc: libc::c_uint, argv: *jsval) { let timeout = int::max(0, timeout) as uint; @@ -65,6 +72,7 @@ fn Window(content_port: Port) -> Window { TimerMessage_Fire(td) => { content_chan.send(Timer(copy td)); } + TimerMessage_TriggerExit => content_chan.send(ExitMsg) } } } diff --git a/src/test/content/harness.js b/src/test/content/harness.js new file mode 100644 index 00000000000..de2eec8bcf9 --- /dev/null +++ b/src/test/content/harness.js @@ -0,0 +1,16 @@ +function _fail(s) { + window.alert("TEST-UNEXPECTED-FAIL | " + s); +} + +function _pass(s) { + window.alert("TEST-PASS | " + s); +} + +function is(a, b) { + let f = a != b ? _fail : _pass; + f(a + " == " + b); +} + +function finish() { + window.close(); +} \ No newline at end of file diff --git a/src/test/content/test_prototypes.html b/src/test/content/test_prototypes.html new file mode 100644 index 00000000000..95d33713711 --- /dev/null +++ b/src/test/content/test_prototypes.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/test/content/test_prototypes.js b/src/test/content/test_prototypes.js new file mode 100644 index 00000000000..327843439f5 --- /dev/null +++ b/src/test/content/test_prototypes.js @@ -0,0 +1,7 @@ +is(HTMLImageElement instanceof HTMLElement, true); +is(HTMLElement instanceof Element, true); +is(Element instanceof Node, true); +is(document instanceof Document, true); +is(document.documentElement instanceof HTMLElement, true); +is(document.documentElement instanceof Element, true); +finish(); \ No newline at end of file diff --git a/src/test/test_close.html b/src/test/test_close.html new file mode 100644 index 00000000000..f4c8b185d0d --- /dev/null +++ b/src/test/test_close.html @@ -0,0 +1,3 @@ + + + diff --git a/src/test/test_close.js b/src/test/test_close.js new file mode 100644 index 00000000000..0f1640bab56 --- /dev/null +++ b/src/test/test_close.js @@ -0,0 +1 @@ +window.setTimeout(function() { window.close(); }, 3000); \ No newline at end of file