TEST_F(PageSerializerTest, Font)
{
    setBaseFolder("pageserializer/font/");

    registerURL("font.html", "text/html");
    registerURL("font.ttf", "application/octet-stream");

    serialize("font.html");

    EXPECT_TRUE(isSerialized("font.ttf", "application/octet-stream"));
}
TEST_F(PageSerializerTest, DontIncludeErrorImage)
{
    setBaseFolder("pageserializer/image/");

    registerURL("page_with_img_error.html", "text/html");
    registerURL("error_image.png", "image/png");

    serialize("page_with_img_error.html");

    EXPECT_EQ(1U, getResources().size());
    EXPECT_TRUE(isSerialized("page_with_img_error.html", "text/html"));
    EXPECT_FALSE(isSerialized("error_image.png", "image/png"));
}
// Test that we don't regress https://bugs.webkit.org/show_bug.cgi?id=99105
TEST_F(PageSerializerTest, SVGImageDontCrash)
{
    setBaseFolder("pageserializer/svg/");

    registerURL("page_with_svg_image.html", "text/html");
    registerURL("green_rectangle.svg", "image/svg+xml");

    serialize("page_with_svg_image.html");

    EXPECT_EQ(2U, getResources().size());

    EXPECT_TRUE(isSerialized("green_rectangle.svg", "image/svg+xml"));
    EXPECT_GT(getSerializedData("green_rectangle.svg", "image/svg+xml").length(), 250U);
}
TEST_F(PageSerializerTest, Frames)
{
    setBaseFolder("pageserializer/frames/");

    registerURL("simple_frames.html", "text/html");
    registerURL("simple_frames_top.html", "text/html");
    registerURL("simple_frames_1.html", "text/html");
    registerURL("simple_frames_3.html", "text/html");

    registerURL("frame_1.png", "image.png", "image/png");
    registerURL("frame_2.png", "image.png", "image/png");
    registerURL("frame_3.png", "image.png", "image/png");
    registerURL("frame_4.png", "image.png", "image/png");

    serialize("simple_frames.html");

    EXPECT_EQ(8U, getResources().size());

    EXPECT_TRUE(isSerialized("simple_frames.html", "text/html"));
    EXPECT_TRUE(isSerialized("simple_frames_top.html", "text/html"));
    EXPECT_TRUE(isSerialized("simple_frames_1.html", "text/html"));
    EXPECT_TRUE(isSerialized("simple_frames_3.html", "text/html"));

    EXPECT_TRUE(isSerialized("frame_1.png", "image/png"));
    EXPECT_TRUE(isSerialized("frame_2.png", "image/png"));
    EXPECT_TRUE(isSerialized("frame_3.png", "image/png"));
    EXPECT_TRUE(isSerialized("frame_4.png", "image/png"));
}
TEST_F(PageSerializerTest, CSSImport)
{
    setBaseFolder("pageserializer/css/");

    registerURL("import.html", "text/html");
    registerURL("import/base.css", "text/css");
    registerURL("import/relative/red-background.css", "text/css");
    registerURL("import/absolute/green-header.css", "text/css");

    serialize("import.html");

    EXPECT_TRUE(isSerialized("import.html", "text/html"));
    EXPECT_TRUE(isSerialized("import/base.css", "text/css"));
    EXPECT_TRUE(isSerialized("import/relative/red-background.css", "text/css"));
    EXPECT_TRUE(isSerialized("import/absolute/green-header.css", "text/css"));
}
TEST_F(PageSerializerTest, RewriteLinksSimple)
{
    setBaseFolder("pageserializer/rewritelinks/");
    setRewriteURLFolder("folder");

    registerURL("rewritelinks_simple.html", "text/html");
    registerURL("absolute.png", "image.png", "image/png");
    registerURL("relative.png", "image.png", "image/png");
    registerRewriteURL("http://www.test.com/absolute.png", "a.png");
    registerRewriteURL("http://www.test.com/relative.png", "b.png");

    serialize("rewritelinks_simple.html");

    EXPECT_EQ(3U, getResources().size());
    EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find("\"folder/a.png\""), kNotFound);
    EXPECT_NE(getSerializedData("rewritelinks_simple.html", "text/html").find("\"folder/b.png\""), kNotFound);
}
TEST_F(PageSerializerTest, DTD)
{
    setBaseFolder("pageserializer/dtd/");

    registerURL("html5.html", "text/html");
    serialize("html5.html");

    String expectedStart("<!DOCTYPE html>");
    EXPECT_TRUE(getSerializedData("html5.html").startsWith(expectedStart));
}
TEST_F(PageSerializerTest, DataURIMorphing)
{
    setBaseFolder("pageserializer/datauri/");

    registerURL("page_with_morphing_data.html", "text/html");

    serialize("page_with_morphing_data.html");

    EXPECT_EQ(2U, getResources().size());
    EXPECT_TRUE(isSerialized("page_with_morphing_data.html", "text/html"));
}
TEST_F(PageSerializerTest, RewriteLinksBase)
{
    setBaseFolder("pageserializer/rewritelinks/");
    setRewriteURLFolder("folder");

    registerURL("rewritelinks_base.html", "text/html");
    registerURL("images/here/image.png", "image.png", "image/png");
    registerURL("images/here/or/in/here/image.png", "image.png", "image/png");
    registerURL("or/absolute.png", "image.png", "image/png");
    registerRewriteURL("http://www.test.com/images/here/image.png", "a.png");
    registerRewriteURL("http://www.test.com/images/here/or/in/here/image.png", "b.png");
    registerRewriteURL("http://www.test.com/or/absolute.png", "c.png");

    serialize("rewritelinks_base.html");

    EXPECT_EQ(4U, getResources().size());
    EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("\"folder/a.png\""), kNotFound);
    EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("\"folder/b.png\""), kNotFound);
    EXPECT_NE(getSerializedData("rewritelinks_base.html", "text/html").find("\"folder/c.png\""), kNotFound);
}
TEST_F(PageSerializerTest, XMLDeclaration)
{
    V8TestingScope scope(v8::Isolate::GetCurrent());
    setBaseFolder("pageserializer/xml/");

    registerURL("xmldecl.xml", "text/xml");
    serialize("xmldecl.xml");

    String expectedStart("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    EXPECT_TRUE(getSerializedData("xmldecl.xml").startsWith(expectedStart));
}
// Tests that when serializing a page with blank frames these are reported with their resources.
TEST_F(PageSerializerTest, BlankFrames)
{
    setBaseFolder("pageserializer/frames/");

    registerURL("blank_frames.html", "text/html");
    registerURL("red_background.png", "image.png", "image/png");
    registerURL("orange_background.png", "image.png", "image/png");
    registerURL("blue_background.png", "image.png", "image/png");

    serialize("blank_frames.html");

    EXPECT_EQ(7U, getResources().size());

    EXPECT_TRUE(isSerialized("http://www.test.com/red_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("http://www.test.com/orange_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("http://www.test.com/blue_background.png", "image/png"));
    // The blank frames should have got a magic URL.
    EXPECT_TRUE(isSerialized("wyciwyg://frame/0", "text/html"));
    EXPECT_TRUE(isSerialized("wyciwyg://frame/1", "text/html"));
    EXPECT_TRUE(isSerialized("wyciwyg://frame/2", "text/html"));
}
Esempio n. 12
0
FileSystem::FileSystem () :
		_homeDir(System.getHomeDirectory()), _dataDir("base/" + Singleton<Application>::getInstance().getName() + "/"), _mapsDir("maps/"), _campaignsDir("campaigns/"), _texturesDir(
				"textures/"), _picsDir("pics/"), _soundsDir("sounds/"), _musicDir("music/"), _shaderDir("shaders/"), _languageDir("lang/"), _gesturesDir("gestures/")
{
#ifdef PKGDATADIR
	_dataDir = PKGDATADIR;
	if (!string::endsWith(_dataDir, "/")) {
		_dataDir += "/";
	}
#endif
	registerURL("maps", getMapsDir());
	registerURL("textures", getTexturesDir());
	registerURL("pics", getPicsDir());
	registerURL("music", getMusicDir());
	registerURL("shaders", getShaderDir());
	registerURL("languages", getLanguageDir());
	registerURL("sounds", getSoundsDir());
	registerURL("campaigns", getCampaignsDir());
	registerURL("gestures", getGesturesDir());
	registerURL("home", _homeDir);
}
TEST_F(PageSerializerTest, NamespaceElementsDontCrash)
{
    setBaseFolder("pageserializer/namespace/");

    registerURL("namespace_element.html", "text/html");

    serialize("namespace_element.html");

    EXPECT_EQ(1U, getResources().size());
    EXPECT_TRUE(isSerialized("namespace_element.html", "text/html"));
    EXPECT_GT(getSerializedData("namespace_element.html", "text/html").length(), 0U);
}
TEST_F(PageSerializerTest, IFrames)
{
    setBaseFolder("pageserializer/frames/");

    registerURL("top_frame.html", "text/html");
    registerURL("simple_iframe.html", "text/html");
    registerURL("object_iframe.html", "text/html");
    registerURL("embed_iframe.html", "text/html");
    registerURL("encoded_iframe.html", "text/html");

    registerURL("top.png", "image.png", "image/png");
    registerURL("simple.png", "image.png", "image/png");
    registerURL("object.png", "image.png", "image/png");
    registerURL("embed.png", "image.png", "image/png");

    serialize("top_frame.html");

    EXPECT_EQ(9U, getResources().size());

    EXPECT_TRUE(isSerialized("top_frame.html", "text/html"));
    EXPECT_TRUE(isSerialized("simple_iframe.html", "text/html"));
    EXPECT_TRUE(isSerialized("object_iframe.html", "text/html"));
    EXPECT_TRUE(isSerialized("embed_iframe.html", "text/html"));
    EXPECT_TRUE(isSerialized("encoded_iframe.html", "text/html"));

    EXPECT_TRUE(isSerialized("top.png", "image/png"));
    EXPECT_TRUE(isSerialized("simple.png", "image/png"));
    EXPECT_TRUE(isSerialized("object.png", "image/png"));
    EXPECT_TRUE(isSerialized("embed.png", "image/png"));

    // Ensure that page contents are not NFC-normalized before encoding.
    String expectedMetaCharset = "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=EUC-KR\">";
    EXPECT_TRUE(getSerializedData("encoded_iframe.html", "text/html").contains(expectedMetaCharset));
    EXPECT_TRUE(getSerializedData("encoded_iframe.html", "text/html").contains("\xE4\xC5\xD1\xE2"));
    EXPECT_FALSE(getSerializedData("encoded_iframe.html", "text/html").contains("\xE4\xC5\xE4\xC5"));
}
 void registerURL(const char* file, const char* mimeType)
 {
     registerURL(file, file, mimeType);
 }
TEST_F(PageSerializerTest, CSS)
{
    setBaseFolder("pageserializer/css/");

    registerURL("css_test_page.html", "text/html");
    registerURL("link_styles.css", "text/css");
    registerURL("encoding.css", "text/css");
    registerURL("import_style_from_link.css", "text/css");
    registerURL("import_styles.css", "text/css");
    registerURL("do_not_serialize.png", "image.png", "image/png");
    registerURL("red_background.png", "image.png", "image/png");
    registerURL("orange_background.png", "image.png", "image/png");
    registerURL("yellow_background.png", "image.png", "image/png");
    registerURL("green_background.png", "image.png", "image/png");
    registerURL("blue_background.png", "image.png", "image/png");
    registerURL("purple_background.png", "image.png", "image/png");
    registerURL("pink_background.png", "image.png", "image/png");
    registerURL("brown_background.png", "image.png", "image/png");
    registerURL("ul-dot.png", "image.png", "image/png");
    registerURL("ol-dot.png", "image.png", "image/png");

    serialize("css_test_page.html");

    EXPECT_EQ(15U, getResources().size());

    EXPECT_FALSE(isSerialized("do_not_serialize.png", "image/png"));

    EXPECT_TRUE(isSerialized("css_test_page.html", "text/html"));
    EXPECT_TRUE(isSerialized("link_styles.css", "text/css"));
    EXPECT_TRUE(isSerialized("encoding.css", "text/css"));
    EXPECT_TRUE(isSerialized("import_styles.css", "text/css"));
    EXPECT_TRUE(isSerialized("import_style_from_link.css", "text/css"));
    EXPECT_TRUE(isSerialized("red_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("orange_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("yellow_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("green_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("blue_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("purple_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("pink_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("brown_background.png", "image/png"));
    EXPECT_TRUE(isSerialized("ul-dot.png", "image/png"));
    EXPECT_TRUE(isSerialized("ol-dot.png", "image/png"));

    // Ensure encodings are specified.
    EXPECT_TRUE(getSerializedData("link_styles.css", "text/css").startsWith("@charset"));
    EXPECT_TRUE(getSerializedData("import_styles.css", "text/css").startsWith("@charset"));
    EXPECT_TRUE(getSerializedData("import_style_from_link.css", "text/css").startsWith("@charset"));
    EXPECT_TRUE(getSerializedData("encoding.css", "text/css").startsWith("@charset \"euc-kr\";"));

    // Ensure that stylesheet contents are not NFC-normalized before encoding.
    EXPECT_TRUE(getSerializedData("encoding.css", "text/css").contains("\xE4\xC5\xD1\xE2"));
    EXPECT_FALSE(getSerializedData("encoding.css", "text/css").contains("\xE4\xC5\xE4\xC5"));
}
TEST_F(PageSerializerTest, HTMLElements)
{
    setBaseFolder("pageserializer/elements/");

    registerURL("elements.html", "text/html");
    registerURL("style.css", "style.css", "text/css");
    registerURL("copyright.html", "empty.txt", "text/html");
    registerURL("script.js", "empty.txt", "text/javascript");

    registerURL("bodyBackground.png", "image.png", "image/png");

    registerURL("imageSrc.png", "image.png", "image/png");

    registerURL("inputImage.png", "image.png", "image/png");

    registerURL("tableBackground.png", "image.png", "image/png");
    registerURL("trBackground.png", "image.png", "image/png");
    registerURL("tdBackground.png", "image.png", "image/png");

    registerURL("blockquoteCite.html", "empty.txt", "text/html");
    registerURL("qCite.html", "empty.txt", "text/html");
    registerURL("delCite.html", "empty.txt", "text/html");
    registerURL("insCite.html", "empty.txt", "text/html");

    registerErrorURL("nonExisting.png", 404);

    serialize("elements.html");

    EXPECT_EQ(8U, getResources().size());

    EXPECT_TRUE(isSerialized("elements.html", "text/html"));
    EXPECT_TRUE(isSerialized("style.css", "text/css"));
    EXPECT_TRUE(isSerialized("bodyBackground.png", "image/png"));
    EXPECT_TRUE(isSerialized("imageSrc.png", "image/png"));
    EXPECT_TRUE(isSerialized("inputImage.png", "image/png"));
    EXPECT_TRUE(isSerialized("tableBackground.png", "image/png"));
    EXPECT_TRUE(isSerialized("trBackground.png", "image/png"));
    EXPECT_TRUE(isSerialized("tdBackground.png", "image/png"));
    EXPECT_FALSE(isSerialized("nonExisting.png", "image/png"));
}