OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/file_path.h" | 5 #include "base/file_path.h" |
6 #include "base/pickle.h" | 6 #include "base/pickle.h" |
7 #include "chrome/common/extensions/user_script.h" | 7 #include "chrome/common/extensions/user_script.h" |
8 #include "googleurl/src/gurl.h" | 8 #include "googleurl/src/gurl.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 static const int kAllSchemes = | 11 static const int kAllSchemes = |
12 URLPattern::SCHEME_HTTP | | 12 URLPattern::SCHEME_HTTP | |
13 URLPattern::SCHEME_HTTPS | | 13 URLPattern::SCHEME_HTTPS | |
14 URLPattern::SCHEME_FILE | | 14 URLPattern::SCHEME_FILE | |
15 URLPattern::SCHEME_FTP | | 15 URLPattern::SCHEME_FTP | |
16 URLPattern::SCHEME_CHROMEUI; | 16 URLPattern::SCHEME_CHROMEUI; |
17 | 17 |
18 TEST(ExtensionUserScriptTest, Match1) { | 18 TEST(ExtensionUserScriptTest, Match1) { |
19 UserScript script; | 19 UserScript script; |
20 script.add_glob("*mail.google.com*"); | 20 script.add_glob("*mail.google.com*"); |
21 script.add_glob("*mail.yahoo.com*"); | 21 script.add_glob("*mail.yahoo.com*"); |
22 script.add_glob("*mail.msn.com*"); | 22 script.add_glob("*mail.msn.com*"); |
23 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); | 23 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); |
24 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); | 24 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); |
25 EXPECT_TRUE(script.MatchesUrl(GURL("https://mail.google.com/foo"))); | 25 EXPECT_TRUE(script.MatchesUrl(GURL("https://mail.google.com/foo"))); |
| 26 EXPECT_TRUE(script.MatchesUrl(GURL("httpsv://mail.google.com/foo"))); |
26 EXPECT_TRUE(script.MatchesUrl(GURL("ftp://mail.google.com/foo"))); | 27 EXPECT_TRUE(script.MatchesUrl(GURL("ftp://mail.google.com/foo"))); |
27 EXPECT_TRUE(script.MatchesUrl(GURL("http://woo.mail.google.com/foo"))); | 28 EXPECT_TRUE(script.MatchesUrl(GURL("http://woo.mail.google.com/foo"))); |
28 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar"))); | 29 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.yahoo.com/bar"))); |
29 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz"))); | 30 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.msn.com/baz"))); |
30 EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com"))); | 31 EXPECT_FALSE(script.MatchesUrl(GURL("http://www.hotmail.com"))); |
31 | 32 |
32 script.add_exclude_glob("*foo*"); | 33 script.add_exclude_glob("*foo*"); |
33 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); | 34 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); |
34 EXPECT_FALSE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); | 35 EXPECT_FALSE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); |
35 } | 36 } |
36 | 37 |
37 TEST(ExtensionUserScriptTest, Match2) { | 38 TEST(ExtensionUserScriptTest, Match2) { |
38 UserScript script; | 39 UserScript script; |
39 script.add_glob("*mail.google.com/"); | 40 script.add_glob("*mail.google.com/"); |
40 // GURL normalizes the URL to have a trailing "/" | 41 // GURL normalizes the URL to have a trailing "/" |
41 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); | 42 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); |
42 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/"))); | 43 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/"))); |
43 EXPECT_FALSE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); | 44 EXPECT_FALSE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); |
44 } | 45 } |
45 | 46 |
46 TEST(ExtensionUserScriptTest, Match3) { | 47 TEST(ExtensionUserScriptTest, Match3) { |
47 UserScript script; | 48 UserScript script; |
48 script.add_glob("http://mail.google.com/*"); | 49 script.add_glob("http://mail.google.com/*"); |
49 // GURL normalizes the URL to have a trailing "/" | 50 // GURL normalizes the URL to have a trailing "/" |
50 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); | 51 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com"))); |
51 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); | 52 EXPECT_TRUE(script.MatchesUrl(GURL("http://mail.google.com/foo"))); |
52 EXPECT_FALSE(script.MatchesUrl(GURL("https://mail.google.com/foo"))); | 53 EXPECT_FALSE(script.MatchesUrl(GURL("https://mail.google.com/foo"))); |
| 54 EXPECT_FALSE(script.MatchesUrl(GURL("httpsv://mail.google.com/foo"))); |
53 } | 55 } |
54 | 56 |
55 TEST(ExtensionUserScriptTest, Match4) { | 57 TEST(ExtensionUserScriptTest, Match4) { |
56 UserScript script; | 58 UserScript script; |
57 script.add_glob("*"); | 59 script.add_glob("*"); |
58 EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar"))); | 60 EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar"))); |
59 EXPECT_TRUE(script.MatchesUrl(GURL("http://hot.com/dog"))); | 61 EXPECT_TRUE(script.MatchesUrl(GURL("http://hot.com/dog"))); |
60 EXPECT_TRUE(script.MatchesUrl(GURL("https://hot.com/dog"))); | 62 EXPECT_TRUE(script.MatchesUrl(GURL("https://hot.com/dog"))); |
| 63 EXPECT_TRUE(script.MatchesUrl(GURL("httpsv://hot.com/dog"))); |
61 EXPECT_TRUE(script.MatchesUrl(GURL("file:///foo/bar"))); | 64 EXPECT_TRUE(script.MatchesUrl(GURL("file:///foo/bar"))); |
62 } | 65 } |
63 | 66 |
64 TEST(ExtensionUserScriptTest, Match5) { | 67 TEST(ExtensionUserScriptTest, Match5) { |
65 UserScript script; | 68 UserScript script; |
66 script.add_glob("*foo*"); | 69 script.add_glob("*foo*"); |
67 EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar"))); | 70 EXPECT_TRUE(script.MatchesUrl(GURL("http://foo.com/bar"))); |
68 EXPECT_TRUE(script.MatchesUrl(GURL("http://baz.org/foo/bar"))); | 71 EXPECT_TRUE(script.MatchesUrl(GURL("http://baz.org/foo/bar"))); |
69 EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org"))); | 72 EXPECT_FALSE(script.MatchesUrl(GURL("http://baz.org"))); |
70 } | 73 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 for (size_t i = 0; i < script1.url_patterns().size(); ++i) { | 162 for (size_t i = 0; i < script1.url_patterns().size(); ++i) { |
160 EXPECT_EQ(script1.url_patterns()[i].GetAsString(), | 163 EXPECT_EQ(script1.url_patterns()[i].GetAsString(), |
161 script2.url_patterns()[i].GetAsString()); | 164 script2.url_patterns()[i].GetAsString()); |
162 } | 165 } |
163 } | 166 } |
164 | 167 |
165 TEST(ExtensionUserScriptTest, Defaults) { | 168 TEST(ExtensionUserScriptTest, Defaults) { |
166 UserScript script; | 169 UserScript script; |
167 ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); | 170 ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); |
168 } | 171 } |
OLD | NEW |