| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "base/pickle.h" | 6 #include "base/pickle.h" |
| 7 #include "extensions/common/user_script.h" | 7 #include "extensions/common/user_script.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 10 | 10 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 EXPECT_TRUE(script.MatchesURL(GURL("http://www.nytimes.com"))); | 126 EXPECT_TRUE(script.MatchesURL(GURL("http://www.nytimes.com"))); |
| 127 EXPECT_FALSE(script.MatchesURL(GURL("http://science.nytimes.com"))); | 127 EXPECT_FALSE(script.MatchesURL(GURL("http://science.nytimes.com"))); |
| 128 EXPECT_FALSE(script.MatchesURL(GURL("http://www.nytimes.com/science"))); | 128 EXPECT_FALSE(script.MatchesURL(GURL("http://www.nytimes.com/science"))); |
| 129 } | 129 } |
| 130 | 130 |
| 131 TEST(ExtensionUserScriptTest, UrlPatternGlobInteraction) { | 131 TEST(ExtensionUserScriptTest, UrlPatternGlobInteraction) { |
| 132 // If there are both, match intersection(union(globs), union(urlpatterns)). | 132 // If there are both, match intersection(union(globs), union(urlpatterns)). |
| 133 UserScript script; | 133 UserScript script; |
| 134 | 134 |
| 135 URLPattern pattern(kAllSchemes); | 135 URLPattern pattern(kAllSchemes); |
| 136 ASSERT_EQ(URLPattern::PARSE_SUCCESS,pattern.Parse("http://www.google.com/*")); | 136 ASSERT_EQ(URLPattern::PARSE_SUCCESS, |
| 137 pattern.Parse("http://www.google.com/*")); |
| 137 script.add_url_pattern(pattern); | 138 script.add_url_pattern(pattern); |
| 138 | 139 |
| 139 script.add_glob("*bar*"); | 140 script.add_glob("*bar*"); |
| 140 | 141 |
| 141 // No match, because it doesn't match the glob. | 142 // No match, because it doesn't match the glob. |
| 142 EXPECT_FALSE(script.MatchesURL(GURL("http://www.google.com/foo"))); | 143 EXPECT_FALSE(script.MatchesURL(GURL("http://www.google.com/foo"))); |
| 143 | 144 |
| 144 script.add_exclude_glob("*baz*"); | 145 script.add_exclude_glob("*baz*"); |
| 145 | 146 |
| 146 // No match, because it matches the exclude glob. | 147 // No match, because it matches the exclude glob. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 ASSERT_EQ(script1.url_patterns(), script2.url_patterns()); | 212 ASSERT_EQ(script1.url_patterns(), script2.url_patterns()); |
| 212 ASSERT_EQ(script1.exclude_url_patterns(), script2.exclude_url_patterns()); | 213 ASSERT_EQ(script1.exclude_url_patterns(), script2.exclude_url_patterns()); |
| 213 } | 214 } |
| 214 | 215 |
| 215 TEST(ExtensionUserScriptTest, Defaults) { | 216 TEST(ExtensionUserScriptTest, Defaults) { |
| 216 UserScript script; | 217 UserScript script; |
| 217 ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); | 218 ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); |
| 218 } | 219 } |
| 219 | 220 |
| 220 } // namespace extensions | 221 } // namespace extensions |
| OLD | NEW |