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 // Bug fix for crbug.com/507461. |
| 582 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, |
| 583 DocumentStartInjectionFromExtensionTabNavigation) { |
| 584 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 585 |
| 586 TestExtensionDir new_tab_override_dir; |
| 587 new_tab_override_dir.WriteManifest(kNewTabOverrideManifest); |
| 588 new_tab_override_dir.WriteFile(FILE_PATH_LITERAL("newtab.html"), kNewTabHtml); |
| 589 const Extension* new_tab_override = |
| 590 LoadExtension(new_tab_override_dir.unpacked_path()); |
| 591 ASSERT_TRUE(new_tab_override); |
| 592 |
| 593 TestExtensionDir injector_dir; |
| 594 injector_dir.WriteManifest( |
| 595 base::StringPrintf(kManifest, "injector", "document_start")); |
| 596 injector_dir.WriteFile(FILE_PATH_LITERAL("script.js"), kNonBlockingScript); |
| 597 const Extension* injector = LoadExtension(injector_dir.unpacked_path()); |
| 598 ASSERT_TRUE(injector); |
| 599 |
| 600 ExtensionTestMessageListener listener("done", false); |
| 601 AddTabAtIndex(0, GURL("chrome://newtab"), ui::PAGE_TRANSITION_LINK); |
| 602 browser()->tab_strip_model()->ActivateTabAt(0, false); |
| 603 content::WebContents* tab_contents = |
| 604 browser()->tab_strip_model()->GetActiveWebContents(); |
| 605 |
| 606 EXPECT_EQ(new_tab_override->GetResourceURL("newtab.html"), |
| 607 tab_contents->GetMainFrame()->GetLastCommittedURL()); |
| 608 EXPECT_FALSE(listener.was_satisfied()); |
| 609 listener.Reset(); |
| 610 |
| 611 ui_test_utils::NavigateToURLWithDisposition( |
| 612 browser(), embedded_test_server()->GetURL("/empty.html"), |
| 613 CURRENT_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 614 base::RunLoop().RunUntilIdle(); |
| 615 EXPECT_TRUE(listener.was_satisfied()); |
| 616 } |
| 617 |
569 } // namespace extensions | 618 } // namespace extensions |
OLD | NEW |