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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/chrome_renderer.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/web_view_browsertest.cc
diff --git a/chrome/browser/extensions/web_view_browsertest.cc b/chrome/browser/extensions/web_view_browsertest.cc
index e09a7113d5593117e098a435f9a5c8a3595c792b..fb4e9000ffcbe6891d9f186a37f0eae90713d70b 100644
--- a/chrome/browser/extensions/web_view_browsertest.cc
+++ b/chrome/browser/extensions/web_view_browsertest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/automation/automation_util.h"
#include "chrome/browser/extensions/extension_test_message_listener.h"
@@ -13,8 +14,10 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chrome/test/base/test_launcher_utils.h"
+#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/web_contents_delegate.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/fake_speech_recognition_manager.h"
#include "ui/compositor/compositor_setup.h"
@@ -23,6 +26,38 @@
using prerender::PrerenderLinkManager;
using prerender::PrerenderLinkManagerFactory;
+// This class intercepts media access request from the embedder. The request
+// should be triggered only if the embedder API (from tests) allows the request
+// in Javascript.
+// We do not issue the actual media request; the fact that the request reached
+// embedder's WebContents is good enough for our tests. This is also to make
+// the test run successfully on trybots.
+class MockWebContentsDelegate : public content::WebContentsDelegate {
+ public:
+ MockWebContentsDelegate() : requested_(false) {}
+ virtual ~MockWebContentsDelegate() {}
+
+ virtual void RequestMediaAccessPermission(
+ content::WebContents* web_contents,
+ const content::MediaStreamRequest& request,
+ const content::MediaResponseCallback& callback) OVERRIDE {
+ requested_ = true;
+ if (message_loop_runner_)
+ message_loop_runner_->Quit();
+ }
+
+ void WaitForSetMediaPermission() {
+ if (requested_)
+ return;
+ message_loop_runner_ = new content::MessageLoopRunner;
+ message_loop_runner_->Run();
+ }
+
+ private:
+ bool requested_;
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+};
+
class WebViewTest : public extensions::PlatformAppBrowserTest {
protected:
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
@@ -686,6 +721,51 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, CloseOnLoadcommit) {
ASSERT_TRUE(done_test_listener.WaitUntilSatisfied());
}
+IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIDeny) {
+ ASSERT_TRUE(StartTestServer()); // For serving guest pages.
+ ASSERT_TRUE(RunPlatformAppTest(
+ "platform_apps/web_view/media_access/deny")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewTest, MediaAccessAPIAllow) {
+ ASSERT_TRUE(StartTestServer()); // For serving guest pages.
+ ExtensionTestMessageListener launched_listener("Launched", false);
+ LoadAndLaunchPlatformApp("web_view/media_access/allow");
+ ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
+
+ content::WebContents* embedder_web_contents =
+ GetFirstShellWindowWebContents();
+ ASSERT_TRUE(embedder_web_contents);
+ MockWebContentsDelegate* mock = new MockWebContentsDelegate;
+ embedder_web_contents->SetDelegate(mock);
+
+ const size_t num_tests = 4;
+ std::string test_names[num_tests] = {
+ "testAllow",
+ "testAllowAndThenDeny",
+ "testAllowTwice",
+ "testAllowAsync",
+ };
+ for (size_t i = 0; i < num_tests; ++i) {
+ ExtensionTestMessageListener done_listener("DoneMediaTest", false);
+ EXPECT_TRUE(
+ content::ExecuteScript(
+ embedder_web_contents,
+ base::StringPrintf("startAllowTest('%s')",
+ test_names[i].c_str())));
+ done_listener.WaitUntilSatisfied();
+
+ std::string result;
+ EXPECT_TRUE(
+ content::ExecuteScriptAndExtractString(
+ embedder_web_contents,
+ "window.domAutomationController.send(getTestStatus())", &result));
+ ASSERT_EQ(std::string("PASSED"), result);
+
+ mock->WaitForSetMediaPermission();
+ }
+}
+
IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) {
ASSERT_TRUE(StartTestServer());
std::string host_str("localhost"); // Must stay in scope with replace_host.
« 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