Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/api/permissions/permissions_api.h" | 9 #include "chrome/browser/extensions/api/permissions/permissions_api.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/test_extension_dir.h" | 12 #include "chrome/browser/extensions/test_extension_dir.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "components/app_modal/javascript_dialog_extensions_client.h" | 17 #include "components/app_modal/javascript_dialog_extensions_client.h" |
| 18 #include "components/app_modal/javascript_dialog_manager.h" | 18 #include "components/app_modal/javascript_dialog_manager.h" |
| 19 #include "content/public/browser/javascript_dialog_manager.h" | 19 #include "content/public/browser/javascript_dialog_manager.h" |
| 20 #include "content/public/browser/render_frame_host.h" | |
| 20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/browser/web_contents_delegate.h" | 22 #include "content/public/browser/web_contents_delegate.h" |
| 22 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 23 #include "extensions/browser/notification_types.h" | 24 #include "extensions/browser/notification_types.h" |
| 24 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 25 #include "extensions/test/extension_test_message_listener.h" | 26 #include "extensions/test/extension_test_message_listener.h" |
| 26 #include "extensions/test/result_catcher.h" | 27 #include "extensions/test/result_catcher.h" |
| 27 #include "net/dns/mock_host_resolver.h" | 28 #include "net/dns/mock_host_resolver.h" |
| 28 #include "net/test/embedded_test_server/embedded_test_server.h" | 29 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 29 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 " \"run_at\": \"%s\"" | 208 " \"run_at\": \"%s\"" |
| 208 " }]" | 209 " }]" |
| 209 "}"; | 210 "}"; |
| 210 | 211 |
| 211 // A (blocking) content script that pops up an alert. | 212 // A (blocking) content script that pops up an alert. |
| 212 const char kBlockingScript[] = "alert('ALERT');"; | 213 const char kBlockingScript[] = "alert('ALERT');"; |
| 213 | 214 |
| 214 // A (non-blocking) content script that sends a message. | 215 // A (non-blocking) content script that sends a message. |
| 215 const char kNonBlockingScript[] = "chrome.test.sendMessage('done');"; | 216 const char kNonBlockingScript[] = "chrome.test.sendMessage('done');"; |
| 216 | 217 |
| 218 const char kNewTabOverrideManifest[] = | |
| 219 "{" | |
| 220 " \"name\": \"New tab override\"," | |
| 221 " \"version\": \"0.1\"," | |
| 222 " \"manifest_version\": 2," | |
| 223 " \"description\": \"Foo!\"," | |
| 224 " \"chrome_url_overrides\": {\"newtab\": \"newtab.html\"}" | |
| 225 "}"; | |
| 226 | |
| 227 const char kNewTabHtml[] = "<html>NewTabOverride!</html>"; | |
| 228 | |
| 217 } // namespace | 229 } // namespace |
| 218 | 230 |
| 219 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) { | 231 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAllFrames) { |
| 220 ASSERT_TRUE(StartEmbeddedTestServer()); | 232 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 221 ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_; | 233 ASSERT_TRUE(RunExtensionTest("content_scripts/all_frames")) << message_; |
| 222 } | 234 } |
| 223 | 235 |
| 224 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAboutBlankIframes) { | 236 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, ContentScriptAboutBlankIframes) { |
| 225 ASSERT_TRUE(StartEmbeddedTestServer()); | 237 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 226 ASSERT_TRUE( | 238 ASSERT_TRUE( |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 run_loop.Run(); | 571 run_loop.Run(); |
| 560 | 572 |
| 561 // The extension will have injected at idle, but it should only inject once. | 573 // The extension will have injected at idle, but it should only inject once. |
| 562 EXPECT_TRUE(RunAllPending(web_contents)); | 574 EXPECT_TRUE(RunAllPending(web_contents)); |
| 563 EXPECT_EQ(1u, dialog_helper.dialog_count()); | 575 EXPECT_EQ(1u, dialog_helper.dialog_count()); |
| 564 dialog_helper.CloseDialogs(); | 576 dialog_helper.CloseDialogs(); |
| 565 EXPECT_TRUE(RunAllPending(web_contents)); | 577 EXPECT_TRUE(RunAllPending(web_contents)); |
| 566 EXPECT_EQ(1u, dialog_helper.dialog_count()); | 578 EXPECT_EQ(1u, dialog_helper.dialog_count()); |
| 567 } | 579 } |
| 568 | 580 |
| 581 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, | |
| 582 DocumentStartInjectionFromExtensionTabNavigation) { | |
|
not at google - send to devlin
2015/07/09 21:39:30
(clang-format should fix this)
Devlin
2015/07/10 00:58:23
But, for some reason, it didn't complain. Done.
| |
| 583 ASSERT_TRUE(StartEmbeddedTestServer()); | |
| 584 | |
| 585 TestExtensionDir new_tab_override_dir; | |
| 586 new_tab_override_dir.WriteManifest(kNewTabOverrideManifest); | |
| 587 new_tab_override_dir.WriteFile(FILE_PATH_LITERAL("newtab.html"), kNewTabHtml); | |
| 588 const Extension* new_tab_override = | |
| 589 LoadExtension(new_tab_override_dir.unpacked_path()); | |
| 590 ASSERT_TRUE(new_tab_override); | |
| 591 | |
| 592 TestExtensionDir injector_dir; | |
| 593 injector_dir.WriteManifest( | |
| 594 base::StringPrintf(kManifest, "injector", "document_start")); | |
| 595 injector_dir.WriteFile(FILE_PATH_LITERAL("script.js"), kNonBlockingScript); | |
| 596 const Extension* injector = LoadExtension(injector_dir.unpacked_path()); | |
| 597 ASSERT_TRUE(injector); | |
| 598 | |
| 599 ExtensionTestMessageListener listener("done", false); | |
| 600 AddTabAtIndex(0, GURL("chrome://newtab"), ui::PAGE_TRANSITION_LINK); | |
| 601 browser()->tab_strip_model()->ActivateTabAt(0, false); | |
| 602 content::WebContents* tab_contents = | |
| 603 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 604 | |
| 605 EXPECT_EQ(new_tab_override->GetResourceURL("newtab.html"), | |
| 606 tab_contents->GetMainFrame()->GetLastCommittedURL()); | |
| 607 EXPECT_FALSE(listener.was_satisfied()); | |
| 608 listener.Reset(); | |
| 609 | |
| 610 ui_test_utils::NavigateToURLWithDisposition( | |
| 611 browser(), embedded_test_server()->GetURL("/empty.html"), | |
| 612 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 613 base::RunLoop().RunUntilIdle(); | |
| 614 EXPECT_TRUE(listener.was_satisfied()); | |
| 615 } | |
| 616 | |
| 569 } // namespace extensions | 617 } // namespace extensions |
| OLD | NEW |