From 6232d13f5321b87ddf12a1aa36b4545da45f173d Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 17 Nov 2021 22:34:57 +0100 Subject: Travel3: Simple image and video display site Reads the images and videos from filesystem and builds a site in memroy. --- test/test_document.cc | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/test_document.cc (limited to 'test/test_document.cc') diff --git a/test/test_document.cc b/test/test_document.cc new file mode 100644 index 0000000..352a14c --- /dev/null +++ b/test/test_document.cc @@ -0,0 +1,71 @@ +#include "common.hh" + +#include "document.hh" +#include "hash_method.hh" +#include "mock_transport.hh" +#include "str_buffer.hh" + +#include + +TEST(document, sanity) { + auto doc = Document::create("title"); + + doc->add_style("style.css"); + doc->body()->add("body"); + + MockTransport transport; + MockResponse response; + + std::string content = "title" + "" + "body"; + + auto hash = HashMethod::sha256(); + hash->update(content.data(), content.size()); + auto tag = "\"" + hash->finish() + "\""; + + EXPECT_CALL( + transport, + create_data_proxy( + 200, + content)) + .WillOnce(testing::Return(&response)); + + EXPECT_CALL(response, add_header("Content-Type", "text/html; charset=utf-8")); + EXPECT_CALL(response, add_header("ETag", tag)); + + doc->build(&transport).release(); +} + +TEST(document, script) { + auto doc = Document::create(""); + + doc->add_script("foo.js"); + auto script = Tag::create("script"); + script->add("alert(\"\");"); + doc->add_script(std::move(script)); + + MockTransport transport; + MockResponse response; + + std::string content = "" + "<script src=\"foo.js\" type=\"text/javascript\"></script>" + "<script type=\"text/javascript\">alert(\"<foo>\");</script>" + "</head><body/></html>"; + + auto hash = HashMethod::sha256(); + hash->update(content.data(), content.size()); + auto tag = "\"" + hash->finish() + "\""; + + EXPECT_CALL( + transport, + create_data_proxy( + 200, + content)) + .WillOnce(testing::Return(&response)); + + EXPECT_CALL(response, add_header("Content-Type", "text/html; charset=utf-8")); + EXPECT_CALL(response, add_header("ETag", tag)); + + doc->build(&transport).release(); +} -- cgit v1.2.3-70-g09d2