diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-10 22:44:21 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-10 22:44:21 +0000 |
commit | a72f5f32c228dd262f7c57546b4cc39c95860c03 (patch) | |
tree | 1741a93170a48fcda4a252eb377a20b48f960f2f /chrome/browser/extensions/user_script_master_unittest.cc | |
parent | 6ebdd17b6b90b0bba9363098987712d7770e89ef (diff) | |
download | chromium_src-a72f5f32c228dd262f7c57546b4cc39c95860c03.zip chromium_src-a72f5f32c228dd262f7c57546b4cc39c95860c03.tar.gz chromium_src-a72f5f32c228dd262f7c57546b4cc39c95860c03.tar.bz2 |
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
Diffstat (limited to 'chrome/browser/extensions/user_script_master_unittest.cc')
-rw-r--r-- | chrome/browser/extensions/user_script_master_unittest.cc | 49 |
1 files changed, 47 insertions, 2 deletions
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)); +} |