From a72f5f32c228dd262f7c57546b4cc39c95860c03 Mon Sep 17 00:00:00 2001 From: "aa@chromium.org" Date: Tue, 10 Feb 2009 22:44:21 +0000 Subject: Optionally support URLPatterns in standalone user scripts via the @match declaration. In the future, maybe @include will be deprecated and result in a warning. Review URL: http://codereview.chromium.org/20127 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9526 0039d316-1c4b-4281-b951-d872f2087c98 --- .../extensions/user_script_master_unittest.cc | 49 +++++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'chrome/browser/extensions/user_script_master_unittest.cc') diff --git a/chrome/browser/extensions/user_script_master_unittest.cc b/chrome/browser/extensions/user_script_master_unittest.cc index 8ce2391..155fe47 100644 --- a/chrome/browser/extensions/user_script_master_unittest.cc +++ b/chrome/browser/extensions/user_script_master_unittest.cc @@ -140,7 +140,8 @@ TEST_F(UserScriptMasterTest, Parse1) { "alert('hoo!');\n"); UserScript script; - UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &script); + EXPECT_TRUE(UserScriptMaster::ScriptReloader::ParseMetadataHeader( + text, &script)); EXPECT_EQ(3U, script.globs().size()); EXPECT_EQ("*mail.google.com*", script.globs()[0]); EXPECT_EQ("*mail.yahoo.com*", script.globs()[1]); @@ -151,7 +152,8 @@ TEST_F(UserScriptMasterTest, Parse2) { const std::string text("default to @include *"); UserScript script; - UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &script); + EXPECT_TRUE(UserScriptMaster::ScriptReloader::ParseMetadataHeader( + text, &script)); EXPECT_EQ(1U, script.globs().size()); EXPECT_EQ("*", script.globs()[0]); } @@ -167,3 +169,46 @@ TEST_F(UserScriptMasterTest, Parse3) { EXPECT_EQ(1U, script.globs().size()); EXPECT_EQ("*foo*", script.globs()[0]); } + +TEST_F(UserScriptMasterTest, Parse4) { + const std::string text( + "// ==UserScript==\n" + "// @match http://*.mail.google.com/*\n" + "// @match \t http://mail.yahoo.com/*\n" + "// ==/UserScript==\n"); + + UserScript script; + EXPECT_TRUE(UserScriptMaster::ScriptReloader::ParseMetadataHeader( + text, &script)); + EXPECT_EQ(0U, script.globs().size()); + EXPECT_EQ(2U, script.url_patterns().size()); + EXPECT_EQ("http://*.mail.google.com/*", + script.url_patterns()[0].GetAsString()); + EXPECT_EQ("http://mail.yahoo.com/*", + script.url_patterns()[1].GetAsString()); +} + +TEST_F(UserScriptMasterTest, Parse5) { + const std::string text( + "// ==UserScript==\n" + "// @match http://*mail.google.com/*\n" + "// ==/UserScript==\n"); + + // Invalid @match value. + UserScript script; + EXPECT_FALSE(UserScriptMaster::ScriptReloader::ParseMetadataHeader( + text, &script)); +} + +TEST_F(UserScriptMasterTest, Parse6) { + const std::string text( + "// ==UserScript==\n" + "// @include http://*.mail.google.com/*\n" + "// @match \t http://mail.yahoo.com/*\n" + "// ==/UserScript==\n"); + + // Not allowed to mix @include and @value. + UserScript script; + EXPECT_FALSE(UserScriptMaster::ScriptReloader::ParseMetadataHeader( + text, &script)); +} -- cgit v1.1