OLD | NEW |
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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_content_browser_client.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 13 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
12 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" | 14 #include "chrome/browser/loader/chrome_resource_dispatcher_host_delegate.h" |
13 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
16 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
18 #include "components/guest_view/browser/guest_view_manager_delegate.h" | 20 #include "components/guest_view/browser/guest_view_manager_delegate.h" |
19 #include "components/guest_view/browser/test_guest_view_manager.h" | 21 #include "components/guest_view/browser/test_guest_view_manager.h" |
| 22 #include "components/spellcheck/spellcheck_build_features.h" |
20 #include "content/public/browser/interstitial_page.h" | 23 #include "content/public/browser/interstitial_page.h" |
21 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
22 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_types.h" | 26 #include "content/public/browser/notification_types.h" |
24 #include "content/public/browser/render_frame_host.h" | 27 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/render_process_host.h" |
25 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
26 #include "content/public/browser/web_contents_observer.h" | 30 #include "content/public/browser/web_contents_observer.h" |
27 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
28 #include "content/public/test/content_browser_test_utils.h" | 32 #include "content/public/test/content_browser_test_utils.h" |
29 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
30 #include "extensions/browser/api/extensions_api_client.h" | 34 #include "extensions/browser/api/extensions_api_client.h" |
31 #include "net/dns/mock_host_resolver.h" | 35 #include "net/dns/mock_host_resolver.h" |
32 #include "net/test/embedded_test_server/embedded_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
33 #include "ui/display/display_switches.h" | 37 #include "ui/display/display_switches.h" |
34 #include "url/gurl.h" | 38 #include "url/gurl.h" |
35 | 39 |
| 40 #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 41 #include "components/spellcheck/common/spellcheck_messages.h" |
| 42 #endif |
| 43 |
36 class ChromeSitePerProcessTest : public InProcessBrowserTest { | 44 class ChromeSitePerProcessTest : public InProcessBrowserTest { |
37 public: | 45 public: |
38 ChromeSitePerProcessTest() {} | 46 ChromeSitePerProcessTest() {} |
39 ~ChromeSitePerProcessTest() override {} | 47 ~ChromeSitePerProcessTest() override {} |
40 | 48 |
41 void SetUpCommandLine(base::CommandLine* command_line) override { | 49 void SetUpCommandLine(base::CommandLine* command_line) override { |
42 content::IsolateAllSitesForTesting(command_line); | 50 content::IsolateAllSitesForTesting(command_line); |
43 } | 51 } |
44 | 52 |
45 void SetUpOnMainThread() override { | 53 void SetUpOnMainThread() override { |
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
501 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" | 509 "document.querySelector('iframe').src = '" + frame_url.spec() + "';\n" |
502 "var w = window.open('about:blank');\n" | 510 "var w = window.open('about:blank');\n" |
503 "window.domAutomationController.send(!!w);\n", | 511 "window.domAutomationController.send(!!w);\n", |
504 &popup_handle_is_valid)); | 512 &popup_handle_is_valid)); |
505 popup_observer.Wait(); | 513 popup_observer.Wait(); |
506 | 514 |
507 // The popup shouldn't be blocked. | 515 // The popup shouldn't be blocked. |
508 EXPECT_TRUE(popup_handle_is_valid); | 516 EXPECT_TRUE(popup_handle_is_valid); |
509 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 517 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
510 } | 518 } |
| 519 |
| 520 #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 521 // Class to sniff incoming IPCs for spell check messages. |
| 522 class TestSpellCheckMessageFilter : public content::BrowserMessageFilter { |
| 523 public: |
| 524 explicit TestSpellCheckMessageFilter(content::RenderProcessHost* process_host) |
| 525 : content::BrowserMessageFilter(SpellCheckMsgStart), |
| 526 process_host_(process_host), |
| 527 text_received_(false), |
| 528 message_loop_runner_(base::MakeShared<content::MessageLoopRunner>()) {} |
| 529 |
| 530 bool OnMessageReceived(const IPC::Message& message) override { |
| 531 IPC_BEGIN_MESSAGE_MAP(TestSpellCheckMessageFilter, message) |
| 532 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 533 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_CallSpellingService, HandleMessage) |
| 534 #else |
| 535 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestTextCheck, HandleMessage) |
| 536 #endif |
| 537 IPC_END_MESSAGE_MAP() |
| 538 return false; |
| 539 } |
| 540 |
| 541 base::string16 last_text() const { return last_text_; } |
| 542 |
| 543 void Wait() { |
| 544 if (!text_received_) |
| 545 message_loop_runner_->Run(); |
| 546 } |
| 547 |
| 548 content::RenderProcessHost* process() const { return process_host_; } |
| 549 |
| 550 private: |
| 551 ~TestSpellCheckMessageFilter() override {} |
| 552 |
| 553 void HandleMessage(int, int, const base::string16& text) { |
| 554 content::BrowserThread::PostTask( |
| 555 content::BrowserThread::UI, FROM_HERE, |
| 556 base::Bind(&TestSpellCheckMessageFilter::HandleMessageOnUI, this, |
| 557 text)); |
| 558 } |
| 559 |
| 560 void HandleMessageOnUI(const base::string16& text) { |
| 561 last_text_ = text; |
| 562 if (!text_received_) { |
| 563 text_received_ = true; |
| 564 message_loop_runner_->Quit(); |
| 565 } |
| 566 } |
| 567 |
| 568 content::RenderProcessHost* process_host_; |
| 569 bool text_received_; |
| 570 base::string16 last_text_; |
| 571 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 572 |
| 573 DISALLOW_COPY_AND_ASSIGN(TestSpellCheckMessageFilter); |
| 574 }; |
| 575 |
| 576 class TestBrowserClientForSpellCheck : public ChromeContentBrowserClient { |
| 577 public: |
| 578 TestBrowserClientForSpellCheck() {} |
| 579 ~TestBrowserClientForSpellCheck() override {} |
| 580 |
| 581 // ContentBrowserClient overrides. |
| 582 void RenderProcessWillLaunch( |
| 583 content::RenderProcessHost* process_host) override { |
| 584 filters_.push_back(new TestSpellCheckMessageFilter(process_host)); |
| 585 process_host->AddFilter(filters_.back().get()); |
| 586 ChromeContentBrowserClient::RenderProcessWillLaunch(process_host); |
| 587 } |
| 588 |
| 589 // Retrieves the registered filter for the given RenderProcessHost. It will |
| 590 // return nullptr if the RenderProcessHost was initialized while a different |
| 591 // instance of ContentBrowserClient was in action. |
| 592 scoped_refptr<TestSpellCheckMessageFilter> |
| 593 GetSpellCheckMessageFilterForProcess( |
| 594 content::RenderProcessHost* process_host) const { |
| 595 for (auto filter : filters_) { |
| 596 if (filter->process() == process_host) |
| 597 return filter; |
| 598 } |
| 599 return nullptr; |
| 600 } |
| 601 |
| 602 private: |
| 603 std::vector<scoped_refptr<TestSpellCheckMessageFilter>> filters_; |
| 604 |
| 605 DISALLOW_COPY_AND_ASSIGN(TestBrowserClientForSpellCheck); |
| 606 }; |
| 607 |
| 608 // Tests that spelling in out-of-process subframes is checked. |
| 609 // See crbug.com/638361 for details. |
| 610 IN_PROC_BROWSER_TEST_F(ChromeSitePerProcessTest, OOPIFSpellCheckTest) { |
| 611 TestBrowserClientForSpellCheck browser_client; |
| 612 content::ContentBrowserClient* old_browser_client = |
| 613 content::SetBrowserClientForTesting(&browser_client); |
| 614 |
| 615 GURL main_url(embedded_test_server()->GetURL( |
| 616 "a.com", "/page_with_contenteditable_in_cross_site_subframe.html")); |
| 617 ui_test_utils::NavigateToURL(browser(), main_url); |
| 618 |
| 619 content::WebContents* web_contents = |
| 620 browser()->tab_strip_model()->GetActiveWebContents(); |
| 621 content::RenderFrameHost* subframe = |
| 622 ChildFrameAt(web_contents->GetMainFrame(), 0); |
| 623 scoped_refptr<TestSpellCheckMessageFilter> filter = |
| 624 browser_client.GetSpellCheckMessageFilterForProcess( |
| 625 subframe->GetProcess()); |
| 626 filter->Wait(); |
| 627 |
| 628 EXPECT_EQ(base::ASCIIToUTF16("zz."), filter->last_text()); |
| 629 |
| 630 content::SetBrowserClientForTesting(old_browser_client); |
| 631 } |
| 632 #endif // BUILDFLAG(ENABLE_SPELLCHECK) |
OLD | NEW |