Chromium Code Reviews| 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 "chrome/browser/apps/app_browsertest_util.h" | 6 #include "chrome/browser/apps/app_browsertest_util.h" |
| 7 #include "components/guest_view/browser/guest_view_manager.h" | 7 #include "components/guest_view/browser/guest_view_manager.h" |
| 8 #include "components/guest_view/browser/guest_view_manager_factory.h" | 8 #include "components/guest_view/browser/guest_view_manager_factory.h" |
| 9 #include "components/guest_view/browser/test_guest_view_manager.h" | 9 #include "components/guest_view/browser/test_guest_view_manager.h" |
| 10 #include "content/public/browser/notification_observer.h" | |
|
lfg
2015/07/06 18:46:21
Is this needed?
EhsanK
2015/07/06 21:09:58
No. Removed. Thanks.
| |
| 10 #include "content/public/browser/notification_service.h" | 11 #include "content/public/browser/notification_service.h" |
| 11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
| 13 #include "content/public/browser/render_process_host_observer.h" | |
| 12 #include "content/public/test/browser_test_utils.h" | 14 #include "content/public/test/browser_test_utils.h" |
| 13 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 16 #include "extensions/browser/app_window/app_window_registry.h" | |
| 17 #include "extensions/browser/guest_view/app_view/app_view_guest.h" | |
| 18 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h " | |
| 19 #include "extensions/browser/process_manager.h" | |
| 14 #include "extensions/common/switches.h" | 20 #include "extensions/common/switches.h" |
| 15 #include "extensions/test/extension_test_message_listener.h" | 21 #include "extensions/test/extension_test_message_listener.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 22 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 #include "net/test/embedded_test_server/http_request.h" | 23 #include "net/test/embedded_test_server/http_request.h" |
| 18 #include "net/test/embedded_test_server/http_response.h" | 24 #include "net/test/embedded_test_server/http_response.h" |
| 19 | 25 |
| 20 using guest_view::GuestViewManager; | 26 using guest_view::GuestViewManager; |
| 21 using guest_view::TestGuestViewManagerFactory; | 27 using guest_view::TestGuestViewManagerFactory; |
| 22 | 28 |
| 29 namespace { | |
| 30 | |
| 31 class RenderProcessHostObserverForExit | |
| 32 : public content::RenderProcessHostObserver { | |
| 33 public: | |
| 34 explicit RenderProcessHostObserverForExit( | |
| 35 content::RenderProcessHost* observed_host) | |
| 36 : render_process_host_exited_(false), | |
| 37 observed_host_(observed_host), | |
| 38 message_loop_runner_(nullptr) { | |
|
Devlin
2015/07/06 20:18:07
nit: scoped_refptrs default to null, so you don't
EhsanK
2015/07/06 21:09:58
Done.
| |
| 39 observed_host->AddObserver(this); | |
| 40 } | |
| 41 | |
| 42 void WaitUntilRenderProcessHostKilled() { | |
| 43 if (render_process_host_exited_) | |
| 44 return; | |
| 45 message_loop_runner_ = new content::MessageLoopRunner; | |
| 46 message_loop_runner_->Run(); | |
| 47 } | |
| 48 | |
| 49 base::TerminationStatus termination_status() const { return status_; } | |
| 50 | |
| 51 private: | |
| 52 void RenderProcessExited(content::RenderProcessHost* host, | |
| 53 base::TerminationStatus status, | |
| 54 int exit_code) override { | |
| 55 DCHECK(observed_host_ == host); | |
| 56 render_process_host_exited_ = true; | |
| 57 status_ = status; | |
| 58 observed_host_->RemoveObserver(this); | |
| 59 if (message_loop_runner_.get()) { | |
| 60 message_loop_runner_->Quit(); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 bool render_process_host_exited_; | |
| 65 content::RenderProcessHost* observed_host_; | |
| 66 scoped_refptr<content::MessageLoopRunner> message_loop_runner_; | |
| 67 base::TerminationStatus status_; | |
| 68 | |
| 69 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostObserverForExit); | |
| 70 }; | |
| 71 | |
| 72 } // namespace | |
| 73 | |
| 23 class AppViewTest : public extensions::PlatformAppBrowserTest { | 74 class AppViewTest : public extensions::PlatformAppBrowserTest { |
| 24 public: | 75 public: |
| 25 AppViewTest() { | 76 AppViewTest() { |
| 26 GuestViewManager::set_factory_for_testing(&factory_); | 77 GuestViewManager::set_factory_for_testing(&factory_); |
| 27 } | 78 } |
| 28 | 79 |
| 29 enum TestServer { | 80 enum TestServer { |
| 30 NEEDS_TEST_SERVER, | 81 NEEDS_TEST_SERVER, |
| 31 NO_TEST_SERVER | 82 NO_TEST_SERVER |
| 32 }; | 83 }; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 52 GetFirstAppWindowWebContents(); | 103 GetFirstAppWindowWebContents(); |
| 53 if (!embedder_web_contents) { | 104 if (!embedder_web_contents) { |
| 54 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS."; | 105 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS."; |
| 55 return; | 106 return; |
| 56 } | 107 } |
| 57 | 108 |
| 58 ExtensionTestMessageListener done_listener("TEST_PASSED", false); | 109 ExtensionTestMessageListener done_listener("TEST_PASSED", false); |
| 59 done_listener.set_failure_message("TEST_FAILED"); | 110 done_listener.set_failure_message("TEST_FAILED"); |
| 60 if (!content::ExecuteScript( | 111 if (!content::ExecuteScript( |
| 61 embedder_web_contents, | 112 embedder_web_contents, |
| 62 base::StringPrintf("runTest('%s', '%s')", | 113 base::StringPrintf("runTest('%s', '%s')", test_name.c_str(), |
| 63 test_name.c_str(), | |
| 64 app_to_embed.c_str()))) { | 114 app_to_embed.c_str()))) { |
| 65 LOG(ERROR) << "UNABLE TO START TEST."; | 115 LOG(ERROR) << "UNABLE TO START TEST."; |
| 66 return; | 116 return; |
| 67 } | 117 } |
| 68 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); | 118 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); |
| 69 } | 119 } |
| 70 | 120 |
| 121 guest_view::TestGuestViewManager* test_guest_view_manager() const { | |
| 122 return test_guest_view_manager_; | |
| 123 } | |
| 124 | |
| 71 private: | 125 private: |
| 72 void SetUpCommandLine(base::CommandLine* command_line) override { | 126 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 73 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); | 127 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 74 } | 128 } |
| 75 | 129 |
| 130 void SetUpOnMainThread() override { | |
|
Devlin
2015/07/06 20:18:07
nit: You need to call the super of this method as
EhsanK
2015/07/06 21:09:58
Done.
EhsanK
2015/07/06 21:09:58
Done.
| |
| 131 test_guest_view_manager_ = static_cast<guest_view::TestGuestViewManager*>( | |
| 132 guest_view::GuestViewManager::CreateWithDelegate( | |
| 133 browser()->profile(), | |
| 134 scoped_ptr<guest_view::GuestViewManagerDelegate>( | |
| 135 new extensions::ExtensionsGuestViewManagerDelegate( | |
| 136 browser()->profile())))); | |
| 137 } | |
| 138 | |
| 76 TestGuestViewManagerFactory factory_; | 139 TestGuestViewManagerFactory factory_; |
| 140 guest_view::TestGuestViewManager* test_guest_view_manager_; | |
| 77 }; | 141 }; |
|
Devlin
2015/07/06 20:18:07
nit: please add a DISALLOW_COPY_AND_ASSIGN() here.
EhsanK
2015/07/06 21:09:58
Done.
| |
| 78 | 142 |
| 79 // Tests that <appview> is able to navigate to another installed app. | 143 // Tests that <appview> is able to navigate to another installed app. |
| 80 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { | 144 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewWithUndefinedDataShouldSucceed) { |
| 81 const extensions::Extension* skeleton_app = | 145 const extensions::Extension* skeleton_app = |
| 82 InstallPlatformApp("app_view/shim/skeleton"); | 146 InstallPlatformApp("app_view/shim/skeleton"); |
| 83 TestHelper("testAppViewWithUndefinedDataShouldSucceed", | 147 TestHelper("testAppViewWithUndefinedDataShouldSucceed", |
| 84 "app_view/shim", | 148 "app_view/shim", |
| 85 skeleton_app->id(), | 149 skeleton_app->id(), |
| 86 NO_TEST_SERVER); | 150 NO_TEST_SERVER); |
| 87 } | 151 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 118 | 182 |
| 119 // Tests that <appview> does not embed self (the app which owns appview). | 183 // Tests that <appview> does not embed self (the app which owns appview). |
| 120 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewEmbedSelfShouldFail) { | 184 IN_PROC_BROWSER_TEST_F(AppViewTest, TestAppViewEmbedSelfShouldFail) { |
| 121 const extensions::Extension* skeleton_app = | 185 const extensions::Extension* skeleton_app = |
| 122 InstallPlatformApp("app_view/shim/skeleton"); | 186 InstallPlatformApp("app_view/shim/skeleton"); |
| 123 TestHelper("testAppViewEmbedSelfShouldFail", | 187 TestHelper("testAppViewEmbedSelfShouldFail", |
| 124 "app_view/shim", | 188 "app_view/shim", |
| 125 skeleton_app->id(), | 189 skeleton_app->id(), |
| 126 NO_TEST_SERVER); | 190 NO_TEST_SERVER); |
| 127 } | 191 } |
| 192 | |
| 193 IN_PROC_BROWSER_TEST_F(AppViewTest, KillGuestWithInvalidInstanceID) { | |
| 194 const extensions::Extension* mock_bad_app = | |
| 195 LoadAndLaunchPlatformApp("app_view/bad_app", "AppViewTest.LAUNCHED"); | |
| 196 | |
| 197 content::RenderProcessHost* bad_app_render_process_host = | |
| 198 extensions::AppWindowRegistry::Get(browser()->profile()) | |
| 199 ->GetCurrentAppWindowForApp(mock_bad_app->id()) | |
| 200 ->web_contents() | |
| 201 ->GetRenderProcessHost(); | |
| 202 | |
| 203 // Monitor |mock_bad_app|'s RenderProcessHost for its exiting. | |
| 204 RenderProcessHostObserverForExit exit_observer(bad_app_render_process_host); | |
| 205 | |
| 206 // Choosing a |guest_instance_id| which does not exist. | |
| 207 int invalid_guest_instance_id = | |
| 208 test_guest_view_manager()->GetNextInstanceID(); | |
| 209 // Call the desired function to verify that the |mock_bad_app| gets killed if | |
| 210 // the provided |guest_instance_id| is not mapped to any "GuestView"'s. | |
| 211 extensions::AppViewGuest::CompletePendingRequest( | |
| 212 browser()->profile(), GURL("about:blank"), invalid_guest_instance_id, | |
| 213 mock_bad_app->id(), bad_app_render_process_host); | |
| 214 exit_observer.WaitUntilRenderProcessHostKilled(); | |
| 215 EXPECT_EQ(exit_observer.termination_status(), | |
| 216 base::TERMINATION_STATUS_PROCESS_WAS_KILLED); | |
| 217 } | |
| 218 | |
| 219 IN_PROC_BROWSER_TEST_F(AppViewTest, KillGuestCommunicatingWithWrongAppView) { | |
| 220 const extensions::Extension* host_app = | |
| 221 LoadAndLaunchPlatformApp("app_view/host_app", "AppViewTest.LAUNCHED"); | |
| 222 const extensions::Extension* mock_guest_extension = | |
| 223 InstallPlatformApp("app_view/guest_app"); | |
| 224 const extensions::Extension* mock_bad_app = | |
| 225 LoadAndLaunchPlatformApp("app_view/bad_app", "AppViewTest.LAUNCHED"); | |
| 226 | |
| 227 EXPECT_TRUE(content::ExecuteScript( | |
| 228 extensions::AppWindowRegistry::Get(browser()->profile()) | |
| 229 ->GetCurrentAppWindowForApp(host_app->id()) | |
| 230 ->web_contents(), | |
| 231 base::StringPrintf("onAppCommand('%s', '%s');", "EMBED", | |
| 232 mock_guest_extension->id().c_str()))); | |
| 233 ExtensionTestMessageListener on_embed_requested_listener( | |
| 234 "AppViewTest.EmbedRequested", true); | |
| 235 EXPECT_TRUE(on_embed_requested_listener.WaitUntilSatisfied()); | |
| 236 // Now assume the bad application is somehow sending a message to complete a | |
| 237 // pending request to attach to <appview>. It should be killed. | |
| 238 content::RenderProcessHost* bad_app_render_process_host = | |
| 239 extensions::ProcessManager::Get(browser()->profile()) | |
| 240 ->GetBackgroundHostForExtension(mock_bad_app->id()) | |
| 241 ->render_process_host(); | |
| 242 RenderProcessHostObserverForExit bad_app_obs(bad_app_render_process_host); | |
| 243 // Make the false request. | |
| 244 int guest_instance_id = | |
| 245 extensions::AppViewGuest::GetAllRegisteredInstanceIdsForTesting()[0]; | |
| 246 extensions::AppViewGuest::CompletePendingRequest( | |
| 247 browser()->profile(), GURL("about:blank"), guest_instance_id, | |
| 248 mock_bad_app->id(), bad_app_render_process_host); | |
| 249 | |
| 250 on_embed_requested_listener.Reply("continue"); | |
| 251 // Make sure the bad application has been terminated. | |
| 252 bad_app_obs.WaitUntilRenderProcessHostKilled(); | |
| 253 | |
| 254 EXPECT_EQ(bad_app_obs.termination_status(), | |
| 255 base::TERMINATION_STATUS_PROCESS_WAS_KILLED); | |
| 256 } | |
| OLD | NEW |