| 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/stringprintf.h" |
| 5 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/browser/automation/automation_util.h" | 7 #include "chrome/browser/automation/automation_util.h" |
| 7 #include "chrome/browser/extensions/extension_test_message_listener.h" | 8 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 8 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 9 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 9 #include "chrome/browser/prerender/prerender_link_manager.h" | 10 #include "chrome/browser/prerender/prerender_link_manager.h" |
| 10 #include "chrome/browser/prerender/prerender_link_manager_factory.h" | 11 #include "chrome/browser/prerender/prerender_link_manager_factory.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "chrome/test/base/test_launcher_utils.h" | 16 #include "chrome/test/base/test_launcher_utils.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "content/public/browser/web_contents_delegate.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
| 19 #include "content/public/test/fake_speech_recognition_manager.h" | 22 #include "content/public/test/fake_speech_recognition_manager.h" |
| 20 #include "ui/compositor/compositor_setup.h" | 23 #include "ui/compositor/compositor_setup.h" |
| 21 #include "ui/gl/gl_switches.h" | 24 #include "ui/gl/gl_switches.h" |
| 22 | 25 |
| 23 using prerender::PrerenderLinkManager; | 26 using prerender::PrerenderLinkManager; |
| 24 using prerender::PrerenderLinkManagerFactory; | 27 using prerender::PrerenderLinkManagerFactory; |
| 25 | 28 |
| 29 // This class intercepts media access request from the embedder. The request |
| 30 // should be triggered only if the embedder API (from tests) allows the request |
| 31 // in Javascript. |
| 32 // We do not issue the actual media request; the fact that the request reached |
| 33 // embedder's WebContents is good enough for our tests. This is also to make |
| 34 // the test run successfully on trybots. |
| 35 class MockWebContentsDelegate : public content::WebContentsDelegate { |
| 36 public: |
| 37 MockWebContentsDelegate() : requested_(false) {} |
| 38 virtual ~MockWebContentsDelegate() {} |
| 39 |
| 40 virtual void RequestMediaAccessPermission( |
| 41 content::WebContents* web_contents, |
| 42 const content::MediaStreamRequest& request, |
| 43 const content::MediaResponseCallback& callback) OVERRIDE { |
| 44 requested_ = true; |
| 45 if (message_loop_runner_) |
| 46 message_loop_runner_->Quit(); |
| 47 } |
| 48 |
| 49 void WaitForSetMediaPermission() { |
| 50 if (requested_) |
| 51 return; |
| 52 message_loop_runner_ = new content::MessageLoopRunner; |
| 53 message_loop_runner_->Run(); |
| 54 } |
| 55 |
| 56 private: |
| 57 bool requested_; |
| 58 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 59 }; |
| 60 |
| 26 class WebViewTest : public extensions::PlatformAppBrowserTest { | 61 class WebViewTest : public extensions::PlatformAppBrowserTest { |
| 27 protected: | 62 protected: |
| 28 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 63 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 29 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 64 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 30 #if !defined(OS_MACOSX) | 65 #if !defined(OS_MACOSX) |
| 31 CHECK(test_launcher_utils::OverrideGLImplementation( | 66 CHECK(test_launcher_utils::OverrideGLImplementation( |
| 32 command_line, gfx::kGLImplementationOSMesaName)) << | 67 command_line, gfx::kGLImplementationOSMesaName)) << |
| 33 "kUseGL must not be set by test framework code!"; | 68 "kUseGL must not be set by test framework code!"; |
| 34 #endif | 69 #endif |
| 35 } | 70 } |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 " if (e.target.result.version == 1)" | 704 " if (e.target.result.version == 1)" |
| 670 " document.title = 'db not found';" | 705 " document.title = 'db not found';" |
| 671 " else " | 706 " else " |
| 672 " document.title = 'error';" | 707 " document.title = 'error';" |
| 673 "}"; | 708 "}"; |
| 674 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0), | 709 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0), |
| 675 script, "db not found"); | 710 script, "db not found"); |
| 676 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); | 711 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); |
| 677 } | 712 } |
| 678 | 713 |
| 714 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny) { |
| 715 ASSERT_TRUE(StartTestServer()); // For serving guest pages. |
| 716 ASSERT_TRUE(RunPlatformAppTest( |
| 717 "platform_apps/web_view/media_access/deny")) << message_; |
| 718 } |
| 719 |
| 720 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow) { |
| 721 ASSERT_TRUE(StartTestServer()); // For serving guest pages. |
| 722 ExtensionTestMessageListener launched_listener("Launched", false); |
| 723 LoadAndLaunchPlatformApp("web_view/media_access/allow"); |
| 724 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 725 |
| 726 content::WebContents* embedder_web_contents = |
| 727 GetFirstShellWindowWebContents(); |
| 728 ASSERT_TRUE(embedder_web_contents); |
| 729 MockWebContentsDelegate* mock = new MockWebContentsDelegate; |
| 730 embedder_web_contents->SetDelegate(mock); |
| 731 |
| 732 const size_t num_tests = 4; |
| 733 std::string test_names[num_tests] = { |
| 734 "testAllow", |
| 735 "testAllowAndThenDeny", |
| 736 "testAllowTwice", |
| 737 "testAllowAsync", |
| 738 }; |
| 739 for (size_t i = 0; i < num_tests; ++i) { |
| 740 ExtensionTestMessageListener done_listener("DoneMediaTest", false); |
| 741 EXPECT_TRUE( |
| 742 content::ExecuteScript( |
| 743 embedder_web_contents, |
| 744 base::StringPrintf("startAllowTest('%s')", |
| 745 test_names[i].c_str()))); |
| 746 done_listener.WaitUntilSatisfied(); |
| 747 |
| 748 std::string result; |
| 749 EXPECT_TRUE( |
| 750 content::ExecuteScriptAndExtractString( |
| 751 embedder_web_contents, |
| 752 "window.domAutomationController.send(getTestStatus())", &result)); |
| 753 ASSERT_EQ(std::string("PASSED"), result); |
| 754 |
| 755 mock->WaitForSetMediaPermission(); |
| 756 } |
| 757 } |
| 758 |
| 679 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) { | 759 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) { |
| 680 ASSERT_TRUE(StartTestServer()); | 760 ASSERT_TRUE(StartTestServer()); |
| 681 std::string host_str("localhost"); // Must stay in scope with replace_host. | 761 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 682 GURL::Replacements replace_host; | 762 GURL::Replacements replace_host; |
| 683 replace_host.SetHostStr(host_str); | 763 replace_host.SetHostStr(host_str); |
| 684 | 764 |
| 685 GURL guest_url = test_server()->GetURL( | 765 GURL guest_url = test_server()->GetURL( |
| 686 "files/extensions/platform_apps/web_view/speech/guest.html"); | 766 "files/extensions/platform_apps/web_view/speech/guest.html"); |
| 687 guest_url = guest_url.ReplaceComponents(replace_host); | 767 guest_url = guest_url.ReplaceComponents(replace_host); |
| 688 | 768 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 702 // Click on the guest (center of the WebContents), the guest is rendered in a | 782 // Click on the guest (center of the WebContents), the guest is rendered in a |
| 703 // way that this will trigger clicking on speech recognition input mic. | 783 // way that this will trigger clicking on speech recognition input mic. |
| 704 SimulateMouseClick(guest_web_contents, 0, WebKit::WebMouseEvent::ButtonLeft); | 784 SimulateMouseClick(guest_web_contents, 0, WebKit::WebMouseEvent::ButtonLeft); |
| 705 | 785 |
| 706 string16 expected_title(ASCIIToUTF16("PASSED")); | 786 string16 expected_title(ASCIIToUTF16("PASSED")); |
| 707 string16 error_title(ASCIIToUTF16("FAILED")); | 787 string16 error_title(ASCIIToUTF16("FAILED")); |
| 708 content::TitleWatcher title_watcher(guest_web_contents, expected_title); | 788 content::TitleWatcher title_watcher(guest_web_contents, expected_title); |
| 709 title_watcher.AlsoWaitForTitle(error_title); | 789 title_watcher.AlsoWaitForTitle(error_title); |
| 710 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 790 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 711 } | 791 } |
| OLD | NEW |