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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_host_browsertest.cc

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: Address two nits from original CL's comments by creis Created 8 years, 4 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
OLDNEW
(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 // This test loads a guest that has inifinite loop, therefore it hangs the guest
Charlie Reis 2012/08/24 00:28:32 nit: inifinite -> infinite
lazyboy 2012/08/25 01:32:51 Done.
72 // and eventually gets killed.
73 IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest, NavigateGuest) {
74 ASSERT_TRUE(test_server()->Start());
75 GURL test_url(test_server()->GetURL(
76 "files/browser_plugin_infinite_loop.html"));
77 NavigateToURL(shell(), test_url);
78
79 WebContentsImpl* embedder = static_cast<WebContentsImpl*>(
80 shell()->web_contents());
81 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
82 embedder->GetRenderViewHost());
83
84 BrowserPluginNotificationObserver update_rect_observer(
85 NOTIFICATION_BROWSER_PLUGIN_UPDATE_RECT,
86 content::NotificationService::AllSources());
87 test_url = test_server()->GetURL(
88 "files/browser_plugin_infinite_loop_child.html");
89 rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
90 StringPrintf("SetSrc('%s');", test_url.spec().c_str())));
91
92 update_rect_observer.Wait();
93 BrowserPluginHostEmbedderDelegate* embedder_browser_plugin =
94 embedder->GetEmbedderRole()->GetDelegate();
95 DCHECK(embedder_browser_plugin);
96
97 // Verify that we have a guest.
98 const ContainerInstanceMap& instance_map =
99 embedder_browser_plugin->guests_for_testing();
100 EXPECT_EQ(1u, instance_map.size());
101
102 WebKit::WebMouseEvent mouse_event;
103 mouse_event.type = WebInputEvent::MouseDown;
104 mouse_event.button = WebMouseEvent::ButtonMiddle;
105 mouse_event.x = 35;
106 mouse_event.y = 35;
107 mouse_event.globalX = 35;
108 mouse_event.globalY = 35;
109
110 IPC::Message* input_message = new ViewMsg_HandleInputEvent(
111 embedder->GetRenderViewHost()->GetRoutingID());
112 input_message->WriteData(reinterpret_cast<const char*>(&mouse_event),
113 sizeof(WebKit::WebMouseEvent));
114 embedder->GetRenderViewHost()->Send(input_message);
115
116 BrowserPluginNotificationObserver crash_observer(
117 NOTIFICATION_BROWSER_PLUGIN_GUEST_CRASHED,
118 content::NotificationService::AllSources());
119 crash_observer.Wait();
120 }
121
122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698