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