#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(); }