Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Side by Side Diff: chrome/browser/extensions/user_script_master_unittest.cc

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 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 "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_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 EXPECT_EQ("http://www.google.com/*", 225 EXPECT_EQ("http://www.google.com/*",
226 script.url_patterns().begin()->GetAsString()); 226 script.url_patterns().begin()->GetAsString());
227 ASSERT_EQ(1U, script.exclude_url_patterns().patterns().size()); 227 ASSERT_EQ(1U, script.exclude_url_patterns().patterns().size());
228 EXPECT_EQ("http://www.google.com/foo*", 228 EXPECT_EQ("http://www.google.com/foo*",
229 script.exclude_url_patterns().begin()->GetAsString()); 229 script.exclude_url_patterns().begin()->GetAsString());
230 } 230 }
231 231
232 TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) { 232 TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) {
233 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js"); 233 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js");
234 const std::string content("\xEF\xBB\xBF alert('hello');"); 234 const std::string content("\xEF\xBB\xBF alert('hello');");
235 size_t written = file_util::WriteFile(path, content.c_str(), content.size()); 235 size_t written = base::WriteFile(path, content.c_str(), content.size());
236 ASSERT_EQ(written, content.size()); 236 ASSERT_EQ(written, content.size());
237 237
238 UserScript user_script; 238 UserScript user_script;
239 user_script.js_scripts().push_back(UserScript::File( 239 user_script.js_scripts().push_back(UserScript::File(
240 temp_dir_.path(), path.BaseName(), GURL())); 240 temp_dir_.path(), path.BaseName(), GURL()));
241 241
242 UserScriptList user_scripts; 242 UserScriptList user_scripts;
243 user_scripts.push_back(user_script); 243 user_scripts.push_back(user_script);
244 244
245 UserScriptMaster::ScriptReloader* script_reloader = 245 UserScriptMaster::ScriptReloader* script_reloader =
246 new UserScriptMaster::ScriptReloader(NULL); 246 new UserScriptMaster::ScriptReloader(NULL);
247 script_reloader->AddRef(); 247 script_reloader->AddRef();
248 script_reloader->LoadUserScripts(&user_scripts); 248 script_reloader->LoadUserScripts(&user_scripts);
249 script_reloader->Release(); 249 script_reloader->Release();
250 250
251 EXPECT_EQ(content.substr(3), 251 EXPECT_EQ(content.substr(3),
252 user_scripts[0].js_scripts()[0].GetContent().as_string()); 252 user_scripts[0].js_scripts()[0].GetContent().as_string());
253 } 253 }
254 254
255 TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) { 255 TEST_F(UserScriptMasterTest, LeaveBOMNotAtTheBeginning) {
256 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js"); 256 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js");
257 const std::string content("alert('here's a BOOM: \xEF\xBB\xBF');"); 257 const std::string content("alert('here's a BOOM: \xEF\xBB\xBF');");
258 size_t written = file_util::WriteFile(path, content.c_str(), content.size()); 258 size_t written = base::WriteFile(path, content.c_str(), content.size());
259 ASSERT_EQ(written, content.size()); 259 ASSERT_EQ(written, content.size());
260 260
261 UserScript user_script; 261 UserScript user_script;
262 user_script.js_scripts().push_back(UserScript::File( 262 user_script.js_scripts().push_back(UserScript::File(
263 temp_dir_.path(), path.BaseName(), GURL())); 263 temp_dir_.path(), path.BaseName(), GURL()));
264 264
265 UserScriptList user_scripts; 265 UserScriptList user_scripts;
266 user_scripts.push_back(user_script); 266 user_scripts.push_back(user_script);
267 267
268 UserScriptMaster::ScriptReloader* script_reloader = 268 UserScriptMaster::ScriptReloader* script_reloader =
269 new UserScriptMaster::ScriptReloader(NULL); 269 new UserScriptMaster::ScriptReloader(NULL);
270 script_reloader->AddRef(); 270 script_reloader->AddRef();
271 script_reloader->LoadUserScripts(&user_scripts); 271 script_reloader->LoadUserScripts(&user_scripts);
272 script_reloader->Release(); 272 script_reloader->Release();
273 273
274 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); 274 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string());
275 } 275 }
276 276
277 } // namespace extensions 277 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/updater/local_extension_cache_unittest.cc ('k') | chrome/browser/feedback/feedback_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698