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