OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_user_script_loader.h" | 5 #include "extensions/browser/extension_user_script_loader.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 ASSERT_EQ("myscript", script.name()); | 225 ASSERT_EQ("myscript", script.name()); |
226 ASSERT_EQ(1U, script.url_patterns().patterns().size()); | 226 ASSERT_EQ(1U, script.url_patterns().patterns().size()); |
227 EXPECT_EQ("http://www.google.com/*", | 227 EXPECT_EQ("http://www.google.com/*", |
228 script.url_patterns().begin()->GetAsString()); | 228 script.url_patterns().begin()->GetAsString()); |
229 ASSERT_EQ(1U, script.exclude_url_patterns().patterns().size()); | 229 ASSERT_EQ(1U, script.exclude_url_patterns().patterns().size()); |
230 EXPECT_EQ("http://www.google.com/foo*", | 230 EXPECT_EQ("http://www.google.com/foo*", |
231 script.exclude_url_patterns().begin()->GetAsString()); | 231 script.exclude_url_patterns().begin()->GetAsString()); |
232 } | 232 } |
233 | 233 |
234 TEST_F(ExtensionUserScriptLoaderTest, SkipBOMAtTheBeginning) { | 234 TEST_F(ExtensionUserScriptLoaderTest, SkipBOMAtTheBeginning) { |
235 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js"); | 235 base::FilePath path = temp_dir_.GetPath().AppendASCII("script.user.js"); |
236 const std::string content("\xEF\xBB\xBF alert('hello');"); | 236 const std::string content("\xEF\xBB\xBF alert('hello');"); |
237 size_t written = base::WriteFile(path, content.c_str(), content.size()); | 237 size_t written = base::WriteFile(path, content.c_str(), content.size()); |
238 ASSERT_EQ(written, content.size()); | 238 ASSERT_EQ(written, content.size()); |
239 | 239 |
240 std::unique_ptr<UserScript> user_script(new UserScript()); | 240 std::unique_ptr<UserScript> user_script(new UserScript()); |
241 user_script->js_scripts().push_back(base::MakeUnique<UserScript::File>( | 241 user_script->js_scripts().push_back(base::MakeUnique<UserScript::File>( |
242 temp_dir_.path(), path.BaseName(), GURL())); | 242 temp_dir_.GetPath(), path.BaseName(), GURL())); |
243 | 243 |
244 UserScriptList user_scripts; | 244 UserScriptList user_scripts; |
245 user_scripts.push_back(std::move(user_script)); | 245 user_scripts.push_back(std::move(user_script)); |
246 | 246 |
247 TestingProfile profile; | 247 TestingProfile profile; |
248 ExtensionUserScriptLoader loader( | 248 ExtensionUserScriptLoader loader( |
249 &profile, | 249 &profile, |
250 HostID(), | 250 HostID(), |
251 true /* listen_for_extension_system_loaded */); | 251 true /* listen_for_extension_system_loaded */); |
252 loader.LoadScriptsForTest(&user_scripts); | 252 loader.LoadScriptsForTest(&user_scripts); |
253 | 253 |
254 EXPECT_EQ(content.substr(3), | 254 EXPECT_EQ(content.substr(3), |
255 user_scripts[0]->js_scripts()[0]->GetContent().as_string()); | 255 user_scripts[0]->js_scripts()[0]->GetContent().as_string()); |
256 } | 256 } |
257 | 257 |
258 TEST_F(ExtensionUserScriptLoaderTest, LeaveBOMNotAtTheBeginning) { | 258 TEST_F(ExtensionUserScriptLoaderTest, LeaveBOMNotAtTheBeginning) { |
259 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js"); | 259 base::FilePath path = temp_dir_.GetPath().AppendASCII("script.user.js"); |
260 const std::string content("alert('here's a BOOM: \xEF\xBB\xBF');"); | 260 const std::string content("alert('here's a BOOM: \xEF\xBB\xBF');"); |
261 size_t written = base::WriteFile(path, content.c_str(), content.size()); | 261 size_t written = base::WriteFile(path, content.c_str(), content.size()); |
262 ASSERT_EQ(written, content.size()); | 262 ASSERT_EQ(written, content.size()); |
263 | 263 |
264 std::unique_ptr<UserScript> user_script(new UserScript()); | 264 std::unique_ptr<UserScript> user_script(new UserScript()); |
265 user_script->js_scripts().push_back(base::MakeUnique<UserScript::File>( | 265 user_script->js_scripts().push_back(base::MakeUnique<UserScript::File>( |
266 temp_dir_.path(), path.BaseName(), GURL())); | 266 temp_dir_.GetPath(), path.BaseName(), GURL())); |
267 | 267 |
268 UserScriptList user_scripts; | 268 UserScriptList user_scripts; |
269 user_scripts.push_back(std::move(user_script)); | 269 user_scripts.push_back(std::move(user_script)); |
270 | 270 |
271 TestingProfile profile; | 271 TestingProfile profile; |
272 ExtensionUserScriptLoader loader( | 272 ExtensionUserScriptLoader loader( |
273 &profile, | 273 &profile, |
274 HostID(), | 274 HostID(), |
275 true /* listen_for_extension_system_loaded */); | 275 true /* listen_for_extension_system_loaded */); |
276 loader.LoadScriptsForTest(&user_scripts); | 276 loader.LoadScriptsForTest(&user_scripts); |
277 | 277 |
278 EXPECT_EQ(content, | 278 EXPECT_EQ(content, |
279 user_scripts[0]->js_scripts()[0]->GetContent().as_string()); | 279 user_scripts[0]->js_scripts()[0]->GetContent().as_string()); |
280 } | 280 } |
281 | 281 |
282 } // namespace extensions | 282 } // namespace extensions |
OLD | NEW |