Chromium Code Reviews| 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" |
| 14 #include "chrome/common/chrome_switches.h" | |
| 13 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 14 #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" | |
| 15 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 16 #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" | |
| 17 #include "content/public/test/browser_test_utils.h" | 21 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/public/test/fake_speech_recognition_manager.h" | 22 #include "content/public/test/fake_speech_recognition_manager.h" |
| 19 #include "ui/compositor/compositor_setup.h" | 23 #include "ui/compositor/compositor_setup.h" |
| 20 #include "ui/gl/gl_switches.h" | 24 #include "ui/gl/gl_switches.h" |
| 21 | 25 |
| 22 using prerender::PrerenderLinkManager; | 26 using prerender::PrerenderLinkManager; |
| 23 using prerender::PrerenderLinkManagerFactory; | 27 using prerender::PrerenderLinkManagerFactory; |
| 24 | 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 | |
|
Charlie Reis
2013/02/13 21:08:05
nit: semicolon. :)
lazyboy
2013/02/13 22:17:34
Done.
| |
| 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 | |
| 25 class WebViewTest : public extensions::PlatformAppBrowserTest { | 61 class WebViewTest : public extensions::PlatformAppBrowserTest { |
| 26 protected: | 62 protected: |
| 27 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 63 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 28 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 64 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 29 #if !defined(OS_MACOSX) | 65 #if !defined(OS_MACOSX) |
| 30 CHECK(test_launcher_utils::OverrideGLImplementation( | 66 CHECK(test_launcher_utils::OverrideGLImplementation( |
| 31 command_line, gfx::kGLImplementationOSMesaName)) << | 67 command_line, gfx::kGLImplementationOSMesaName)) << |
| 32 "kUseGL must not be set by test framework code!"; | 68 "kUseGL must not be set by test framework code!"; |
| 33 #endif | 69 #endif |
| 70 const testing::TestInfo* const test_info = | |
| 71 testing::UnitTest::GetInstance()->current_test_info(); | |
| 72 bool requires_experimental = | |
| 73 !strcmp(test_info->name(), "MediaAccessAPIAllow") || | |
| 74 !strcmp(test_info->name(), "MediaAccessAPIDeny"); | |
| 75 if (requires_experimental) { | |
| 76 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 77 switches::kEnableExperimentalExtensionApis); | |
| 78 } | |
| 34 } | 79 } |
| 35 | 80 |
| 36 virtual void SetUp() OVERRIDE { | 81 virtual void SetUp() OVERRIDE { |
| 37 const testing::TestInfo* const test_info = | 82 const testing::TestInfo* const test_info = |
| 38 testing::UnitTest::GetInstance()->current_test_info(); | 83 testing::UnitTest::GetInstance()->current_test_info(); |
| 39 | 84 |
| 40 // SpeechRecognition test specific SetUp. | 85 // SpeechRecognition test specific SetUp. |
| 41 if (!strcmp(test_info->name(), "SpeechRecognition")) { | 86 if (!strcmp(test_info->name(), "SpeechRecognition")) { |
| 42 fake_speech_recognition_manager_.reset( | 87 fake_speech_recognition_manager_.reset( |
| 43 new content::FakeSpeechRecognitionManager()); | 88 new content::FakeSpeechRecognitionManager()); |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 " if (e.target.result.version == 1)" | 707 " if (e.target.result.version == 1)" |
| 663 " document.title = 'db not found';" | 708 " document.title = 'db not found';" |
| 664 " else " | 709 " else " |
| 665 " document.title = 'error';" | 710 " document.title = 'error';" |
| 666 "}"; | 711 "}"; |
| 667 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0), | 712 ExecuteScriptWaitForTitle(browser()->tab_strip_model()->GetWebContentsAt(0), |
| 668 script, "db not found"); | 713 script, "db not found"); |
| 669 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); | 714 ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found"); |
| 670 } | 715 } |
| 671 | 716 |
| 717 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny) { | |
| 718 ASSERT_TRUE(StartTestServer()); // For serving guest pages. | |
| 719 ASSERT_TRUE(RunPlatformAppTest( | |
| 720 "platform_apps/web_view/media_access/deny")) << message_; | |
| 721 } | |
| 722 | |
| 723 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow) { | |
| 724 ASSERT_TRUE(StartTestServer()); // For serving guest pages. | |
| 725 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 726 LoadAndLaunchPlatformApp("web_view/media_access/allow"); | |
| 727 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 728 | |
| 729 content::WebContents* embedder_web_contents = | |
| 730 GetFirstShellWindowWebContents(); | |
| 731 ASSERT_TRUE(embedder_web_contents != NULL); | |
|
Charlie Reis
2013/02/13 21:08:05
nit: Don't need the != NULL.
lazyboy
2013/02/13 22:17:34
Done.
| |
| 732 MockWebContentsDelegate* mock = new MockWebContentsDelegate; | |
| 733 embedder_web_contents->SetDelegate(mock); | |
| 734 | |
| 735 const size_t num_tests = 4; | |
| 736 std::string test_names[num_tests] = { | |
| 737 "testAllow", | |
| 738 "testAllowAndThenDeny", | |
| 739 "testAllowTwice", | |
| 740 "testAllowAsync", | |
| 741 }; | |
| 742 for (size_t i = 0; i < num_tests; ++i) { | |
| 743 ExtensionTestMessageListener done_listener("DoneMediaTest", false); | |
| 744 EXPECT_TRUE( | |
| 745 content::ExecuteScript( | |
| 746 embedder_web_contents, | |
| 747 base::StringPrintf("startAllowTest('%s')", | |
| 748 test_names[i].c_str()))); | |
| 749 done_listener.WaitUntilSatisfied(); | |
| 750 | |
| 751 std::string result; | |
| 752 EXPECT_TRUE( | |
| 753 content::ExecuteScriptAndExtractString( | |
| 754 embedder_web_contents, | |
| 755 "window.domAutomationController.send(getTestStatus())", &result)); | |
| 756 ASSERT_EQ(std::string("PASSED"), result); | |
| 757 | |
| 758 mock->WaitForSetMediaPermission(); | |
| 759 } | |
| 760 } | |
| 761 | |
| 672 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) { | 762 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) { |
| 673 ASSERT_TRUE(StartTestServer()); | 763 ASSERT_TRUE(StartTestServer()); |
| 674 std::string host_str("localhost"); // Must stay in scope with replace_host. | 764 std::string host_str("localhost"); // Must stay in scope with replace_host. |
| 675 GURL::Replacements replace_host; | 765 GURL::Replacements replace_host; |
| 676 replace_host.SetHostStr(host_str); | 766 replace_host.SetHostStr(host_str); |
| 677 | 767 |
| 678 GURL guest_url = test_server()->GetURL( | 768 GURL guest_url = test_server()->GetURL( |
| 679 "files/extensions/platform_apps/web_view/speech/guest.html"); | 769 "files/extensions/platform_apps/web_view/speech/guest.html"); |
| 680 guest_url = guest_url.ReplaceComponents(replace_host); | 770 guest_url = guest_url.ReplaceComponents(replace_host); |
| 681 | 771 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 695 // Click on the guest (center of the WebContents), the guest is rendered in a | 785 // 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. | 786 // way that this will trigger clicking on speech recognition input mic. |
| 697 SimulateMouseClick(guest_web_contents, 0, WebKit::WebMouseEvent::ButtonLeft); | 787 SimulateMouseClick(guest_web_contents, 0, WebKit::WebMouseEvent::ButtonLeft); |
| 698 | 788 |
| 699 string16 expected_title(ASCIIToUTF16("PASSED")); | 789 string16 expected_title(ASCIIToUTF16("PASSED")); |
| 700 string16 error_title(ASCIIToUTF16("FAILED")); | 790 string16 error_title(ASCIIToUTF16("FAILED")); |
| 701 content::TitleWatcher title_watcher(guest_web_contents, expected_title); | 791 content::TitleWatcher title_watcher(guest_web_contents, expected_title); |
| 702 title_watcher.AlsoWaitForTitle(error_title); | 792 title_watcher.AlsoWaitForTitle(error_title); |
| 703 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 793 EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 704 } | 794 } |
| 795 | |
|
Charlie Reis
2013/02/13 21:08:05
nit: Extra line.
lazyboy
2013/02/13 22:17:34
Removed.
| |
| OLD | NEW |