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/path_service.h" | 5 #include "base/path_service.h" |
6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "content/public/test/browser_test.h" | 7 #include "content/public/test/browser_test.h" |
8 #include "content/public/test/browser_test_utils.h" | 8 #include "content/public/test/browser_test_utils.h" |
9 #include "content/public/test/test_utils.h" | 9 #include "content/public/test/test_utils.h" |
10 #include "extensions/browser/app_window/app_window.h" | 10 #include "extensions/browser/app_window/app_window.h" |
11 #include "extensions/browser/app_window/app_window_registry.h" | 11 #include "extensions/browser/app_window/app_window_registry.h" |
12 #include "extensions/browser/guest_view/guest_view_manager.h" | 12 #include "extensions/browser/guest_view/guest_view_manager.h" |
13 #include "extensions/browser/guest_view/guest_view_manager_factory.h" | 13 #include "extensions/browser/guest_view/guest_view_manager_factory.h" |
14 #include "extensions/browser/guest_view/test_guest_view_manager.h" | 14 #include "extensions/browser/guest_view/test_guest_view_manager.h" |
15 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
16 #include "extensions/common/extension_paths.h" | 16 #include "extensions/common/extension_paths.h" |
| 17 #include "extensions/shell/browser/shell_app_delegate.h" |
| 18 #include "extensions/shell/browser/shell_app_view_guest_delegate.h" |
17 #include "extensions/shell/browser/shell_content_browser_client.h" | 19 #include "extensions/shell/browser/shell_content_browser_client.h" |
18 #include "extensions/shell/browser/shell_extension_system.h" | 20 #include "extensions/shell/browser/shell_extension_system.h" |
| 21 #include "extensions/shell/browser/shell_extensions_api_client.h" |
| 22 #include "extensions/shell/browser/shell_extensions_browser_client.h" |
19 #include "extensions/shell/test/shell_test.h" | 23 #include "extensions/shell/test/shell_test.h" |
20 #include "extensions/test/extension_test_message_listener.h" | 24 #include "extensions/test/extension_test_message_listener.h" |
21 #include "net/base/filename_util.h" | 25 #include "net/base/filename_util.h" |
22 | 26 |
| 27 namespace { |
| 28 |
| 29 class MockShellAppDelegate : public extensions::ShellAppDelegate { |
| 30 public: |
| 31 MockShellAppDelegate() : requested_(false) { |
| 32 DCHECK(instance_ == nullptr); |
| 33 instance_ = this; |
| 34 } |
| 35 ~MockShellAppDelegate() override { instance_ = nullptr; } |
| 36 |
| 37 void RequestMediaAccessPermission( |
| 38 content::WebContents* web_contents, |
| 39 const content::MediaStreamRequest& request, |
| 40 const content::MediaResponseCallback& callback, |
| 41 const extensions::Extension* extension) override { |
| 42 requested_ = true; |
| 43 if (request_message_loop_runner_.get()) |
| 44 request_message_loop_runner_->Quit(); |
| 45 } |
| 46 |
| 47 void WaitForRequestMediaPermission() { |
| 48 if (requested_) |
| 49 return; |
| 50 request_message_loop_runner_ = new content::MessageLoopRunner; |
| 51 request_message_loop_runner_->Run(); |
| 52 } |
| 53 |
| 54 static MockShellAppDelegate* Get() { return instance_; } |
| 55 |
| 56 private: |
| 57 bool requested_; |
| 58 scoped_refptr<content::MessageLoopRunner> request_message_loop_runner_; |
| 59 static MockShellAppDelegate* instance_; |
| 60 }; |
| 61 |
| 62 MockShellAppDelegate* MockShellAppDelegate::instance_ = nullptr; |
| 63 |
| 64 class MockShellAppViewGuestDelegate |
| 65 : public extensions::ShellAppViewGuestDelegate { |
| 66 public: |
| 67 MockShellAppViewGuestDelegate() {} |
| 68 |
| 69 extensions::AppDelegate* CreateAppDelegate() override { |
| 70 return new MockShellAppDelegate(); |
| 71 } |
| 72 }; |
| 73 |
| 74 class MockExtensionsAPIClient : public extensions::ShellExtensionsAPIClient { |
| 75 public: |
| 76 MockExtensionsAPIClient() {} |
| 77 |
| 78 extensions::AppViewGuestDelegate* CreateAppViewGuestDelegate() |
| 79 const override { |
| 80 return new MockShellAppViewGuestDelegate(); |
| 81 } |
| 82 }; |
| 83 |
| 84 } // namespace |
| 85 |
23 namespace extensions { | 86 namespace extensions { |
24 | 87 |
25 class AppViewTest : public AppShellTest { | 88 class AppViewTest : public AppShellTest { |
26 protected: | 89 protected: |
27 AppViewTest() { GuestViewManager::set_factory_for_testing(&factory_); } | 90 AppViewTest() { GuestViewManager::set_factory_for_testing(&factory_); } |
28 | 91 |
29 TestGuestViewManager* GetGuestViewManager() { | 92 TestGuestViewManager* GetGuestViewManager() { |
30 return static_cast<TestGuestViewManager*>( | 93 return static_cast<TestGuestViewManager*>( |
31 TestGuestViewManager::FromBrowserContext( | 94 TestGuestViewManager::FromBrowserContext( |
32 ShellContentBrowserClient::Get()->GetBrowserContext())); | 95 ShellContentBrowserClient::Get()->GetBrowserContext())); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 TestGuestViewManagerFactory factory_; | 142 TestGuestViewManagerFactory factory_; |
80 }; | 143 }; |
81 | 144 |
82 // Tests that <appview> correctly processes parameters passed on connect. | 145 // Tests that <appview> correctly processes parameters passed on connect. |
83 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewGoodDataShouldSucceed) { | 146 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewGoodDataShouldSucceed) { |
84 RunTest("testAppViewGoodDataShouldSucceed", | 147 RunTest("testAppViewGoodDataShouldSucceed", |
85 "app_view/apitest", | 148 "app_view/apitest", |
86 "app_view/apitest/skeleton"); | 149 "app_view/apitest/skeleton"); |
87 } | 150 } |
88 | 151 |
| 152 // Tests that <appview> can handle media permission requests. |
| 153 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewMediaRequest) { |
| 154 static_cast<ShellExtensionsBrowserClient*>(ExtensionsBrowserClient::Get()) |
| 155 ->SetAPIClientForTest(nullptr); |
| 156 static_cast<ShellExtensionsBrowserClient*>(ExtensionsBrowserClient::Get()) |
| 157 ->SetAPIClientForTest(new MockExtensionsAPIClient); |
| 158 |
| 159 RunTest("testAppViewMediaRequest", "app_view/apitest", |
| 160 "app_view/apitest/media_request"); |
| 161 |
| 162 MockShellAppDelegate::Get()->WaitForRequestMediaPermission(); |
| 163 } |
| 164 |
89 // Tests that <appview> correctly processes parameters passed on connect. | 165 // Tests that <appview> correctly processes parameters passed on connect. |
90 // This test should fail to connect because the embedded app (skeleton) will | 166 // This test should fail to connect because the embedded app (skeleton) will |
91 // refuse the data passed by the embedder app and deny the request. | 167 // refuse the data passed by the embedder app and deny the request. |
92 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewRefusedDataShouldFail) { | 168 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewRefusedDataShouldFail) { |
93 RunTest("testAppViewRefusedDataShouldFail", | 169 RunTest("testAppViewRefusedDataShouldFail", |
94 "app_view/apitest", | 170 "app_view/apitest", |
95 "app_view/apitest/skeleton"); | 171 "app_view/apitest/skeleton"); |
96 } | 172 } |
97 | 173 |
98 // Tests that <appview> is able to navigate to another installed app. | 174 // Tests that <appview> is able to navigate to another installed app. |
99 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { | 175 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { |
100 RunTest("testAppViewWithUndefinedDataShouldSucceed", | 176 RunTest("testAppViewWithUndefinedDataShouldSucceed", |
101 "app_view/apitest", | 177 "app_view/apitest", |
102 "app_view/apitest/skeleton"); | 178 "app_view/apitest/skeleton"); |
103 } | 179 } |
104 | 180 |
105 } // namespace extensions | 181 } // namespace extensions |
OLD | NEW |