OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "chrome/renderer/greasemonkey_slave.h" | 6 #include "chrome/renderer/user_script_slave.h" |
7 #include "googleurl/src/gurl.h" | 7 #include "googleurl/src/gurl.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 TEST(GreasemonkeySlaveTest, EscapeGlob) { | 10 TEST(UserScriptSlaveTest, EscapeGlob) { |
11 EXPECT_EQ("", GreasemonkeyScript::EscapeGlob("")); | 11 EXPECT_EQ("", UserScript::EscapeGlob("")); |
12 EXPECT_EQ("*", GreasemonkeyScript::EscapeGlob("*")); | 12 EXPECT_EQ("*", UserScript::EscapeGlob("*")); |
13 EXPECT_EQ("www.google.com", GreasemonkeyScript::EscapeGlob("www.google.com")); | 13 EXPECT_EQ("www.google.com", UserScript::EscapeGlob("www.google.com")); |
14 EXPECT_EQ("*google.com*", GreasemonkeyScript::EscapeGlob("*google.com*")); | 14 EXPECT_EQ("*google.com*", UserScript::EscapeGlob("*google.com*")); |
15 EXPECT_EQ("foo\\\\bar\\?hot=dog", | 15 EXPECT_EQ("foo\\\\bar\\?hot=dog", |
16 GreasemonkeyScript::EscapeGlob("foo\\bar?hot=dog")); | 16 UserScript::EscapeGlob("foo\\bar?hot=dog")); |
17 } | 17 } |
18 | 18 |
19 TEST(GreasemonkeySlaveTest, Parse1) { | 19 TEST(UserScriptSlaveTest, Parse1) { |
20 const std::string text( | 20 const std::string text( |
21 "// This is my awesome script\n" | 21 "// This is my awesome script\n" |
22 "// It does stuff.\n" | 22 "// It does stuff.\n" |
23 "// ==UserScript== trailing garbage\n" | 23 "// ==UserScript== trailing garbage\n" |
24 "// @name foobar script\n" | 24 "// @name foobar script\n" |
25 "// @namespace http://www.google.com/\n" | 25 "// @namespace http://www.google.com/\n" |
26 "// @include *mail.google.com*\n" | 26 "// @include *mail.google.com*\n" |
27 "// \n" | 27 "// \n" |
28 "// @othergarbage\n" | 28 "// @othergarbage\n" |
29 "// @include *mail.yahoo.com*\r\n" | 29 "// @include *mail.yahoo.com*\r\n" |
30 "// @include \t *mail.msn.com*\n" // extra spaces after "@include" OK | 30 "// @include \t *mail.msn.com*\n" // extra spaces after "@include" OK |
31 "//@include not-recognized\n" // must have one space after "//" | 31 "//@include not-recognized\n" // must have one space after "//" |
32 "// ==/UserScript== trailing garbage\n" | 32 "// ==/UserScript== trailing garbage\n" |
33 "\n" | 33 "\n" |
34 "\n" | 34 "\n" |
35 "alert('hoo!');\n"); | 35 "alert('hoo!');\n"); |
36 | 36 |
37 GreasemonkeyScript script("foo"); | 37 UserScript script("foo"); |
38 script.Parse(text); | 38 script.Parse(text); |
39 EXPECT_EQ(3U, script.include_patterns_.size()); | 39 EXPECT_EQ(3U, script.include_patterns_.size()); |
40 EXPECT_EQ(text, script.GetBody()); | 40 EXPECT_EQ(text, script.GetBody()); |
41 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); | 41 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); |
42 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); | 42 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); |
43 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar"))); | 43 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar"))); |
44 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz"))); | 44 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz"))); |
45 EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com"))); | 45 EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com"))); |
46 } | 46 } |
47 | 47 |
48 TEST(GreasemonkeySlaveTest, Parse2) { | 48 TEST(UserScriptSlaveTest, Parse2) { |
49 const std::string text("default to @include *"); | 49 const std::string text("default to @include *"); |
50 | 50 |
51 GreasemonkeyScript script("foo"); | 51 UserScript script("foo"); |
52 script.Parse(text); | 52 script.Parse(text); |
53 EXPECT_EQ(1U, script.include_patterns_.size()); | 53 EXPECT_EQ(1U, script.include_patterns_.size()); |
54 EXPECT_EQ(text, script.GetBody()); | 54 EXPECT_EQ(text, script.GetBody()); |
55 EXPECT_TRUE(script.MatchesUrl(GURL("foo"))); | 55 EXPECT_TRUE(script.MatchesUrl(GURL("foo"))); |
56 EXPECT_TRUE(script.MatchesUrl(GURL("bar"))); | 56 EXPECT_TRUE(script.MatchesUrl(GURL("bar"))); |
57 } | 57 } |
58 | 58 |
59 TEST(GreasemonkeySlaveTest, Parse3) { | 59 TEST(UserScriptSlaveTest, Parse3) { |
60 const std::string text( | 60 const std::string text( |
61 "// ==UserScript==\n" | 61 "// ==UserScript==\n" |
62 "// @include *foo*\n" | 62 "// @include *foo*\n" |
63 "// ==/UserScript=="); // no trailing newline | 63 "// ==/UserScript=="); // no trailing newline |
64 | 64 |
65 GreasemonkeyScript script("foo"); | 65 UserScript script("foo"); |
66 script.Parse(text); | 66 script.Parse(text); |
67 EXPECT_EQ(1U, script.include_patterns_.size()); | 67 EXPECT_EQ(1U, script.include_patterns_.size()); |
68 EXPECT_EQ(text, script.GetBody()); | 68 EXPECT_EQ(text, script.GetBody()); |
69 EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar"))); | 69 EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar"))); |
70 EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org"))); | 70 EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org"))); |
71 } | 71 } |
OLD | NEW |