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

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

Issue 635573005: Cleanup: Better constify some strings in chrome/browser/{chromeos,extensions}. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, nit Created 6 years, 1 month 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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/extensions/active_script_controller.h" 8 #include "chrome/browser/extensions/active_script_controller.h"
9 #include "chrome/browser/extensions/extension_action.h" 9 #include "chrome/browser/extensions/extension_action.h"
10 #include "chrome/browser/extensions/extension_browsertest.h" 10 #include "chrome/browser/extensions/extension_browsertest.h"
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 101
102 const Extension* ActiveScriptControllerBrowserTest::CreateExtension( 102 const Extension* ActiveScriptControllerBrowserTest::CreateExtension(
103 HostType host_type, InjectionType injection_type) { 103 HostType host_type, InjectionType injection_type) {
104 std::string name = 104 std::string name =
105 base::StringPrintf( 105 base::StringPrintf(
106 "%s %s", 106 "%s %s",
107 injection_type == CONTENT_SCRIPT ? 107 injection_type == CONTENT_SCRIPT ?
108 "content_script" : "execute_script", 108 "content_script" : "execute_script",
109 host_type == ALL_HOSTS ? "all_hosts" : "explicit_hosts"); 109 host_type == ALL_HOSTS ? "all_hosts" : "explicit_hosts");
110 110
111 const char* permission_scheme = 111 const char* const permission_scheme =
112 host_type == ALL_HOSTS ? kAllHostsScheme : kExplicitHostsScheme; 112 host_type == ALL_HOSTS ? kAllHostsScheme : kExplicitHostsScheme;
113 113
114 std::string permissions = base::StringPrintf( 114 std::string permissions = base::StringPrintf(
115 "\"permissions\": [\"tabs\", \"%s\"]", permission_scheme); 115 "\"permissions\": [\"tabs\", \"%s\"]", permission_scheme);
116 116
117 std::string scripts; 117 std::string scripts;
118 std::string script_source; 118 std::string script_source;
119 if (injection_type == CONTENT_SCRIPT) { 119 if (injection_type == CONTENT_SCRIPT) {
120 scripts = base::StringPrintf( 120 scripts = base::StringPrintf(
121 "\"content_scripts\": [" 121 "\"content_scripts\": ["
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 bool ActiveScriptTester::WantsToRun() { 296 bool ActiveScriptTester::WantsToRun() {
297 ActiveScriptController* controller = GetActiveScriptController(); 297 ActiveScriptController* controller = GetActiveScriptController();
298 return controller ? controller->WantsToRun(extension_) : false; 298 return controller ? controller->WantsToRun(extension_) : false;
299 } 299 }
300 300
301 IN_PROC_BROWSER_TEST_F(ActiveScriptControllerBrowserTest, 301 IN_PROC_BROWSER_TEST_F(ActiveScriptControllerBrowserTest,
302 ActiveScriptsAreDisplayedAndDelayExecution) { 302 ActiveScriptsAreDisplayedAndDelayExecution) {
303 base::FilePath active_script_path = 303 base::FilePath active_script_path =
304 test_data_dir_.AppendASCII("active_script"); 304 test_data_dir_.AppendASCII("active_script");
305 305
306 const char* kExtensionNames[] = { 306 const char* const kExtensionNames[] = {
307 "inject_scripts_all_hosts", 307 "inject_scripts_all_hosts",
308 "inject_scripts_explicit_hosts", 308 "inject_scripts_explicit_hosts",
309 "content_scripts_all_hosts", 309 "content_scripts_all_hosts",
310 "content_scripts_explicit_hosts" 310 "content_scripts_explicit_hosts"
311 }; 311 };
312 312
313 // First, we load up three extensions: 313 // First, we load up three extensions:
314 // - An extension that injects scripts into all hosts, 314 // - An extension that injects scripts into all hosts,
315 // - An extension that injects scripts into explicit hosts, 315 // - An extension that injects scripts into explicit hosts,
316 // - An extension with a content script that runs on all hosts, 316 // - An extension with a content script that runs on all hosts,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 : public ActiveScriptControllerBrowserTest { 408 : public ActiveScriptControllerBrowserTest {
409 private: 409 private:
410 // Simply don't append the flag. 410 // Simply don't append the flag.
411 void SetUpCommandLine(base::CommandLine* command_line) override { 411 void SetUpCommandLine(base::CommandLine* command_line) override {
412 ExtensionBrowserTest::SetUpCommandLine(command_line); 412 ExtensionBrowserTest::SetUpCommandLine(command_line);
413 } 413 }
414 }; 414 };
415 415
416 IN_PROC_BROWSER_TEST_F(FlagOffActiveScriptControllerBrowserTest, 416 IN_PROC_BROWSER_TEST_F(FlagOffActiveScriptControllerBrowserTest,
417 ScriptsExecuteWhenFlagAbsent) { 417 ScriptsExecuteWhenFlagAbsent) {
418 const char* kExtensionNames[] = { 418 const char* const kExtensionNames[] = {
419 "content_scripts_all_hosts", 419 "content_scripts_all_hosts",
420 "inject_scripts_all_hosts", 420 "inject_scripts_all_hosts",
421 }; 421 };
422 ActiveScriptTester testers[] = { 422 ActiveScriptTester testers[] = {
423 ActiveScriptTester( 423 ActiveScriptTester(
424 kExtensionNames[0], 424 kExtensionNames[0],
425 CreateExtension(ALL_HOSTS, CONTENT_SCRIPT), 425 CreateExtension(ALL_HOSTS, CONTENT_SCRIPT),
426 browser(), 426 browser(),
427 DOES_NOT_REQUIRE_CONSENT, 427 DOES_NOT_REQUIRE_CONSENT,
428 CONTENT_SCRIPT), 428 CONTENT_SCRIPT),
429 ActiveScriptTester( 429 ActiveScriptTester(
430 kExtensionNames[1], 430 kExtensionNames[1],
431 CreateExtension(ALL_HOSTS, EXECUTE_SCRIPT), 431 CreateExtension(ALL_HOSTS, EXECUTE_SCRIPT),
432 browser(), 432 browser(),
433 DOES_NOT_REQUIRE_CONSENT, 433 DOES_NOT_REQUIRE_CONSENT,
434 EXECUTE_SCRIPT), 434 EXECUTE_SCRIPT),
435 }; 435 };
436 436
437 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 437 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
438 ui_test_utils::NavigateToURL( 438 ui_test_utils::NavigateToURL(
439 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); 439 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
440 440
441 for (size_t i = 0u; i < arraysize(testers); ++i) 441 for (size_t i = 0u; i < arraysize(testers); ++i)
442 EXPECT_TRUE(testers[i].Verify()) << kExtensionNames[i]; 442 EXPECT_TRUE(testers[i].Verify()) << kExtensionNames[i];
443 } 443 }
444 444
445 } // namespace extensions 445 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698