| 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 d1d78e9e4c35263d552fdd402849f0551c37f788..cc3fd9a258dcc4bd8019be705d12789f580060f9 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 {
|
| @@ -676,6 +711,51 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, IndexedDBIsolation) {
|
| ExecuteScriptWaitForTitle(default_tag_contents1, script, "db not found");
|
| }
|
|
|
| +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.
|
|
|