| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/extensions/user_script_master.h" | 5 #include "chrome/browser/extensions/user_script_master.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 size_t written = file_util::WriteFile(path, content.c_str(), content.size()); | 213 size_t written = file_util::WriteFile(path, content.c_str(), content.size()); |
| 214 ASSERT_EQ(written, content.size()); | 214 ASSERT_EQ(written, content.size()); |
| 215 | 215 |
| 216 UserScript user_script; | 216 UserScript user_script; |
| 217 user_script.js_scripts().push_back(UserScript::File( | 217 user_script.js_scripts().push_back(UserScript::File( |
| 218 temp_dir_.path(), path.BaseName(), GURL())); | 218 temp_dir_.path(), path.BaseName(), GURL())); |
| 219 | 219 |
| 220 UserScriptList user_scripts; | 220 UserScriptList user_scripts; |
| 221 user_scripts.push_back(user_script); | 221 user_scripts.push_back(user_script); |
| 222 | 222 |
| 223 UserScriptMaster::ScriptReloader::LoadUserScripts(&user_scripts); | 223 UserScriptMaster::ScriptReloader* script_reloader = |
| 224 new UserScriptMaster::ScriptReloader(NULL); |
| 225 script_reloader->AddRef(); |
| 226 script_reloader->LoadUserScripts(&user_scripts); |
| 227 script_reloader->Release(); |
| 224 | 228 |
| 225 EXPECT_EQ(content.substr(3), | 229 EXPECT_EQ(content.substr(3), |
| 226 user_scripts[0].js_scripts()[0].GetContent().as_string()); | 230 user_scripts[0].js_scripts()[0].GetContent().as_string()); |
| 227 } | 231 } |
| 228 | 232 |
| 229 TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) { | 233 TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) { |
| 230 FilePath path = temp_dir_.path().AppendASCII("script.user.js"); | 234 FilePath path = temp_dir_.path().AppendASCII("script.user.js"); |
| 231 const std::string content("alert('here's a BOOM: \xEF\xBB\xBF');"); | 235 const std::string content("alert('here's a BOOM: \xEF\xBB\xBF');"); |
| 232 size_t written = file_util::WriteFile(path, content.c_str(), content.size()); | 236 size_t written = file_util::WriteFile(path, content.c_str(), content.size()); |
| 233 ASSERT_EQ(written, content.size()); | 237 ASSERT_EQ(written, content.size()); |
| 234 | 238 |
| 235 UserScript user_script; | 239 UserScript user_script; |
| 236 user_script.js_scripts().push_back(UserScript::File( | 240 user_script.js_scripts().push_back(UserScript::File( |
| 237 temp_dir_.path(), path.BaseName(), GURL())); | 241 temp_dir_.path(), path.BaseName(), GURL())); |
| 238 | 242 |
| 239 UserScriptList user_scripts; | 243 UserScriptList user_scripts; |
| 240 user_scripts.push_back(user_script); | 244 user_scripts.push_back(user_script); |
| 241 | 245 |
| 242 UserScriptMaster::ScriptReloader::LoadUserScripts(&user_scripts); | 246 UserScriptMaster::ScriptReloader* script_reloader = |
| 247 new UserScriptMaster::ScriptReloader(NULL); |
| 248 script_reloader->AddRef(); |
| 249 script_reloader->LoadUserScripts(&user_scripts); |
| 250 script_reloader->Release(); |
| 243 | 251 |
| 244 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); | 252 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); |
| 245 } | 253 } |
| OLD | NEW |