OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 = |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 script1.set_run_location(UserScript::DOCUMENT_START); | 182 script1.set_run_location(UserScript::DOCUMENT_START); |
183 | 183 |
184 script1.add_url_pattern(pattern1); | 184 script1.add_url_pattern(pattern1); |
185 script1.add_url_pattern(pattern2); | 185 script1.add_url_pattern(pattern2); |
186 script1.add_exclude_url_pattern(exclude1); | 186 script1.add_exclude_url_pattern(exclude1); |
187 script1.add_exclude_url_pattern(exclude2); | 187 script1.add_exclude_url_pattern(exclude2); |
188 | 188 |
189 Pickle pickle; | 189 Pickle pickle; |
190 script1.Pickle(&pickle); | 190 script1.Pickle(&pickle); |
191 | 191 |
192 void* iter = NULL; | 192 PickleIterator iter(pickle); |
193 UserScript script2; | 193 UserScript script2; |
194 script2.Unpickle(pickle, &iter); | 194 script2.Unpickle(pickle, &iter); |
195 | 195 |
196 EXPECT_EQ(1U, script2.js_scripts().size()); | 196 EXPECT_EQ(1U, script2.js_scripts().size()); |
197 EXPECT_EQ(script1.js_scripts()[0].url(), script2.js_scripts()[0].url()); | 197 EXPECT_EQ(script1.js_scripts()[0].url(), script2.js_scripts()[0].url()); |
198 | 198 |
199 EXPECT_EQ(2U, script2.css_scripts().size()); | 199 EXPECT_EQ(2U, script2.css_scripts().size()); |
200 for (size_t i = 0; i < script2.js_scripts().size(); ++i) { | 200 for (size_t i = 0; i < script2.js_scripts().size(); ++i) { |
201 EXPECT_EQ(script1.css_scripts()[i].url(), script2.css_scripts()[i].url()); | 201 EXPECT_EQ(script1.css_scripts()[i].url(), script2.css_scripts()[i].url()); |
202 } | 202 } |
203 | 203 |
204 ASSERT_EQ(script1.globs().size(), script2.globs().size()); | 204 ASSERT_EQ(script1.globs().size(), script2.globs().size()); |
205 for (size_t i = 0; i < script1.globs().size(); ++i) { | 205 for (size_t i = 0; i < script1.globs().size(); ++i) { |
206 EXPECT_EQ(script1.globs()[i], script2.globs()[i]); | 206 EXPECT_EQ(script1.globs()[i], script2.globs()[i]); |
207 } | 207 } |
208 | 208 |
209 ASSERT_EQ(script1.url_patterns(), script2.url_patterns()); | 209 ASSERT_EQ(script1.url_patterns(), script2.url_patterns()); |
210 ASSERT_EQ(script1.exclude_url_patterns(), script2.exclude_url_patterns()); | 210 ASSERT_EQ(script1.exclude_url_patterns(), script2.exclude_url_patterns()); |
211 } | 211 } |
212 | 212 |
213 TEST(ExtensionUserScriptTest, Defaults) { | 213 TEST(ExtensionUserScriptTest, Defaults) { |
214 UserScript script; | 214 UserScript script; |
215 ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); | 215 ASSERT_EQ(UserScript::DOCUMENT_IDLE, script.run_location()); |
216 } | 216 } |
OLD | NEW |