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/renderer_host/render_view_host_impl.h" | |
8 #include "content/browser/web_contents/web_contents_impl.h" | |
9 #include "content/common/view_messages.h" | |
10 #include "content/public/browser/notification_service.h" | |
11 #include "content/public/browser/notification_types.h" | |
12 #include "content/public/test/test_utils.h" | |
13 #include "content/shell/shell.h" | |
14 #include "content/test/content_browser_test_utils.h" | |
15 #include "content/test/content_browser_test.h" | |
16 #include "ipc/ipc_message.h" | |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | |
18 | |
19 using WebKit::WebInputEvent; | |
20 using WebKit::WebMouseEvent; | |
21 | |
22 namespace content { | |
23 // Watches for an GuestCrashed notification. | |
Charlie Reis
2012/08/13 17:50:14
nit: an -> a
| |
24 class BrowserPluginNotificationObserver : | |
25 public content::NotificationObserver { | |
26 public: | |
27 BrowserPluginNotificationObserver( | |
28 int notification_type, | |
29 const content::NotificationSource& source) : | |
30 ran_(false), | |
31 notification_type_(notification_type) { | |
32 registrar_.Add(this, notification_type, source); | |
33 } | |
34 virtual ~BrowserPluginNotificationObserver() {} | |
35 | |
36 // Wait for notification to arrive. | |
37 void Wait() { | |
38 if (!ran_) { | |
39 message_loop_runner_ = new MessageLoopRunner(); | |
40 message_loop_runner_->Run(); | |
41 } | |
42 } | |
43 | |
44 // Overridden content::NotificationObserver methods. | |
45 virtual void Observe(int type, | |
46 const content::NotificationSource& source, | |
47 const content::NotificationDetails& details) OVERRIDE { | |
48 if (type == notification_type_) { | |
49 if (message_loop_runner_.get()) { | |
50 message_loop_runner_->Quit(); | |
51 } else { | |
52 ran_ = true; | |
53 } | |
54 } | |
55 } | |
56 private: | |
57 bool ran_; | |
Charlie Reis
2012/08/13 17:50:14
nit: observed_
| |
58 content::NotificationRegistrar registrar_; | |
59 scoped_refptr<MessageLoopRunner> message_loop_runner_; | |
60 int notification_type_; | |
61 DISALLOW_COPY_AND_ASSIGN(BrowserPluginNotificationObserver); | |
62 }; | |
63 | |
64 class BrowserPluginHostTest : public ContentBrowserTest { | |
65 public: | |
66 BrowserPluginHostTest() {} | |
67 }; | |
68 | |
69 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, | |
Charlie Reis
2012/08/13 17:50:14
It would really help to describe a bit of what you
| |
70 NavigateOrCreateGuest) { | |
Charlie Reis
2012/08/13 17:50:14
Ditto: NavigateGuest
| |
71 ASSERT_TRUE(test_server()->Start()); | |
72 GURL test_url(test_server()->GetURL( | |
73 "files/browser_plugin_infinite_loop.html")); | |
74 NavigateToURL(shell(), test_url); | |
75 | |
76 WebContentsImpl* embedder = static_cast<WebContentsImpl*>( | |
77 shell()->web_contents()); | |
78 BrowserPluginHost* browser_plugin_host = embedder->browser_plugin_host(); | |
79 DCHECK(browser_plugin_host); | |
80 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | |
81 embedder->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 // Verify that we have a guest. | |
93 const ContainerInstanceMap& instance_map = | |
94 browser_plugin_host->guests_for_testing(); | |
95 EXPECT_EQ(1u, instance_map.size()); | |
96 | |
97 WebKit::WebMouseEvent mouse_event; | |
98 mouse_event.type = WebInputEvent::MouseDown; | |
99 mouse_event.button = WebMouseEvent::ButtonMiddle; | |
100 mouse_event.x = 35; | |
101 mouse_event.y = 35; | |
102 mouse_event.globalX = 35; | |
103 mouse_event.globalY = 35; | |
104 | |
105 IPC::Message* input_message = new ViewMsg_HandleInputEvent( | |
106 embedder->GetRenderViewHost()->GetRoutingID()); | |
107 input_message->WriteData(reinterpret_cast<const char*>(&mouse_event), | |
108 sizeof(WebKit::WebMouseEvent)); | |
109 embedder->GetRenderViewHost()->Send(input_message); | |
110 | |
111 BrowserPluginNotificationObserver crash_observer( | |
112 NOTIFICATION_BROWSER_PLUGIN_GUEST_CRASHED, | |
113 content::NotificationService::AllSources()); | |
114 crash_observer.Wait(); | |
Charlie Reis
2012/08/13 17:50:14
I still wonder about the kill behavior here. A 5
| |
115 } | |
116 | |
117 } | |
OLD | NEW |