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

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

Issue 226663003: Allow content script insertion on about:-URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use matches_about_blank key instead of about:* permission. Created 6 years, 8 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 (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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 text, &script)); 222 text, &script));
223 ASSERT_EQ("myscript", script.name()); 223 ASSERT_EQ("myscript", script.name());
224 ASSERT_EQ(1U, script.url_patterns().patterns().size()); 224 ASSERT_EQ(1U, script.url_patterns().patterns().size());
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, Parse9) {
233 const std::string text(
234 "// ==UserScript==\n"
235 "// @include about:blank\n"
not at google - send to devlin 2014/04/21 19:56:22 ah. do we really need to make this work for about:
robwu 2014/04/21 22:15:41 No, my use case does not require about:blank for u
236 "// @match http://example.com/*\n"
237 "// ==/UserScript==\n");
238
239 UserScript script;
240 EXPECT_TRUE(
241 UserScriptMaster::ScriptReloader::ParseMetadataHeader(text, &script));
242 ASSERT_EQ(0U, script.globs().size());
243 EXPECT_TRUE(script.match_about_blank());
244 }
245
232 TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) { 246 TEST_F(UserScriptMasterTest, SkipBOMAtTheBeginning) {
233 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js"); 247 base::FilePath path = temp_dir_.path().AppendASCII("script.user.js");
234 const std::string content("\xEF\xBB\xBF alert('hello');"); 248 const std::string content("\xEF\xBB\xBF alert('hello');");
235 size_t written = base::WriteFile(path, content.c_str(), content.size()); 249 size_t written = base::WriteFile(path, content.c_str(), content.size());
236 ASSERT_EQ(written, content.size()); 250 ASSERT_EQ(written, content.size());
237 251
238 UserScript user_script; 252 UserScript user_script;
239 user_script.js_scripts().push_back(UserScript::File( 253 user_script.js_scripts().push_back(UserScript::File(
240 temp_dir_.path(), path.BaseName(), GURL())); 254 temp_dir_.path(), path.BaseName(), GURL()));
241 255
(...skipping 26 matching lines...) Expand all
268 UserScriptMaster::ScriptReloader* script_reloader = 282 UserScriptMaster::ScriptReloader* script_reloader =
269 new UserScriptMaster::ScriptReloader(NULL); 283 new UserScriptMaster::ScriptReloader(NULL);
270 script_reloader->AddRef(); 284 script_reloader->AddRef();
271 script_reloader->LoadUserScripts(&user_scripts); 285 script_reloader->LoadUserScripts(&user_scripts);
272 script_reloader->Release(); 286 script_reloader->Release();
273 287
274 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); 288 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string());
275 } 289 }
276 290
277 } // namespace extensions 291 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698