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

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: Fix file name in chrome_renderer.gypi Created 7 years, 9 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
« no previous file with comments | « no previous file | chrome/chrome_renderer.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 // This test ensures that closing app window on 'loadcommit' does not crash. 714 // This test ensures that closing app window on 'loadcommit' does not crash.
680 // The test launches an app with guest and closes the window on loadcommit. It 715 // The test launches an app with guest and closes the window on loadcommit. It
681 // then launches the app window again. The process is repeated 3 times. 716 // then launches the app window again. The process is repeated 3 times.
682 IN_PROC_BROWSER_TEST_F(WebViewTest, CloseOnLoadcommit) { 717 IN_PROC_BROWSER_TEST_F(WebViewTest, CloseOnLoadcommit) {
683 ExtensionTestMessageListener done_test_listener( 718 ExtensionTestMessageListener done_test_listener(
684 "done-close-on-loadcommit", false); 719 "done-close-on-loadcommit", false);
685 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit"); 720 LoadAndLaunchPlatformApp("web_view/close_on_loadcommit");
686 ASSERT_TRUE(done_test_listener.WaitUntilSatisfied()); 721 ASSERT_TRUE(done_test_listener.WaitUntilSatisfied());
687 } 722 }
688 723
724 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny) {
725 ASSERT_TRUE(StartTestServer()); // For serving guest pages.
726 ASSERT_TRUE(RunPlatformAppTest(
727 "platform_apps/web_view/media_access/deny")) << message_;
728 }
729
730 IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow) {
731 ASSERT_TRUE(StartTestServer()); // For serving guest pages.
732 ExtensionTestMessageListener launched_listener("Launched", false);
733 LoadAndLaunchPlatformApp("web_view/media_access/allow");
734 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
735
736 content::WebContents* embedder_web_contents =
737 GetFirstShellWindowWebContents();
738 ASSERT_TRUE(embedder_web_contents);
739 MockWebContentsDelegate* mock = new MockWebContentsDelegate;
740 embedder_web_contents->SetDelegate(mock);
741
742 const size_t num_tests = 4;
743 std::string test_names[num_tests] = {
744 "testAllow",
745 "testAllowAndThenDeny",
746 "testAllowTwice",
747 "testAllowAsync",
748 };
749 for (size_t i = 0; i < num_tests; ++i) {
750 ExtensionTestMessageListener done_listener("DoneMediaTest", false);
751 EXPECT_TRUE(
752 content::ExecuteScript(
753 embedder_web_contents,
754 base::StringPrintf("startAllowTest('%s')",
755 test_names[i].c_str())));
756 done_listener.WaitUntilSatisfied();
757
758 std::string result;
759 EXPECT_TRUE(
760 content::ExecuteScriptAndExtractString(
761 embedder_web_contents,
762 "window.domAutomationController.send(getTestStatus())", &result));
763 ASSERT_EQ(std::string("PASSED"), result);
764
765 mock->WaitForSetMediaPermission();
766 }
767 }
768
689 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) { 769 IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) {
690 ASSERT_TRUE(StartTestServer()); 770 ASSERT_TRUE(StartTestServer());
691 std::string host_str("localhost"); // Must stay in scope with replace_host. 771 std::string host_str("localhost"); // Must stay in scope with replace_host.
692 GURL::Replacements replace_host; 772 GURL::Replacements replace_host;
693 replace_host.SetHostStr(host_str); 773 replace_host.SetHostStr(host_str);
694 774
695 GURL guest_url = test_server()->GetURL( 775 GURL guest_url = test_server()->GetURL(
696 "files/extensions/platform_apps/web_view/speech/guest.html"); 776 "files/extensions/platform_apps/web_view/speech/guest.html");
697 guest_url = guest_url.ReplaceComponents(replace_host); 777 guest_url = guest_url.ReplaceComponents(replace_host);
698 778
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 window = CreateShellWindow(extension); 810 window = CreateShellWindow(extension);
731 else 811 else
732 window = GetFirstShellWindow(); 812 window = GetFirstShellWindow();
733 CloseShellWindow(window); 813 CloseShellWindow(window);
734 814
735 // Load the app again. 815 // Load the app again.
736 ExtensionTestMessageListener second_loaded_listener("guest-loaded", false); 816 ExtensionTestMessageListener second_loaded_listener("guest-loaded", false);
737 LoadAndLaunchPlatformApp("web_view/teardown"); 817 LoadAndLaunchPlatformApp("web_view/teardown");
738 ASSERT_TRUE(second_loaded_listener.WaitUntilSatisfied()); 818 ASSERT_TRUE(second_loaded_listener.WaitUntilSatisfied());
739 } 819 }
OLDNEW
« no previous file with comments | « no previous file | chrome/chrome_renderer.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698