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" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
32 #include "content/public/test/content_browser_test_utils.h" | 32 #include "content/public/test/content_browser_test_utils.h" |
33 #include "content/public/test/test_utils.h" | 33 #include "content/public/test/test_utils.h" |
34 #include "extensions/browser/api/extensions_api_client.h" | 34 #include "extensions/browser/api/extensions_api_client.h" |
35 #include "net/dns/mock_host_resolver.h" | 35 #include "net/dns/mock_host_resolver.h" |
36 #include "net/test/embedded_test_server/embedded_test_server.h" | 36 #include "net/test/embedded_test_server/embedded_test_server.h" |
37 #include "ui/display/display_switches.h" | 37 #include "ui/display/display_switches.h" |
38 #include "url/gurl.h" | 38 #include "url/gurl.h" |
39 | 39 |
40 #if BUILDFLAG(ENABLE_SPELLCHECK) | 40 #if BUILDFLAG(ENABLE_SPELLCHECK) |
| 41 #include "components/spellcheck/common/spellcheck.mojom.h" |
41 #include "components/spellcheck/common/spellcheck_messages.h" | 42 #include "components/spellcheck/common/spellcheck_messages.h" |
| 43 #include "services/service_manager/public/cpp/bind_source_info.h" |
42 #endif | 44 #endif |
43 | 45 |
44 class ChromeSitePerProcessTest : public InProcessBrowserTest { | 46 class ChromeSitePerProcessTest : public InProcessBrowserTest { |
45 public: | 47 public: |
46 ChromeSitePerProcessTest() {} | 48 ChromeSitePerProcessTest() {} |
47 ~ChromeSitePerProcessTest() override {} | 49 ~ChromeSitePerProcessTest() override {} |
48 | 50 |
49 void SetUpCommandLine(base::CommandLine* command_line) override { | 51 void SetUpCommandLine(base::CommandLine* command_line) override { |
50 content::IsolateAllSitesForTesting(command_line); | 52 content::IsolateAllSitesForTesting(command_line); |
51 } | 53 } |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 "window.domAutomationController.send(!!w);\n", | 513 "window.domAutomationController.send(!!w);\n", |
512 &popup_handle_is_valid)); | 514 &popup_handle_is_valid)); |
513 popup_observer.Wait(); | 515 popup_observer.Wait(); |
514 | 516 |
515 // The popup shouldn't be blocked. | 517 // The popup shouldn't be blocked. |
516 EXPECT_TRUE(popup_handle_is_valid); | 518 EXPECT_TRUE(popup_handle_is_valid); |
517 ASSERT_EQ(2, browser()->tab_strip_model()->count()); | 519 ASSERT_EQ(2, browser()->tab_strip_model()->count()); |
518 } | 520 } |
519 | 521 |
520 #if BUILDFLAG(ENABLE_SPELLCHECK) | 522 #if BUILDFLAG(ENABLE_SPELLCHECK) |
521 // Class to sniff incoming IPCs for spell check messages. | 523 // Class to sniff incoming spellcheck IPC / Mojo SpellCheckHost messages. |
522 class TestSpellCheckMessageFilter : public content::BrowserMessageFilter { | 524 class TestSpellCheckMessageFilter : public content::BrowserMessageFilter, |
| 525 spellcheck::mojom::SpellCheckHost { |
523 public: | 526 public: |
524 explicit TestSpellCheckMessageFilter(content::RenderProcessHost* process_host) | 527 explicit TestSpellCheckMessageFilter(content::RenderProcessHost* process_host) |
525 : content::BrowserMessageFilter(SpellCheckMsgStart), | 528 : content::BrowserMessageFilter(SpellCheckMsgStart), |
526 process_host_(process_host), | 529 process_host_(process_host), |
527 text_received_(false), | 530 text_received_(false), |
528 message_loop_runner_(base::MakeShared<content::MessageLoopRunner>()) {} | 531 message_loop_runner_(base::MakeShared<content::MessageLoopRunner>()), |
| 532 binding_(this) {} |
529 | 533 |
530 bool OnMessageReceived(const IPC::Message& message) override { | 534 content::RenderProcessHost* process() const { return process_host_; } |
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 | 535 |
541 base::string16 last_text() const { return last_text_; } | 536 const base::string16& text() const { return text_; } |
542 | 537 |
543 void Wait() { | 538 void Wait() { |
544 if (!text_received_) | 539 if (!text_received_) |
545 message_loop_runner_->Run(); | 540 message_loop_runner_->Run(); |
546 } | 541 } |
547 | 542 |
548 content::RenderProcessHost* process() const { return process_host_; } | 543 bool OnMessageReceived(const IPC::Message& message) override { |
| 544 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 545 IPC_BEGIN_MESSAGE_MAP(TestSpellCheckMessageFilter, message) |
| 546 // TODO(crbug.com/714480): convert the RequestTextCheck IPC to mojo. |
| 547 IPC_MESSAGE_HANDLER(SpellCheckHostMsg_RequestTextCheck, HandleMessage) |
| 548 IPC_END_MESSAGE_MAP() |
| 549 #endif |
| 550 return false; |
| 551 } |
| 552 |
| 553 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 554 void ShellCheckHostRequest(const service_manager::BindSourceInfo& source_info, |
| 555 spellcheck::mojom::SpellCheckHostRequest request) { |
| 556 EXPECT_FALSE(binding_.is_bound()); |
| 557 binding_.Bind(std::move(request)); |
| 558 } |
| 559 #endif |
549 | 560 |
550 private: | 561 private: |
551 ~TestSpellCheckMessageFilter() override {} | 562 ~TestSpellCheckMessageFilter() override {} |
552 | 563 |
| 564 #if BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
553 void HandleMessage(int, int, const base::string16& text) { | 565 void HandleMessage(int, int, const base::string16& text) { |
554 content::BrowserThread::PostTask( | 566 content::BrowserThread::PostTask( |
555 content::BrowserThread::UI, FROM_HERE, | 567 content::BrowserThread::UI, FROM_HERE, |
556 base::BindOnce(&TestSpellCheckMessageFilter::HandleMessageOnUI, this, | 568 base::BindOnce(&TestSpellCheckMessageFilter::HandleMessageOnUIThread, |
557 text)); | 569 this, text)); |
| 570 } |
| 571 #endif |
| 572 |
| 573 void HandleMessageOnUIThread(const base::string16& text) { |
| 574 if (!text_received_) { |
| 575 text_received_ = true; |
| 576 text_ = text; |
| 577 message_loop_runner_->Quit(); |
| 578 } else { |
| 579 NOTREACHED(); |
| 580 } |
558 } | 581 } |
559 | 582 |
560 void HandleMessageOnUI(const base::string16& text) { | 583 // spellcheck::mojom::SpellCheckHost: |
561 last_text_ = text; | 584 void RequestDictionary() override {} |
562 if (!text_received_) { | 585 |
563 text_received_ = true; | 586 void NotifyChecked(const base::string16& word, bool misspelled) override {} |
564 message_loop_runner_->Quit(); | 587 |
565 } | 588 void CallSpellingService( |
| 589 const base::string16& text, |
| 590 const CallSpellingServiceCallback& callback) override { |
| 591 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 592 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 593 callback.Run(true, std::vector<SpellCheckResult>()); |
| 594 binding_.Close(); |
| 595 HandleMessageOnUIThread(text); |
| 596 #endif |
566 } | 597 } |
567 | 598 |
568 content::RenderProcessHost* process_host_; | 599 content::RenderProcessHost* process_host_; |
569 bool text_received_; | 600 bool text_received_; |
570 base::string16 last_text_; | 601 base::string16 text_; |
571 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 602 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 603 mojo::Binding<spellcheck::mojom::SpellCheckHost> binding_; |
572 | 604 |
573 DISALLOW_COPY_AND_ASSIGN(TestSpellCheckMessageFilter); | 605 DISALLOW_COPY_AND_ASSIGN(TestSpellCheckMessageFilter); |
574 }; | 606 }; |
575 | 607 |
576 class TestBrowserClientForSpellCheck : public ChromeContentBrowserClient { | 608 class TestBrowserClientForSpellCheck : public ChromeContentBrowserClient { |
577 public: | 609 public: |
578 TestBrowserClientForSpellCheck() {} | 610 TestBrowserClientForSpellCheck() {} |
579 ~TestBrowserClientForSpellCheck() override {} | 611 ~TestBrowserClientForSpellCheck() override {} |
580 | 612 |
581 // ContentBrowserClient overrides. | 613 // ContentBrowserClient overrides. |
582 void RenderProcessWillLaunch( | 614 void RenderProcessWillLaunch( |
583 content::RenderProcessHost* process_host) override { | 615 content::RenderProcessHost* process_host) override { |
584 filters_.push_back(new TestSpellCheckMessageFilter(process_host)); | 616 filters_.push_back(new TestSpellCheckMessageFilter(process_host)); |
585 process_host->AddFilter(filters_.back().get()); | 617 process_host->AddFilter(filters_.back().get()); |
586 ChromeContentBrowserClient::RenderProcessWillLaunch(process_host); | 618 ChromeContentBrowserClient::RenderProcessWillLaunch(process_host); |
587 } | 619 } |
588 | 620 |
| 621 #if !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 622 void ExposeInterfacesToRenderer( |
| 623 service_manager::BinderRegistry* registry, |
| 624 content::AssociatedInterfaceRegistry* associated_registry, |
| 625 content::RenderProcessHost* render_process_host) override { |
| 626 // Expose the default interfaces. |
| 627 ChromeContentBrowserClient::ExposeInterfacesToRenderer( |
| 628 registry, associated_registry, render_process_host); |
| 629 |
| 630 scoped_refptr<TestSpellCheckMessageFilter> filter = |
| 631 GetSpellCheckMessageFilterForProcess(render_process_host); |
| 632 CHECK(filter); |
| 633 |
| 634 // Override the default SpellCheckHost interface. |
| 635 auto ui_task_runner = content::BrowserThread::GetTaskRunnerForThread( |
| 636 content::BrowserThread::UI); |
| 637 registry->AddInterface( |
| 638 base::Bind(&TestSpellCheckMessageFilter::ShellCheckHostRequest, filter), |
| 639 ui_task_runner); |
| 640 } |
| 641 #endif // !BUILDFLAG(USE_BROWSER_SPELLCHECKER) |
| 642 |
589 // Retrieves the registered filter for the given RenderProcessHost. It will | 643 // Retrieves the registered filter for the given RenderProcessHost. It will |
590 // return nullptr if the RenderProcessHost was initialized while a different | 644 // return nullptr if the RenderProcessHost was initialized while a different |
591 // instance of ContentBrowserClient was in action. | 645 // instance of ContentBrowserClient was in action. |
592 scoped_refptr<TestSpellCheckMessageFilter> | 646 scoped_refptr<TestSpellCheckMessageFilter> |
593 GetSpellCheckMessageFilterForProcess( | 647 GetSpellCheckMessageFilterForProcess( |
594 content::RenderProcessHost* process_host) const { | 648 content::RenderProcessHost* process_host) const { |
595 for (auto filter : filters_) { | 649 for (auto filter : filters_) { |
596 if (filter->process() == process_host) | 650 if (filter->process() == process_host) |
597 return filter; | 651 return filter; |
598 } | 652 } |
(...skipping 12 matching lines...) Expand all Loading... |
611 TestBrowserClientForSpellCheck browser_client; | 665 TestBrowserClientForSpellCheck browser_client; |
612 content::ContentBrowserClient* old_browser_client = | 666 content::ContentBrowserClient* old_browser_client = |
613 content::SetBrowserClientForTesting(&browser_client); | 667 content::SetBrowserClientForTesting(&browser_client); |
614 | 668 |
615 GURL main_url(embedded_test_server()->GetURL( | 669 GURL main_url(embedded_test_server()->GetURL( |
616 "a.com", "/page_with_contenteditable_in_cross_site_subframe.html")); | 670 "a.com", "/page_with_contenteditable_in_cross_site_subframe.html")); |
617 ui_test_utils::NavigateToURL(browser(), main_url); | 671 ui_test_utils::NavigateToURL(browser(), main_url); |
618 | 672 |
619 content::WebContents* web_contents = | 673 content::WebContents* web_contents = |
620 browser()->tab_strip_model()->GetActiveWebContents(); | 674 browser()->tab_strip_model()->GetActiveWebContents(); |
621 content::RenderFrameHost* subframe = | 675 content::RenderFrameHost* cross_site_subframe = |
622 ChildFrameAt(web_contents->GetMainFrame(), 0); | 676 ChildFrameAt(web_contents->GetMainFrame(), 0); |
| 677 |
623 scoped_refptr<TestSpellCheckMessageFilter> filter = | 678 scoped_refptr<TestSpellCheckMessageFilter> filter = |
624 browser_client.GetSpellCheckMessageFilterForProcess( | 679 browser_client.GetSpellCheckMessageFilterForProcess( |
625 subframe->GetProcess()); | 680 cross_site_subframe->GetProcess()); |
626 filter->Wait(); | 681 filter->Wait(); |
627 | 682 |
628 EXPECT_EQ(base::ASCIIToUTF16("zz."), filter->last_text()); | 683 EXPECT_EQ(base::ASCIIToUTF16("zz."), filter->text()); |
629 | 684 |
630 content::SetBrowserClientForTesting(old_browser_client); | 685 content::SetBrowserClientForTesting(old_browser_client); |
631 } | 686 } |
632 #endif // BUILDFLAG(ENABLE_SPELLCHECK) | 687 #endif // BUILDFLAG(ENABLE_SPELLCHECK) |
OLD | NEW |