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

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

Issue 1409163006: Migrating tests to use EmbeddedTestServer (/chrome/browser misc) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rebase bug. Created 5 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 kExtensionNames[3], 341 kExtensionNames[3],
342 CreateExtension(EXPLICIT_HOSTS, CONTENT_SCRIPT), 342 CreateExtension(EXPLICIT_HOSTS, CONTENT_SCRIPT),
343 browser(), 343 browser(),
344 DOES_NOT_REQUIRE_CONSENT, 344 DOES_NOT_REQUIRE_CONSENT,
345 CONTENT_SCRIPT), 345 CONTENT_SCRIPT),
346 }; 346 };
347 347
348 // Navigate to an URL (which matches the explicit host specified in the 348 // Navigate to an URL (which matches the explicit host specified in the
349 // extension content_scripts_explicit_hosts). All four extensions should 349 // extension content_scripts_explicit_hosts). All four extensions should
350 // inject the script. 350 // inject the script.
351 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 351 ASSERT_TRUE(embedded_test_server()->Start());
352 ui_test_utils::NavigateToURL( 352 ui_test_utils::NavigateToURL(
353 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); 353 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
354 354
355 for (size_t i = 0u; i < arraysize(testers); ++i) 355 for (size_t i = 0u; i < arraysize(testers); ++i)
356 EXPECT_TRUE(testers[i].Verify()) << kExtensionNames[i]; 356 EXPECT_TRUE(testers[i].Verify()) << kExtensionNames[i];
357 } 357 }
358 358
359 // Test that removing an extension with pending injections a) removes the 359 // Test that removing an extension with pending injections a) removes the
360 // pending injections for that extension, and b) does not affect pending 360 // pending injections for that extension, and b) does not affect pending
361 // injections for other extensions. 361 // injections for other extensions.
362 IN_PROC_BROWSER_TEST_F(ActiveScriptControllerBrowserTest, 362 IN_PROC_BROWSER_TEST_F(ActiveScriptControllerBrowserTest,
363 RemoveExtensionWithPendingInjections) { 363 RemoveExtensionWithPendingInjections) {
364 // Load up two extensions, each with content scripts. 364 // Load up two extensions, each with content scripts.
365 const Extension* extension1 = CreateExtension(ALL_HOSTS, CONTENT_SCRIPT); 365 const Extension* extension1 = CreateExtension(ALL_HOSTS, CONTENT_SCRIPT);
366 ASSERT_TRUE(extension1); 366 ASSERT_TRUE(extension1);
367 const Extension* extension2 = CreateExtension(ALL_HOSTS, CONTENT_SCRIPT); 367 const Extension* extension2 = CreateExtension(ALL_HOSTS, CONTENT_SCRIPT);
368 ASSERT_TRUE(extension2); 368 ASSERT_TRUE(extension2);
369 369
370 ASSERT_NE(extension1->id(), extension2->id()); 370 ASSERT_NE(extension1->id(), extension2->id());
371 371
372 content::WebContents* web_contents = 372 content::WebContents* web_contents =
373 browser()->tab_strip_model()->GetActiveWebContents(); 373 browser()->tab_strip_model()->GetActiveWebContents();
374 ASSERT_TRUE(web_contents); 374 ASSERT_TRUE(web_contents);
375 ActiveScriptController* active_script_controller = 375 ActiveScriptController* active_script_controller =
376 ActiveScriptController::GetForWebContents(web_contents); 376 ActiveScriptController::GetForWebContents(web_contents);
377 ASSERT_TRUE(active_script_controller); 377 ASSERT_TRUE(active_script_controller);
378 378
379 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 379 ASSERT_TRUE(embedded_test_server()->Start());
380 ui_test_utils::NavigateToURL( 380 ui_test_utils::NavigateToURL(
381 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); 381 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
382 382
383 // Both extensions should have pending requests. 383 // Both extensions should have pending requests.
384 EXPECT_TRUE(active_script_controller->WantsToRun(extension1)); 384 EXPECT_TRUE(active_script_controller->WantsToRun(extension1));
385 EXPECT_TRUE(active_script_controller->WantsToRun(extension2)); 385 EXPECT_TRUE(active_script_controller->WantsToRun(extension2));
386 386
387 // Unload one of the extensions. 387 // Unload one of the extensions.
388 UnloadExtension(extension2->id()); 388 UnloadExtension(extension2->id());
389 389
(...skipping 27 matching lines...) Expand all
417 ASSERT_TRUE(web_contents); 417 ASSERT_TRUE(web_contents);
418 ActiveScriptController* active_script_controller = 418 ActiveScriptController* active_script_controller =
419 ActiveScriptController::GetForWebContents(web_contents); 419 ActiveScriptController::GetForWebContents(web_contents);
420 ASSERT_TRUE(active_script_controller); 420 ASSERT_TRUE(active_script_controller);
421 421
422 ExtensionTestMessageListener inject_success_listener( 422 ExtensionTestMessageListener inject_success_listener(
423 new ExtensionTestMessageListener(kInjectSucceeded, 423 new ExtensionTestMessageListener(kInjectSucceeded,
424 false /* won't reply */)); 424 false /* won't reply */));
425 inject_success_listener.set_extension_id(extension->id()); 425 inject_success_listener.set_extension_id(extension->id());
426 426
427 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 427 ASSERT_TRUE(embedded_test_server()->Start());
428 GURL url = embedded_test_server()->GetURL("/extensions/test_file.html"); 428 GURL url = embedded_test_server()->GetURL("/extensions/test_file.html");
429 ui_test_utils::NavigateToURL(browser(), url); 429 ui_test_utils::NavigateToURL(browser(), url);
430 430
431 // The extension shouldn't be allowed to run. 431 // The extension shouldn't be allowed to run.
432 EXPECT_TRUE(active_script_controller->WantsToRun(extension)); 432 EXPECT_TRUE(active_script_controller->WantsToRun(extension));
433 EXPECT_EQ(1, active_script_controller->num_page_requests()); 433 EXPECT_EQ(1, active_script_controller->num_page_requests());
434 EXPECT_FALSE(inject_success_listener.was_satisfied()); 434 EXPECT_FALSE(inject_success_listener.was_satisfied());
435 435
436 // Enable the extension to run on all urls. 436 // Enable the extension to run on all urls.
437 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), true); 437 util::SetAllowedScriptingOnAllUrls(extension->id(), profile(), true);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 DOES_NOT_REQUIRE_CONSENT, 481 DOES_NOT_REQUIRE_CONSENT,
482 CONTENT_SCRIPT), 482 CONTENT_SCRIPT),
483 ActiveScriptTester( 483 ActiveScriptTester(
484 kExtensionNames[1], 484 kExtensionNames[1],
485 CreateExtension(ALL_HOSTS, EXECUTE_SCRIPT), 485 CreateExtension(ALL_HOSTS, EXECUTE_SCRIPT),
486 browser(), 486 browser(),
487 DOES_NOT_REQUIRE_CONSENT, 487 DOES_NOT_REQUIRE_CONSENT,
488 EXECUTE_SCRIPT), 488 EXECUTE_SCRIPT),
489 }; 489 };
490 490
491 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 491 ASSERT_TRUE(embedded_test_server()->Start());
492 ui_test_utils::NavigateToURL( 492 ui_test_utils::NavigateToURL(
493 browser(), embedded_test_server()->GetURL("/extensions/test_file.html")); 493 browser(), embedded_test_server()->GetURL("/extensions/test_file.html"));
494 494
495 for (size_t i = 0u; i < arraysize(testers); ++i) 495 for (size_t i = 0u; i < arraysize(testers); ++i)
496 EXPECT_TRUE(testers[i].Verify()) << kExtensionNames[i]; 496 EXPECT_TRUE(testers[i].Verify()) << kExtensionNames[i];
497 } 497 }
498 498
499 } // namespace extensions 499 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698