summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/user_script_slave_unittest.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-09 20:37:35 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-09 20:37:35 +0000
commit0938d3cb82dfd2424117f73573e757424ebede00 (patch)
treef1d0503af86c6c8bf6be409c1744437384d7cb86 /chrome/renderer/user_script_slave_unittest.cc
parent4f2321dbb2e034601fed172d222a90009e4674a0 (diff)
downloadchromium_src-0938d3cb82dfd2424117f73573e757424ebede00.zip
chromium_src-0938d3cb82dfd2424117f73573e757424ebede00.tar.gz
chromium_src-0938d3cb82dfd2424117f73573e757424ebede00.tar.bz2
This is a rename of the term 'Greasemonkey' to 'user script' in Chromium.
I'm doing this to avoid confusion with the Firefox version of Greasemonkey and also because 'user script' is really the correct generic term. At the same time, I also moved user_script_master* into extensions/ because I want these two pieces to get closer and closer such that standalone user scripts are just a very small extension. Also extensions will be relying on most of the user script code. Review URL: http://codereview.chromium.org/17281 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7827 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/user_script_slave_unittest.cc')
-rw-r--r--chrome/renderer/user_script_slave_unittest.cc71
1 files changed, 71 insertions, 0 deletions
diff --git a/chrome/renderer/user_script_slave_unittest.cc b/chrome/renderer/user_script_slave_unittest.cc
new file mode 100644
index 0000000..57d34a9
--- /dev/null
+++ b/chrome/renderer/user_script_slave_unittest.cc
@@ -0,0 +1,71 @@
+// Copyright (c) 2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/logging.h"
+#include "chrome/renderer/user_script_slave.h"
+#include "googleurl/src/gurl.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+TEST(UserScriptSlaveTest, EscapeGlob) {
+ EXPECT_EQ("", UserScript::EscapeGlob(""));
+ EXPECT_EQ("*", UserScript::EscapeGlob("*"));
+ EXPECT_EQ("www.google.com", UserScript::EscapeGlob("www.google.com"));
+ EXPECT_EQ("*google.com*", UserScript::EscapeGlob("*google.com*"));
+ EXPECT_EQ("foo\\\\bar\\?hot=dog",
+ UserScript::EscapeGlob("foo\\bar?hot=dog"));
+}
+
+TEST(UserScriptSlaveTest, Parse1) {
+ const std::string text(
+ "// This is my awesome script\n"
+ "// It does stuff.\n"
+ "// ==UserScript== trailing garbage\n"
+ "// @name foobar script\n"
+ "// @namespace http://www.google.com/\n"
+ "// @include *mail.google.com*\n"
+ "// \n"
+ "// @othergarbage\n"
+ "// @include *mail.yahoo.com*\r\n"
+ "// @include \t *mail.msn.com*\n" // extra spaces after "@include" OK
+ "//@include not-recognized\n" // must have one space after "//"
+ "// ==/UserScript== trailing garbage\n"
+ "\n"
+ "\n"
+ "alert('hoo!');\n");
+
+ UserScript script("foo");
+ script.Parse(text);
+ EXPECT_EQ(3U, script.include_patterns_.size());
+ EXPECT_EQ(text, script.GetBody());
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz")));
+ EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com")));
+}
+
+TEST(UserScriptSlaveTest, Parse2) {
+ const std::string text("default to @include *");
+
+ UserScript script("foo");
+ script.Parse(text);
+ EXPECT_EQ(1U, script.include_patterns_.size());
+ EXPECT_EQ(text, script.GetBody());
+ EXPECT_TRUE(script.MatchesUrl(GURL("foo")));
+ EXPECT_TRUE(script.MatchesUrl(GURL("bar")));
+}
+
+TEST(UserScriptSlaveTest, Parse3) {
+ const std::string text(
+ "// ==UserScript==\n"
+ "// @include *foo*\n"
+ "// ==/UserScript=="); // no trailing newline
+
+ UserScript script("foo");
+ script.Parse(text);
+ EXPECT_EQ(1U, script.include_patterns_.size());
+ EXPECT_EQ(text, script.GetBody());
+ EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar")));
+ EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org")));
+}