OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/run_loop.h" | |
6 #include "base/utf_string_conversions.h" | |
7 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | |
8 #include "content/browser/renderer_host/render_view_host_impl.h" | |
9 #include "content/browser/web_contents/web_contents_impl.h" | |
10 #include "content/common/view_messages.h" | |
11 #include "content/public/browser/notification_service.h" | |
12 #include "content/public/browser/notification_types.h" | |
13 #include "content/public/test/test_utils.h" | |
14 #include "content/shell/shell.h" | |
15 #include "content/test/content_browser_test_utils.h" | |
16 #include "content/test/content_browser_test.h" | |
17 #include "ipc/ipc_message.h" | |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | |
19 | |
20 using WebKit::WebInputEvent; | |
21 using WebKit::WebMouseEvent; | |
22 | |
23 namespace content { | |
24 // Watches for a GuestCrashed notification. | |
25 class BrowserPluginNotificationObserver : | |
26 public content::NotificationObserver { | |
27 public: | |
28 BrowserPluginNotificationObserver( | |
29 int notification_type, | |
30 const content::NotificationSource& source) : | |
31 observed_(false), | |
32 notification_type_(notification_type) { | |
33 registrar_.Add(this, notification_type, source); | |
34 } | |
35 virtual ~BrowserPluginNotificationObserver() {} | |
36 | |
37 // Wait for notification to arrive. | |
38 void Wait() { | |
39 if (!observed_) { | |
40 message_loop_runner_ = new MessageLoopRunner(); | |
41 message_loop_runner_->Run(); | |
42 } | |
43 } | |
44 | |
45 // Overridden content::NotificationObserver methods. | |
46 virtual void Observe(int type, | |
47 const content::NotificationSource& source, | |
48 const content::NotificationDetails& details) OVERRIDE { | |
49 if (type == notification_type_) { | |
50 if (message_loop_runner_.get()) { | |
51 message_loop_runner_->Quit(); | |
52 } else { | |
53 observed_ = true; | |
54 } | |
55 } | |
56 } | |
57 private: | |
58 bool observed_; | |
59 content::NotificationRegistrar registrar_; | |
60 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
61 int notification_type_; | |
62 DISALLOW_COPY_AND_ASSIGN(BrowserPluginNotificationObserver); | |
63 }; | |
64 | |
65 class BrowserPluginHostTest : public ContentBrowserTest { | |
66 public: | |
67 BrowserPluginHostTest() {} | |
68 }; | |
69 | |
70 // This test loads a guest that has infinite loop, therefore it hangs the guest | |
71 // and eventually gets killed. | |
72 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateGuest) { | |
73 ASSERT_TRUE(test_server()->Start()); | |
74 GURL test_url(test_server()->GetURL( | |
75 "files/browser_plugin_infinite_loop.html")); | |
76 NavigateToURL(shell(), test_url); | |
77 | |
78 WebContentsImpl* embedder_web_contents = static_cast<WebContentsImpl*>( | |
79 shell()->web_contents()); | |
Charlie Reis
2012/08/27 20:23:59
nit: Wrong indent.
lazyboy
2012/08/28 19:07:14
Done.
| |
80 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
81 embedder_web_contents->GetRenderViewHost()); | |
82 | |
83 BrowserPluginNotificationObserver update_rect_observer( | |
84 NOTIFICATION_BROWSER_PLUGIN_UPDATE_RECT, | |
85 content::NotificationService::AllSources()); | |
86 test_url = test_server()->GetURL( | |
87 "files/browser_plugin_infinite_loop_child.html"); | |
88 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16( | |
89 StringPrintf("SetSrc('%s');", test_url.spec().c_str()))); | |
90 | |
91 update_rect_observer.Wait(); | |
92 BrowserPluginEmbedder* embedder_browser_plugin = | |
93 embedder_web_contents->GetBrowserPluginEmbedder(); | |
94 DCHECK(embedder_browser_plugin); | |
95 | |
96 // Verify that we have a guest. | |
97 const ContainerInstanceMap& instance_map = | |
98 embedder_browser_plugin->guests_for_testing(); | |
99 EXPECT_EQ(1u, instance_map.size()); | |
100 | |
101 WebKit::WebMouseEvent mouse_event; | |
102 mouse_event.type = WebInputEvent::MouseDown; | |
103 mouse_event.button = WebMouseEvent::ButtonMiddle; | |
104 mouse_event.x = 35; | |
105 mouse_event.y = 35; | |
106 mouse_event.globalX = 35; | |
107 mouse_event.globalY = 35; | |
108 | |
109 IPC::Message* input_message = new ViewMsg_HandleInputEvent( | |
110 embedder_web_contents->GetRenderViewHost()->GetRoutingID()); | |
111 input_message->WriteData(reinterpret_cast<const char*>(&mouse_event), | |
112 sizeof(WebKit::WebMouseEvent)); | |
113 embedder_web_contents->GetRenderViewHost()->Send(input_message); | |
114 | |
115 BrowserPluginNotificationObserver crash_observer( | |
116 NOTIFICATION_BROWSER_PLUGIN_GUEST_CRASHED, | |
117 content::NotificationService::AllSources()); | |
118 crash_observer.Wait(); | |
119 } | |
120 | |
121 } | |
OLD | NEW |