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

Unified Diff: extensions/browser/guest_view/web_view/web_view_media_access_apitest.cc

Issue 626093002: Cleanup webview app_shell_browsertests and add webview media permission tests in app_shell_browsert… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tests_load
Patch Set: Created 6 years, 2 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 | « extensions/browser/guest_view/web_view/web_view_apitest.cc ('k') | extensions/extensions.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/guest_view/web_view/web_view_media_access_apitest.cc
diff --git a/extensions/browser/guest_view/web_view/web_view_media_access_apitest.cc b/extensions/browser/guest_view/web_view/web_view_media_access_apitest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b2dfbc57557c2d98247f550c580623b51ebd269c
--- /dev/null
+++ b/extensions/browser/guest_view/web_view/web_view_media_access_apitest.cc
@@ -0,0 +1,172 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/strings/stringprintf.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/test/browser_test_utils.h"
+#include "extensions/browser/guest_view/web_view/web_view_apitest.h"
+#include "extensions/test/extension_test_message_listener.h"
+
+namespace {
+
+// 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), checked_(false) {}
+ virtual ~MockWebContentsDelegate() {}
+
+ virtual void RequestMediaAccessPermission(
+ content::WebContents* web_contents,
+ const content::MediaStreamRequest& request,
+ const content::MediaResponseCallback& callback) override {
+ requested_ = true;
+ if (request_message_loop_runner_.get())
+ request_message_loop_runner_->Quit();
+ }
+
+ virtual bool CheckMediaAccessPermission(
+ content::WebContents* web_contents,
+ const GURL& security_origin,
+ content::MediaStreamType type) override {
+ checked_ = true;
+ if (check_message_loop_runner_.get())
+ check_message_loop_runner_->Quit();
+ return true;
+ }
+
+ void WaitForRequestMediaPermission() {
+ if (requested_)
+ return;
+ request_message_loop_runner_ = new content::MessageLoopRunner;
+ request_message_loop_runner_->Run();
+ }
+
+ void WaitForCheckMediaPermission() {
+ if (checked_)
+ return;
+ check_message_loop_runner_ = new content::MessageLoopRunner;
+ check_message_loop_runner_->Run();
+ }
+
+ private:
+ bool requested_;
+ bool checked_;
+ scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_;
+ scoped_refptr<content::MessageLoopRunner> check_message_loop_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockWebContentsDelegate);
+};
+
+} // namespace
+
+namespace extensions {
+
+class WebViewMediaAccessAPITest : public WebViewAPITest {
+ protected:
+ WebViewMediaAccessAPITest() {}
+
+ // Runs media_access tests.
+ void RunTest(const std::string& test_name) {
+ ExtensionTestMessageListener test_run_listener("TEST_PASSED", false);
+ test_run_listener.set_failure_message("TEST_FAILED");
+ EXPECT_TRUE(content::ExecuteScript(
+ embedder_web_contents_,
+ base::StringPrintf("runTest('%s');", test_name.c_str())));
+ ASSERT_TRUE(test_run_listener.WaitUntilSatisfied());
+ }
+
+ // content::BrowserTestBase implementation
+ virtual void SetUpOnMainThread() override {
+ WebViewAPITest::SetUpOnMainThread();
+ StartTestServer();
+ }
+
+ virtual void TearDownOnMainThread() override {
+ WebViewAPITest::TearDownOnMainThread();
+ StopTestServer();
+ }
+};
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestAllow) {
+ LaunchApp("web_view/media_access/allow");
+ scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
+ embedder_web_contents_->SetDelegate(mock.get());
+
+ RunTest("testAllow");
+
+ mock->WaitForRequestMediaPermission();
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestAllowAndThenDeny) {
+ LaunchApp("web_view/media_access/allow");
+ scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
+ embedder_web_contents_->SetDelegate(mock.get());
+
+ RunTest("testAllowAndThenDeny");
+
+ mock->WaitForRequestMediaPermission();
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestAllowAsync) {
+ LaunchApp("web_view/media_access/allow");
+ scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
+ embedder_web_contents_->SetDelegate(mock.get());
+
+ RunTest("testAllowAsync");
+
+ mock->WaitForRequestMediaPermission();
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestAllowTwice) {
+ LaunchApp("web_view/media_access/allow");
+ scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
+ embedder_web_contents_->SetDelegate(mock.get());
+
+ RunTest("testAllowTwice");
+
+ mock->WaitForRequestMediaPermission();
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestCheck) {
+ LaunchApp("web_view/media_access/check");
+ scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate());
+ embedder_web_contents_->SetDelegate(mock.get());
+
+ RunTest("testCheck");
+
+ mock->WaitForCheckMediaPermission();
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestDeny) {
+ LaunchApp("web_view/media_access/deny");
+ RunTest("testDeny");
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestDenyThenAllowThrows) {
+ LaunchApp("web_view/media_access/deny");
+ RunTest("testDenyThenAllowThrows");
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestDenyWithPreventDefault) {
+ LaunchApp("web_view/media_access/deny");
+ RunTest("testDenyWithPreventDefault");
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestNoListenersImplyDeny) {
+ LaunchApp("web_view/media_access/deny");
+ RunTest("testNoListenersImplyDeny");
+}
+
+IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest,
+ TestNoPreventDefaultImpliesDeny) {
+ LaunchApp("web_view/media_access/deny");
+ RunTest("testNoPreventDefaultImpliesDeny");
+}
+
+} // namespace extensions
« no previous file with comments | « extensions/browser/guest_view/web_view/web_view_apitest.cc ('k') | extensions/extensions.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698