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

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

Issue 2227193002: Make UserScript non-copyable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync @tott Created 4 years, 4 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
OLDNEW
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>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/memory/ptr_util.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
19 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
20 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
21 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
22 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
23 #include "content/public/test/test_browser_thread.h" 24 #include "content/public/test/test_browser_thread.h"
24 #include "extensions/common/host_id.h" 25 #include "extensions/common/host_id.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 EXPECT_EQ("http://www.google.com/foo*", 230 EXPECT_EQ("http://www.google.com/foo*",
230 script.exclude_url_patterns().begin()->GetAsString()); 231 script.exclude_url_patterns().begin()->GetAsString());
231 } 232 }
232 233
233 TEST_F(ExtensionUserScriptLoaderTest, SkipBOMAtTheBeginning) { 234 TEST_F(ExtensionUserScriptLoaderTest, SkipBOMAtTheBeginning) {
234 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js"); 235 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js");
235 const std::string content("\xEF\xBB\xBF alert('hello');"); 236 const std::string content("\xEF\xBB\xBF alert('hello');");
236 size_t written = base::WriteFile(path, content.c_str(), content.size()); 237 size_t written = base::WriteFile(path, content.c_str(), content.size());
237 ASSERT_EQ(written, content.size()); 238 ASSERT_EQ(written, content.size());
238 239
239 UserScript user_script; 240 std::unique_ptr<UserScript> user_script(new UserScript());
240 user_script.js_scripts().push_back( 241 user_script->js_scripts().push_back(base::MakeUnique<UserScript::File>(
241 UserScript::File(temp_dir_.path(), path.BaseName(), GURL())); 242 temp_dir_.path(), path.BaseName(), GURL()));
242 243
243 UserScriptList user_scripts; 244 UserScriptList user_scripts;
244 user_scripts.push_back(user_script); 245 user_scripts.push_back(std::move(user_script));
245 246
246 TestingProfile profile; 247 TestingProfile profile;
247 ExtensionUserScriptLoader loader( 248 ExtensionUserScriptLoader loader(
248 &profile, 249 &profile,
249 HostID(), 250 HostID(),
250 true /* listen_for_extension_system_loaded */); 251 true /* listen_for_extension_system_loaded */);
251 loader.LoadScriptsForTest(&user_scripts); 252 loader.LoadScriptsForTest(&user_scripts);
252 253
253 EXPECT_EQ(content.substr(3), 254 EXPECT_EQ(content.substr(3),
254 user_scripts[0].js_scripts()[0].GetContent().as_string()); 255 user_scripts[0]->js_scripts()[0]->GetContent().as_string());
255 } 256 }
256 257
257 TEST_F(ExtensionUserScriptLoaderTest, LeaveBOMNotAtTheBeginning) { 258 TEST_F(ExtensionUserScriptLoaderTest, LeaveBOMNotAtTheBeginning) {
258 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js"); 259 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js");
259 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');");
260 size_t written = base::WriteFile(path, content.c_str(), content.size()); 261 size_t written = base::WriteFile(path, content.c_str(), content.size());
261 ASSERT_EQ(written, content.size()); 262 ASSERT_EQ(written, content.size());
262 263
263 UserScript user_script; 264 std::unique_ptr<UserScript> user_script(new UserScript());
264 user_script.js_scripts().push_back(UserScript::File( 265 user_script->js_scripts().push_back(base::MakeUnique<UserScript::File>(
265 temp_dir_.path(), path.BaseName(), GURL())); 266 temp_dir_.path(), path.BaseName(), GURL()));
266 267
267 UserScriptList user_scripts; 268 UserScriptList user_scripts;
268 user_scripts.push_back(user_script); 269 user_scripts.push_back(std::move(user_script));
269 270
270 TestingProfile profile; 271 TestingProfile profile;
271 ExtensionUserScriptLoader loader( 272 ExtensionUserScriptLoader loader(
272 &profile, 273 &profile,
273 HostID(), 274 HostID(),
274 true /* listen_for_extension_system_loaded */); 275 true /* listen_for_extension_system_loaded */);
275 loader.LoadScriptsForTest(&user_scripts); 276 loader.LoadScriptsForTest(&user_scripts);
276 277
277 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); 278 EXPECT_EQ(content,
279 user_scripts[0]->js_scripts()[0]->GetContent().as_string());
278 } 280 }
279 281
280 } // namespace extensions 282 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service_unittest.cc ('k') | chrome/browser/extensions/shared_user_script_master.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698