| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #include "content/public/browser/web_contents_delegate.h" | 6 #include "content/public/browser/web_contents_delegate.h" |
| 7 #include "content/public/test/browser_test_utils.h" | 7 #include "content/public/test/browser_test_utils.h" |
| 8 #include "extensions/browser/guest_view/web_view/web_view_apitest.h" | 8 #include "extensions/browser/guest_view/web_view/web_view_apitest.h" |
| 9 #include "extensions/test/extension_test_message_listener.h" | 9 #include "extensions/test/extension_test_message_listener.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // This class intercepts media access request from the embedder. The request | 13 // This class intercepts media access request from the embedder. The request |
| 14 // should be triggered only if the embedder API (from tests) allows the request | 14 // should be triggered only if the embedder API (from tests) allows the request |
| 15 // in Javascript. | 15 // in Javascript. |
| 16 // We do not issue the actual media request; the fact that the request reached | 16 // We do not issue the actual media request; the fact that the request reached |
| 17 // embedder's WebContents is good enough for our tests. This is also to make | 17 // embedder's WebContents is good enough for our tests. This is also to make |
| 18 // the test run successfully on trybots. | 18 // the test run successfully on trybots. |
| 19 class MockWebContentsDelegate : public content::WebContentsDelegate { | 19 class MockWebContentsDelegate : public content::WebContentsDelegate { |
| 20 public: | 20 public: |
| 21 MockWebContentsDelegate() : requested_(false), checked_(false) {} | 21 MockWebContentsDelegate() : requested_(false), checked_(false) {} |
| 22 virtual ~MockWebContentsDelegate() {} | 22 ~MockWebContentsDelegate() override {} |
| 23 | 23 |
| 24 virtual void RequestMediaAccessPermission( | 24 void RequestMediaAccessPermission( |
| 25 content::WebContents* web_contents, | 25 content::WebContents* web_contents, |
| 26 const content::MediaStreamRequest& request, | 26 const content::MediaStreamRequest& request, |
| 27 const content::MediaResponseCallback& callback) override { | 27 const content::MediaResponseCallback& callback) override { |
| 28 requested_ = true; | 28 requested_ = true; |
| 29 if (request_message_loop_runner_.get()) | 29 if (request_message_loop_runner_.get()) |
| 30 request_message_loop_runner_->Quit(); | 30 request_message_loop_runner_->Quit(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 virtual bool CheckMediaAccessPermission( | 33 bool CheckMediaAccessPermission(content::WebContents* web_contents, |
| 34 content::WebContents* web_contents, | 34 const GURL& security_origin, |
| 35 const GURL& security_origin, | 35 content::MediaStreamType type) override { |
| 36 content::MediaStreamType type) override { | |
| 37 checked_ = true; | 36 checked_ = true; |
| 38 if (check_message_loop_runner_.get()) | 37 if (check_message_loop_runner_.get()) |
| 39 check_message_loop_runner_->Quit(); | 38 check_message_loop_runner_->Quit(); |
| 40 return true; | 39 return true; |
| 41 } | 40 } |
| 42 | 41 |
| 43 void WaitForRequestMediaPermission() { | 42 void WaitForRequestMediaPermission() { |
| 44 if (requested_) | 43 if (requested_) |
| 45 return; | 44 return; |
| 46 request_message_loop_runner_ = new content::MessageLoopRunner; | 45 request_message_loop_runner_ = new content::MessageLoopRunner; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 75 void RunTest(const std::string& test_name) { | 74 void RunTest(const std::string& test_name) { |
| 76 ExtensionTestMessageListener test_run_listener("TEST_PASSED", false); | 75 ExtensionTestMessageListener test_run_listener("TEST_PASSED", false); |
| 77 test_run_listener.set_failure_message("TEST_FAILED"); | 76 test_run_listener.set_failure_message("TEST_FAILED"); |
| 78 EXPECT_TRUE(content::ExecuteScript( | 77 EXPECT_TRUE(content::ExecuteScript( |
| 79 embedder_web_contents_, | 78 embedder_web_contents_, |
| 80 base::StringPrintf("runTest('%s');", test_name.c_str()))); | 79 base::StringPrintf("runTest('%s');", test_name.c_str()))); |
| 81 ASSERT_TRUE(test_run_listener.WaitUntilSatisfied()); | 80 ASSERT_TRUE(test_run_listener.WaitUntilSatisfied()); |
| 82 } | 81 } |
| 83 | 82 |
| 84 // content::BrowserTestBase implementation | 83 // content::BrowserTestBase implementation |
| 85 virtual void SetUpOnMainThread() override { | 84 void SetUpOnMainThread() override { |
| 86 WebViewAPITest::SetUpOnMainThread(); | 85 WebViewAPITest::SetUpOnMainThread(); |
| 87 StartTestServer(); | 86 StartTestServer(); |
| 88 } | 87 } |
| 89 | 88 |
| 90 virtual void TearDownOnMainThread() override { | 89 void TearDownOnMainThread() override { |
| 91 WebViewAPITest::TearDownOnMainThread(); | 90 WebViewAPITest::TearDownOnMainThread(); |
| 92 StopTestServer(); | 91 StopTestServer(); |
| 93 } | 92 } |
| 94 }; | 93 }; |
| 95 | 94 |
| 96 IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestAllow) { | 95 IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, TestAllow) { |
| 97 LaunchApp("web_view/media_access/allow"); | 96 LaunchApp("web_view/media_access/allow"); |
| 98 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate()); | 97 scoped_ptr<MockWebContentsDelegate> mock(new MockWebContentsDelegate()); |
| 99 embedder_web_contents_->SetDelegate(mock.get()); | 98 embedder_web_contents_->SetDelegate(mock.get()); |
| 100 | 99 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 RunTest("testNoListenersImplyDeny"); | 162 RunTest("testNoListenersImplyDeny"); |
| 164 } | 163 } |
| 165 | 164 |
| 166 IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, | 165 IN_PROC_BROWSER_TEST_F(WebViewMediaAccessAPITest, |
| 167 TestNoPreventDefaultImpliesDeny) { | 166 TestNoPreventDefaultImpliesDeny) { |
| 168 LaunchApp("web_view/media_access/deny"); | 167 LaunchApp("web_view/media_access/deny"); |
| 169 RunTest("testNoPreventDefaultImpliesDeny"); | 168 RunTest("testNoPreventDefaultImpliesDeny"); |
| 170 } | 169 } |
| 171 | 170 |
| 172 } // namespace extensions | 171 } // namespace extensions |
| OLD | NEW |