Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1353)

Side by Side Diff: chrome/browser/extensions/web_view_browsertest.cc

Issue 11093080: <webview>: First stab at implementing media permission request for guests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments from abarth@, call map.erase asynchronously. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_renderer.gypi » ('j') | content/renderer/browser_plugin/browser_plugin.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698