Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
|
lazyboy
2016/04/12 18:09:34
What about app_view_apitest.cc, have you tried run
lfg
2016/04/12 20:53:38
They all pass, but since they run on the unsupport
lfg
2016/04/12 21:45:43
I've enabled the tests.
| |
| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/apps/app_browsertest_util.h" | 9 #include "chrome/browser/apps/app_browsertest_util.h" |
| 10 #include "components/guest_view/browser/guest_view_manager.h" | 10 #include "components/guest_view/browser/guest_view_manager.h" |
| 11 #include "components/guest_view/browser/guest_view_manager_factory.h" | 11 #include "components/guest_view/browser/guest_view_manager_factory.h" |
| 12 #include "components/guest_view/browser/test_guest_view_manager.h" | 12 #include "components/guest_view/browser/test_guest_view_manager.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/render_process_host_observer.h" | 15 #include "content/public/browser/render_process_host_observer.h" |
| 16 #include "content/public/common/content_switches.h" | |
| 16 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 17 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
| 18 #include "extensions/browser/api/app_runtime/app_runtime_api.h" | 19 #include "extensions/browser/api/app_runtime/app_runtime_api.h" |
| 19 #include "extensions/browser/api/extensions_api_client.h" | 20 #include "extensions/browser/api/extensions_api_client.h" |
| 20 #include "extensions/browser/app_window/app_window_registry.h" | 21 #include "extensions/browser/app_window/app_window_registry.h" |
| 21 #include "extensions/browser/guest_view/app_view/app_view_constants.h" | 22 #include "extensions/browser/guest_view/app_view/app_view_constants.h" |
| 22 #include "extensions/browser/guest_view/app_view/app_view_guest.h" | 23 #include "extensions/browser/guest_view/app_view/app_view_guest.h" |
| 23 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h " | 24 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h " |
| 24 #include "extensions/browser/process_manager.h" | 25 #include "extensions/browser/process_manager.h" |
| 25 #include "extensions/common/switches.h" | 26 #include "extensions/common/switches.h" |
| 26 #include "extensions/test/extension_test_message_listener.h" | 27 #include "extensions/test/extension_test_message_listener.h" |
| 27 #include "net/test/embedded_test_server/embedded_test_server.h" | 28 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 28 #include "net/test/embedded_test_server/http_request.h" | 29 #include "net/test/embedded_test_server/http_request.h" |
| 29 #include "net/test/embedded_test_server/http_response.h" | 30 #include "net/test/embedded_test_server/http_response.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | |
| 30 | 32 |
| 31 using extensions::ExtensionsAPIClient; | 33 using extensions::ExtensionsAPIClient; |
| 32 using guest_view::GuestViewManager; | 34 using guest_view::GuestViewManager; |
| 33 using guest_view::TestGuestViewManagerFactory; | 35 using guest_view::TestGuestViewManagerFactory; |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 class RenderProcessHostObserverForExit | 39 class RenderProcessHostObserverForExit |
| 38 : public content::RenderProcessHostObserver { | 40 : public content::RenderProcessHostObserver { |
| 39 public: | 41 public: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 68 bool render_process_host_exited_; | 70 bool render_process_host_exited_; |
| 69 content::RenderProcessHost* observed_host_; | 71 content::RenderProcessHost* observed_host_; |
| 70 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | 72 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; |
| 71 base::TerminationStatus status_; | 73 base::TerminationStatus status_; |
| 72 | 74 |
| 73 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostObserverForExit); | 75 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostObserverForExit); |
| 74 }; | 76 }; |
| 75 | 77 |
| 76 } // namespace | 78 } // namespace |
| 77 | 79 |
| 78 class AppViewTest : public extensions::PlatformAppBrowserTest { | 80 class AppViewTest : public extensions::PlatformAppBrowserTest, |
| 81 public testing::WithParamInterface<bool> { | |
| 79 public: | 82 public: |
| 80 AppViewTest() { | 83 AppViewTest() { |
| 81 GuestViewManager::set_factory_for_testing(&factory_); | 84 GuestViewManager::set_factory_for_testing(&factory_); |
| 82 } | 85 } |
| 83 | 86 |
| 84 enum TestServer { | 87 enum TestServer { |
| 85 NEEDS_TEST_SERVER, | 88 NEEDS_TEST_SERVER, |
| 86 NO_TEST_SERVER | 89 NO_TEST_SERVER |
| 87 }; | 90 }; |
| 88 | 91 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | 125 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 123 } | 126 } |
| 124 | 127 |
| 125 guest_view::TestGuestViewManager* test_guest_view_manager() const { | 128 guest_view::TestGuestViewManager* test_guest_view_manager() const { |
| 126 return test_guest_view_manager_; | 129 return test_guest_view_manager_; |
| 127 } | 130 } |
| 128 | 131 |
| 129 private: | 132 private: |
| 130 void SetUpCommandLine(base::CommandLine* command_line) override { | 133 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 131 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 134 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 135 | |
| 136 bool use_cross_process_frames_for_guests = GetParam(); | |
| 137 if (use_cross_process_frames_for_guests) | |
| 138 command_line->AppendSwitch(switches::kUseCrossProcessFramesForGuests); | |
| 132 } | 139 } |
| 133 | 140 |
| 134 void SetUpOnMainThread() override { | 141 void SetUpOnMainThread() override { |
| 135 extensions::PlatformAppBrowserTest::SetUpOnMainThread(); | 142 extensions::PlatformAppBrowserTest::SetUpOnMainThread(); |
| 136 test_guest_view_manager_ = static_cast<guest_view::TestGuestViewManager*>( | 143 test_guest_view_manager_ = static_cast<guest_view::TestGuestViewManager*>( |
| 137 guest_view::GuestViewManager::CreateWithDelegate( | 144 guest_view::GuestViewManager::CreateWithDelegate( |
| 138 browser()->profile(), | 145 browser()->profile(), |
| 139 scoped_ptr<guest_view::GuestViewManagerDelegate>( | 146 scoped_ptr<guest_view::GuestViewManagerDelegate>( |
| 140 ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( | 147 ExtensionsAPIClient::Get()->CreateGuestViewManagerDelegate( |
| 141 browser()->profile())))); | 148 browser()->profile())))); |
| 142 } | 149 } |
| 143 | 150 |
| 144 TestGuestViewManagerFactory factory_; | 151 TestGuestViewManagerFactory factory_; |
| 145 guest_view::TestGuestViewManager* test_guest_view_manager_; | 152 guest_view::TestGuestViewManager* test_guest_view_manager_; |
| 146 | 153 |
| 147 DISALLOW_COPY_AND_ASSIGN(AppViewTest); | 154 DISALLOW_COPY_AND_ASSIGN(AppViewTest); |
| 148 }; | 155 }; |
| 149 | 156 |
| 157 INSTANTIATE_TEST_CASE_P(AppViewTests, AppViewTest, testing::Bool()); | |
| 158 | |
| 150 // Tests that <appview> is able to navigate to another installed app. | 159 // Tests that <appview> is able to navigate to another installed app. |
| 151 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { | 160 IN_PROC_BROWSER_TEST_P(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { |
| 152 const extensions::Extension* skeleton_app = | 161 const extensions::Extension* skeleton_app = |
| 153 InstallPlatformApp("app_view/shim/skeleton"); | 162 InstallPlatformApp("app_view/shim/skeleton"); |
| 154 TestHelper("testAppViewWithUndefinedDataShouldSucceed", | 163 TestHelper("testAppViewWithUndefinedDataShouldSucceed", |
| 155 "app_view/shim", | 164 "app_view/shim", |
| 156 skeleton_app->id(), | 165 skeleton_app->id(), |
| 157 NO_TEST_SERVER); | 166 NO_TEST_SERVER); |
| 158 } | 167 } |
| 159 | 168 |
| 160 // Tests that <appview> correctly processes parameters passed on connect. | 169 // Tests that <appview> correctly processes parameters passed on connect. |
| 161 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewRefusedDataShouldFail) { | 170 IN_PROC_BROWSER_TEST_P(AppViewTest, TestAppViewRefusedDataShouldFail) { |
|
Devlin
2016/04/12 18:09:52
Out of curiosity, is this significantly better tha
lfg
2016/04/12 20:53:38
Yes, the SiteIsolation trybot tests with --site-pe
| |
| 162 const extensions::Extension* skeleton_app = | 171 const extensions::Extension* skeleton_app = |
| 163 InstallPlatformApp("app_view/shim/skeleton"); | 172 InstallPlatformApp("app_view/shim/skeleton"); |
| 164 TestHelper("testAppViewRefusedDataShouldFail", | 173 TestHelper("testAppViewRefusedDataShouldFail", |
| 165 "app_view/shim", | 174 "app_view/shim", |
| 166 skeleton_app->id(), | 175 skeleton_app->id(), |
| 167 NO_TEST_SERVER); | 176 NO_TEST_SERVER); |
| 168 } | 177 } |
| 169 | 178 |
| 170 // Tests that <appview> correctly processes parameters passed on connect. | 179 // Tests that <appview> correctly processes parameters passed on connect. |
| 171 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewGoodDataShouldSucceed) { | 180 IN_PROC_BROWSER_TEST_P(AppViewTest, TestAppViewGoodDataShouldSucceed) { |
| 172 const extensions::Extension* skeleton_app = | 181 const extensions::Extension* skeleton_app = |
| 173 InstallPlatformApp("app_view/shim/skeleton"); | 182 InstallPlatformApp("app_view/shim/skeleton"); |
| 174 TestHelper("testAppViewGoodDataShouldSucceed", | 183 TestHelper("testAppViewGoodDataShouldSucceed", |
| 175 "app_view/shim", | 184 "app_view/shim", |
| 176 skeleton_app->id(), | 185 skeleton_app->id(), |
| 177 NO_TEST_SERVER); | 186 NO_TEST_SERVER); |
| 178 } | 187 } |
| 179 | 188 |
| 180 // Tests that <appview> correctly handles multiple successive connects. | 189 // Tests that <appview> correctly handles multiple successive connects. |
| 181 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewMultipleConnects) { | 190 IN_PROC_BROWSER_TEST_P(AppViewTest, TestAppViewMultipleConnects) { |
| 182 const extensions::Extension* skeleton_app = | 191 const extensions::Extension* skeleton_app = |
| 183 InstallPlatformApp("app_view/shim/skeleton"); | 192 InstallPlatformApp("app_view/shim/skeleton"); |
| 184 TestHelper("testAppViewMultipleConnects", | 193 TestHelper("testAppViewMultipleConnects", |
| 185 "app_view/shim", | 194 "app_view/shim", |
| 186 skeleton_app->id(), | 195 skeleton_app->id(), |
| 187 NO_TEST_SERVER); | 196 NO_TEST_SERVER); |
| 188 } | 197 } |
| 189 | 198 |
| 190 // Tests that <appview> does not embed self (the app which owns appview). | 199 // Tests that <appview> does not embed self (the app which owns appview). |
| 191 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewEmbedSelfShouldFail) { | 200 IN_PROC_BROWSER_TEST_P(AppViewTest, TestAppViewEmbedSelfShouldFail) { |
| 192 const extensions::Extension* skeleton_app = | 201 const extensions::Extension* skeleton_app = |
| 193 InstallPlatformApp("app_view/shim/skeleton"); | 202 InstallPlatformApp("app_view/shim/skeleton"); |
| 194 TestHelper("testAppViewEmbedSelfShouldFail", | 203 TestHelper("testAppViewEmbedSelfShouldFail", |
| 195 "app_view/shim", | 204 "app_view/shim", |
| 196 skeleton_app->id(), | 205 skeleton_app->id(), |
| 197 NO_TEST_SERVER); | 206 NO_TEST_SERVER); |
| 198 } | 207 } |
| 199 | 208 |
| 200 IN_PROC_BROWSER_TEST_F(AppViewTest, KillGuestWithInvalidInstanceID) { | 209 IN_PROC_BROWSER_TEST_P(AppViewTest, KillGuestWithInvalidInstanceID) { |
| 201 const extensions::Extension* bad_app = | 210 const extensions::Extension* bad_app = |
| 202 LoadAndLaunchPlatformApp("app_view/bad_app", "AppViewTest.LAUNCHED"); | 211 LoadAndLaunchPlatformApp("app_view/bad_app", "AppViewTest.LAUNCHED"); |
| 203 | 212 |
| 204 content::RenderProcessHost* bad_app_render_process_host = | 213 content::RenderProcessHost* bad_app_render_process_host = |
| 205 extensions::AppWindowRegistry::Get(browser()->profile()) | 214 extensions::AppWindowRegistry::Get(browser()->profile()) |
| 206 ->GetCurrentAppWindowForApp(bad_app->id()) | 215 ->GetCurrentAppWindowForApp(bad_app->id()) |
| 207 ->web_contents() | 216 ->web_contents() |
| 208 ->GetRenderProcessHost(); | 217 ->GetRenderProcessHost(); |
| 209 | 218 |
| 210 // Monitor |bad_app|'s RenderProcessHost for its exiting. | 219 // Monitor |bad_app|'s RenderProcessHost for its exiting. |
| 211 RenderProcessHostObserverForExit exit_observer(bad_app_render_process_host); | 220 RenderProcessHostObserverForExit exit_observer(bad_app_render_process_host); |
| 212 | 221 |
| 213 // Choosing a |guest_instance_id| which does not exist. | 222 // Choosing a |guest_instance_id| which does not exist. |
| 214 int invalid_guest_instance_id = | 223 int invalid_guest_instance_id = |
| 215 test_guest_view_manager()->GetNextInstanceID(); | 224 test_guest_view_manager()->GetNextInstanceID(); |
| 216 // Call the desired function to verify that the |bad_app| gets killed if | 225 // Call the desired function to verify that the |bad_app| gets killed if |
| 217 // the provided |guest_instance_id| is not mapped to any "GuestView"'s. | 226 // the provided |guest_instance_id| is not mapped to any "GuestView"'s. |
| 218 extensions::AppViewGuest::CompletePendingRequest( | 227 extensions::AppViewGuest::CompletePendingRequest( |
| 219 browser()->profile(), GURL("about:blank"), invalid_guest_instance_id, | 228 browser()->profile(), GURL("about:blank"), invalid_guest_instance_id, |
| 220 bad_app->id(), bad_app_render_process_host); | 229 bad_app->id(), bad_app_render_process_host); |
| 221 exit_observer.WaitUntilRenderProcessHostKilled(); | 230 exit_observer.WaitUntilRenderProcessHostKilled(); |
| 222 } | 231 } |
| 223 | 232 |
| 224 IN_PROC_BROWSER_TEST_F(AppViewTest, KillGuestCommunicatingWithWrongAppView) { | 233 IN_PROC_BROWSER_TEST_P(AppViewTest, KillGuestCommunicatingWithWrongAppView) { |
| 225 const extensions::Extension* host_app = | 234 const extensions::Extension* host_app = |
| 226 LoadAndLaunchPlatformApp("app_view/host_app", "AppViewTest.LAUNCHED"); | 235 LoadAndLaunchPlatformApp("app_view/host_app", "AppViewTest.LAUNCHED"); |
| 227 const extensions::Extension* guest_app = | 236 const extensions::Extension* guest_app = |
| 228 InstallPlatformApp("app_view/guest_app"); | 237 InstallPlatformApp("app_view/guest_app"); |
| 229 const extensions::Extension* bad_app = | 238 const extensions::Extension* bad_app = |
| 230 LoadAndLaunchPlatformApp("app_view/bad_app", "AppViewTest.LAUNCHED"); | 239 LoadAndLaunchPlatformApp("app_view/bad_app", "AppViewTest.LAUNCHED"); |
| 231 // The host app attemps to embed the guest | 240 // The host app attemps to embed the guest |
| 232 EXPECT_TRUE(content::ExecuteScript( | 241 EXPECT_TRUE(content::ExecuteScript( |
| 233 extensions::AppWindowRegistry::Get(browser()->profile()) | 242 extensions::AppWindowRegistry::Get(browser()->profile()) |
| 234 ->GetCurrentAppWindowForApp(host_app->id()) | 243 ->GetCurrentAppWindowForApp(host_app->id()) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 254 extensions::AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( | 263 extensions::AppRuntimeEventRouter::DispatchOnEmbedRequestedEvent( |
| 255 browser()->profile(), std::move(fake_embed_request_param), bad_app); | 264 browser()->profile(), std::move(fake_embed_request_param), bad_app); |
| 256 bad_app_obs.WaitUntilRenderProcessHostKilled(); | 265 bad_app_obs.WaitUntilRenderProcessHostKilled(); |
| 257 // Now ask the guest to continue embedding. | 266 // Now ask the guest to continue embedding. |
| 258 ASSERT_TRUE( | 267 ASSERT_TRUE( |
| 259 ExecuteScript(extensions::ProcessManager::Get(browser()->profile()) | 268 ExecuteScript(extensions::ProcessManager::Get(browser()->profile()) |
| 260 ->GetBackgroundHostForExtension(guest_app->id()) | 269 ->GetBackgroundHostForExtension(guest_app->id()) |
| 261 ->web_contents(), | 270 ->web_contents(), |
| 262 "continueEmbedding();")); | 271 "continueEmbedding();")); |
| 263 } | 272 } |
| OLD | NEW |