Chromium Code Reviews| 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 b3480af87a9f005b53800d5744ac56fbbff5fe26..4e5c2b5b57571013bf1ddef2f89f5b59ab087649 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" |
| @@ -10,10 +11,13 @@ |
| #include "chrome/browser/prerender/prerender_link_manager_factory.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/common/chrome_switches.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" |
| @@ -22,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 |
|
Charlie Reis
2013/02/13 21:08:05
nit: semicolon. :)
lazyboy
2013/02/13 22:17:34
Done.
|
| +// 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 { |
| @@ -31,6 +67,15 @@ class WebViewTest : public extensions::PlatformAppBrowserTest { |
| command_line, gfx::kGLImplementationOSMesaName)) << |
| "kUseGL must not be set by test framework code!"; |
| #endif |
| + const testing::TestInfo* const test_info = |
| + testing::UnitTest::GetInstance()->current_test_info(); |
| + bool requires_experimental = |
| + !strcmp(test_info->name(), "MediaAccessAPIAllow") || |
| + !strcmp(test_info->name(), "MediaAccessAPIDeny"); |
| + if (requires_experimental) { |
| + CommandLine::ForCurrentProcess()->AppendSwitch( |
| + switches::kEnableExperimentalExtensionApis); |
| + } |
| } |
| virtual void SetUp() OVERRIDE { |
| @@ -669,6 +714,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 != NULL); |
|
Charlie Reis
2013/02/13 21:08:05
nit: Don't need the != NULL.
lazyboy
2013/02/13 22:17:34
Done.
|
| + 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. |
| @@ -702,3 +792,4 @@ IN_PROC_BROWSER_TEST_F(WebViewTest, SpeechRecognition) { |
| title_watcher.AlsoWaitForTitle(error_title); |
| EXPECT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| } |
| + |
|
Charlie Reis
2013/02/13 21:08:05
nit: Extra line.
lazyboy
2013/02/13 22:17:34
Removed.
|