| Index: content/browser/browser_plugin/browser_plugin_host_browsertest.cc
|
| diff --git a/content/browser/browser_plugin/browser_plugin_host_browsertest.cc b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..bde878d0dd58c1b3d5feed5be42901c0f3bcf961
|
| --- /dev/null
|
| +++ b/content/browser/browser_plugin/browser_plugin_host_browsertest.cc
|
| @@ -0,0 +1,117 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/run_loop.h"
|
| +#include "base/utf_string_conversions.h"
|
| +#include "content/browser/renderer_host/render_view_host_impl.h"
|
| +#include "content/browser/web_contents/web_contents_impl.h"
|
| +#include "content/common/view_messages.h"
|
| +#include "content/public/browser/notification_service.h"
|
| +#include "content/public/browser/notification_types.h"
|
| +#include "content/public/test/test_utils.h"
|
| +#include "content/shell/shell.h"
|
| +#include "content/test/content_browser_test_utils.h"
|
| +#include "content/test/content_browser_test.h"
|
| +#include "ipc/ipc_message.h"
|
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
|
| +
|
| +using WebKit::WebInputEvent;
|
| +using WebKit::WebMouseEvent;
|
| +
|
| +namespace content {
|
| +// Watches for an GuestCrashed notification.
|
| +class BrowserPluginNotificationObserver :
|
| + public content::NotificationObserver {
|
| + public:
|
| + BrowserPluginNotificationObserver(
|
| + int notification_type,
|
| + const content::NotificationSource& source) :
|
| + ran_(false),
|
| + notification_type_(notification_type) {
|
| + registrar_.Add(this, notification_type, source);
|
| + }
|
| + virtual ~BrowserPluginNotificationObserver() {}
|
| +
|
| + // Wait for notification to arrive.
|
| + void Wait() {
|
| + if (!ran_) {
|
| + message_loop_runner_ = new MessageLoopRunner();
|
| + message_loop_runner_->Run();
|
| + }
|
| + }
|
| +
|
| + // Overridden content::NotificationObserver methods.
|
| + virtual void Observe(int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) OVERRIDE {
|
| + if (type == notification_type_) {
|
| + if (message_loop_runner_.get()) {
|
| + message_loop_runner_->Quit();
|
| + } else {
|
| + ran_ = true;
|
| + }
|
| + }
|
| + }
|
| + private:
|
| + bool ran_;
|
| + content::NotificationRegistrar registrar_;
|
| + scoped_refptr<MessageLoopRunner> message_loop_runner_;
|
| + int notification_type_;
|
| + DISALLOW_COPY_AND_ASSIGN(BrowserPluginNotificationObserver);
|
| +};
|
| +
|
| +class BrowserPluginHostTest : public ContentBrowserTest {
|
| + public:
|
| + BrowserPluginHostTest() {}
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(BrowserPluginHostTest,
|
| + NavigateOrCreateGuest) {
|
| + ASSERT_TRUE(test_server()->Start());
|
| + GURL test_url(test_server()->GetURL(
|
| + "files/browser_plugin_infinite_loop.html"));
|
| + NavigateToURL(shell(), test_url);
|
| +
|
| + WebContentsImpl* embedder = static_cast<WebContentsImpl*>(
|
| + shell()->web_contents());
|
| + BrowserPluginHost* browser_plugin_host = embedder->browser_plugin_host();
|
| + DCHECK(browser_plugin_host);
|
| + RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>(
|
| + embedder->GetRenderViewHost());
|
| +
|
| + BrowserPluginNotificationObserver update_rect_observer(
|
| + NOTIFICATION_BROWSER_PLUGIN_UPDATE_RECT,
|
| + content::NotificationService::AllSources());
|
| + test_url = test_server()->GetURL(
|
| + "files/browser_plugin_infinite_loop_child.html");
|
| + rvh->ExecuteJavascriptAndGetValue(string16(), ASCIIToUTF16(
|
| + StringPrintf("SetSrc('%s');", test_url.spec().c_str())));
|
| +
|
| + update_rect_observer.Wait();
|
| + // Verify that we have a guest.
|
| + const ContainerInstanceMap& instance_map =
|
| + browser_plugin_host->guests_for_testing();
|
| + EXPECT_EQ(1u, instance_map.size());
|
| +
|
| + WebKit::WebMouseEvent mouse_event;
|
| + mouse_event.type = WebInputEvent::MouseDown;
|
| + mouse_event.button = WebMouseEvent::ButtonMiddle;
|
| + mouse_event.x = 35;
|
| + mouse_event.y = 35;
|
| + mouse_event.globalX = 35;
|
| + mouse_event.globalY = 35;
|
| +
|
| + IPC::Message* input_message = new ViewMsg_HandleInputEvent(
|
| + embedder->GetRenderViewHost()->GetRoutingID());
|
| + input_message->WriteData(reinterpret_cast<const char*>(&mouse_event),
|
| + sizeof(WebKit::WebMouseEvent));
|
| + embedder->GetRenderViewHost()->Send(input_message);
|
| +
|
| + BrowserPluginNotificationObserver crash_observer(
|
| + NOTIFICATION_BROWSER_PLUGIN_GUEST_CRASHED,
|
| + content::NotificationService::AllSources());
|
| + crash_observer.Wait();
|
| +}
|
| +
|
| +}
|
|
|