Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Side by Side Diff: chrome/browser/apps/guest_view/app_view_browsertest.cc

Issue 1181893003: Kill bad apps. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed Check for Termination Status (Windows Problems) Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/app_view/bad_app/background.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_service.h" 10 #include "content/public/browser/notification_service.h"
11 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_process_host_observer.h"
12 #include "content/public/test/browser_test_utils.h" 13 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
15 #include "extensions/browser/app_window/app_window_registry.h"
16 #include "extensions/browser/guest_view/app_view/app_view_guest.h"
17 #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h "
18 #include "extensions/browser/process_manager.h"
14 #include "extensions/common/switches.h" 19 #include "extensions/common/switches.h"
15 #include "extensions/test/extension_test_message_listener.h" 20 #include "extensions/test/extension_test_message_listener.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "net/test/embedded_test_server/http_request.h" 22 #include "net/test/embedded_test_server/http_request.h"
18 #include "net/test/embedded_test_server/http_response.h" 23 #include "net/test/embedded_test_server/http_response.h"
19 24
20 using guest_view::GuestViewManager; 25 using guest_view::GuestViewManager;
21 using guest_view::TestGuestViewManagerFactory; 26 using guest_view::TestGuestViewManagerFactory;
22 27
28 namespace {
29
30 class RenderProcessHostObserverForExit
31 : public content::RenderProcessHostObserver {
32 public:
33 explicit RenderProcessHostObserverForExit(
34 content::RenderProcessHost* observed_host)
35 : render_process_host_exited_(false), observed_host_(observed_host) {
36 observed_host->AddObserver(this);
37 }
38
39 void WaitUntilRenderProcessHostKilled() {
40 if (render_process_host_exited_)
41 return;
42 message_loop_runner_ = new content::MessageLoopRunner;
43 message_loop_runner_->Run();
44 }
45
46 base::TerminationStatus termination_status() const { return status_; }
47
48 private:
49 void RenderProcessExited(content::RenderProcessHost* host,
50 base::TerminationStatus status,
51 int exit_code) override {
52 DCHECK(observed_host_ == host);
53 render_process_host_exited_ = true;
54 status_ = status;
55 observed_host_->RemoveObserver(this);
56 if (message_loop_runner_.get()) {
57 message_loop_runner_->Quit();
58 }
59 }
60
61 bool render_process_host_exited_;
62 content::RenderProcessHost* observed_host_;
63 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
64 base::TerminationStatus status_;
65
66 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostObserverForExit);
67 };
68
69 } // namespace
70
23 class AppViewTest : public extensions::PlatformAppBrowserTest { 71 class AppViewTest : public extensions::PlatformAppBrowserTest {
24 public: 72 public:
25 AppViewTest() { 73 AppViewTest() {
26 GuestViewManager::set_factory_for_testing(&factory_); 74 GuestViewManager::set_factory_for_testing(&factory_);
27 } 75 }
28 76
29 enum TestServer { 77 enum TestServer {
30 NEEDS_TEST_SERVER, 78 NEEDS_TEST_SERVER,
31 NO_TEST_SERVER 79 NO_TEST_SERVER
32 }; 80 };
(...skipping 19 matching lines...) Expand all
52 GetFirstAppWindowWebContents(); 100 GetFirstAppWindowWebContents();
53 if (!embedder_web_contents) { 101 if (!embedder_web_contents) {
54 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS."; 102 LOG(ERROR) << "UNABLE TO FIND EMBEDDER WEB CONTENTS.";
55 return; 103 return;
56 } 104 }
57 105
58 ExtensionTestMessageListener done_listener("TEST_PASSED", false); 106 ExtensionTestMessageListener done_listener("TEST_PASSED", false);
59 done_listener.set_failure_message("TEST_FAILED"); 107 done_listener.set_failure_message("TEST_FAILED");
60 if (!content::ExecuteScript( 108 if (!content::ExecuteScript(
61 embedder_web_contents, 109 embedder_web_contents,
62 base::StringPrintf("runTest('%s', '%s')", 110 base::StringPrintf("runTest('%s', '%s')", test_name.c_str(),
63 test_name.c_str(),
64 app_to_embed.c_str()))) { 111 app_to_embed.c_str()))) {
65 LOG(ERROR) << "UNABLE TO START TEST."; 112 LOG(ERROR) << "UNABLE TO START TEST.";
66 return; 113 return;
67 } 114 }
68 ASSERT_TRUE(done_listener.WaitUntilSatisfied()); 115 ASSERT_TRUE(done_listener.WaitUntilSatisfied());
69 } 116 }
70 117
118 guest_view::TestGuestViewManager* test_guest_view_manager() const {
119 return test_guest_view_manager_;
120 }
121
71 private: 122 private:
72 void SetUpCommandLine(base::CommandLine* command_line) override { 123 void SetUpCommandLine(base::CommandLine* command_line) override {
73 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line); 124 extensions::PlatformAppBrowserTest::SetUpCommandLine(command_line);
74 } 125 }
75 126
127 void SetUpOnMainThread() override {
128 extensions::PlatformAppBrowserTest::SetUpOnMainThread();
129 test_guest_view_manager_ = static_cast<guest_view::TestGuestViewManager*>(
130 guest_view::GuestViewManager::CreateWithDelegate(
131 browser()->profile(),
132 scoped_ptr<guest_view::GuestViewManagerDelegate>(
133 new extensions::ExtensionsGuestViewManagerDelegate(
134 browser()->profile()))));
135 }
136
76 TestGuestViewManagerFactory factory_; 137 TestGuestViewManagerFactory factory_;
138 guest_view::TestGuestViewManager* test_guest_view_manager_;
139
140 DISALLOW_COPY_AND_ASSIGN(AppViewTest);
77 }; 141 };
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);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
216
217 IN_PROC_BROWSER_TEST_F(AppViewTest, KillGuestCommunicatingWithWrongAppView) {
218 const extensions::Extension* host_app =
219 LoadAndLaunchPlatformApp("app_view/host_app", "AppViewTest.LAUNCHED");
220 const extensions::Extension* mock_guest_extension =
221 InstallPlatformApp("app_view/guest_app");
222 const extensions::Extension* mock_bad_app =
223 LoadAndLaunchPlatformApp("app_view/bad_app", "AppViewTest.LAUNCHED");
224
225 EXPECT_TRUE(content::ExecuteScript(
226 extensions::AppWindowRegistry::Get(browser()->profile())
227 ->GetCurrentAppWindowForApp(host_app->id())
228 ->web_contents(),
229 base::StringPrintf("onAppCommand('%s', '%s');", "EMBED",
230 mock_guest_extension->id().c_str())));
231 ExtensionTestMessageListener on_embed_requested_listener(
232 "AppViewTest.EmbedRequested", true);
233 EXPECT_TRUE(on_embed_requested_listener.WaitUntilSatisfied());
234 // Now assume the bad application is somehow sending a message to complete a
235 // pending request to attach to <appview>. It should be killed.
236 content::RenderProcessHost* bad_app_render_process_host =
237 extensions::ProcessManager::Get(browser()->profile())
238 ->GetBackgroundHostForExtension(mock_bad_app->id())
239 ->render_process_host();
240 RenderProcessHostObserverForExit bad_app_obs(bad_app_render_process_host);
241 // Make the false request.
242 int guest_instance_id =
243 extensions::AppViewGuest::GetAllRegisteredInstanceIdsForTesting()[0];
244 extensions::AppViewGuest::CompletePendingRequest(
245 browser()->profile(), GURL("about:blank"), guest_instance_id,
246 mock_bad_app->id(), bad_app_render_process_host);
247
248 on_embed_requested_listener.Reply("continue");
249 // Make sure the bad application has been terminated.
250 bad_app_obs.WaitUntilRenderProcessHostKilled();
251 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/platform_apps/app_view/bad_app/background.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698