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

Unified Diff: content/browser/browser_plugin/test_browser_plugin_guest.cc

Issue 10868012: Browser Plugin: New Implementation (Browser Side) (Closed) Base URL: http://git.chromium.org/chromium/src.git@master-trial-obrowser
Patch Set: @tott + Address comments + fix win_rel trybot flakiness Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/browser_plugin/test_browser_plugin_guest.cc
diff --git a/content/browser/browser_plugin/test_browser_plugin_guest.cc b/content/browser/browser_plugin/test_browser_plugin_guest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..45c039ce66eceada6fbd9312053cbc9bc371c9a0
--- /dev/null
+++ b/content/browser/browser_plugin/test_browser_plugin_guest.cc
@@ -0,0 +1,181 @@
+// 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 "content/browser/browser_plugin/test_browser_plugin_guest.h"
+
+#include "base/test/test_timeouts.h"
+#include "content/browser/browser_plugin/browser_plugin_guest.h"
+#include "content/browser/browser_plugin/test_timeout_tracker.h"
+#include "content/browser/renderer_host/render_view_host_impl.h"
+#include "content/browser/web_contents/web_contents_impl.h"
+#include "content/common/browser_plugin_messages.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_types.h"
+#include "content/public/test/test_utils.h"
+#include "ipc/ipc_channel_handle.h"
+#include "ipc/ipc_sync_message.h"
+#include "ui/gfx/size.h"
+
+namespace content {
+
+class BrowserPluginGuest;
+
+TestBrowserPluginGuest::TestBrowserPluginGuest(
+ int instance_id,
+ WebContentsImpl* web_contents,
+ RenderViewHost* render_view_host)
+ : BrowserPluginGuest(instance_id, web_contents, render_view_host),
+ update_rect_count_(0),
+ crash_observed_(false),
+ focus_observed_(false),
+ advance_focus_observed_(false),
+ was_hidden_observed_(false),
+ waiting_for_update_rect_msg_with_size_(false),
+ last_update_rect_width_(-1),
+ last_update_rect_height_(-1) {
+ // Listen to visibility changes so that a test can wait for these changes.
+ registrar_.Add(this,
+ NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
+ Source<WebContents>(web_contents));
+}
+
+TestBrowserPluginGuest::~TestBrowserPluginGuest() {
+}
+
+void TestBrowserPluginGuest::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ switch (type) {
+ case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
+ bool visible = *Details<bool>(details).ptr();
+ if (!visible) {
+ was_hidden_observed_ = true;
+ if (was_hidden_message_loop_runner_)
+ was_hidden_message_loop_runner_->Quit();
+ }
+ break;
+ }
+ default:
+ NOTREACHED() << "Unexpected notification type: " << type;
+ }
+}
+
+void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
+ if (msg->type() == BrowserPluginMsg_UpdateRect::ID) {
+ PickleIterator iter(*msg);
+
+ int instance_id;
+ int message_id;
+ BrowserPluginMsg_UpdateRect_Params update_rect_params;
+
+ if (!IPC::ReadParam(msg, &iter, &instance_id) ||
+ !IPC::ReadParam(msg, &iter, &message_id) ||
+ !IPC::ReadParam(msg, &iter, &update_rect_params)) {
+ NOTREACHED() <<
+ "Cannot read BrowserPluginMsg_UpdateRect params from ipc message";
+ }
+ last_update_rect_width_ = update_rect_params.view_size.width();
+ last_update_rect_height_ = update_rect_params.view_size.height();
+ update_rect_count_++;
+ if (waiting_for_update_rect_msg_with_size_ &&
+ expected_width_ == last_update_rect_width_ &&
+ expected_height_ == last_update_rect_height_) {
+ waiting_for_update_rect_msg_with_size_ = false;
+ if (send_message_loop_runner_)
+ send_message_loop_runner_->Quit();
+ } else if (!waiting_for_update_rect_msg_with_size_) {
+ if (send_message_loop_runner_)
+ send_message_loop_runner_->Quit();
+ }
+ }
+ BrowserPluginGuest::SendMessageToEmbedder(msg);
+}
+
+bool TestBrowserPluginGuest::WaitForUpdateRectMsg() {
+ // Check if we already got any UpdateRect message.
+ if (update_rect_count_ > 0)
+ return true;
+ send_message_loop_runner_ = new MessageLoopRunner();
+ return TestTimeoutTracker::RunInActionTimeout(
+ send_message_loop_runner_.get());
+}
+
+bool TestBrowserPluginGuest::WaitForUpdateRectMsgWithSize(int width,
+ int height) {
+ if (update_rect_count_ > 0 &&
+ last_update_rect_width_ == width &&
+ last_update_rect_height_ == height) {
+ // We already saw this message.
+ return true;
+ }
+ waiting_for_update_rect_msg_with_size_ = true;
+ expected_width_ = width;
+ expected_height_ = height;
+
+ send_message_loop_runner_ = new MessageLoopRunner();
+ return TestTimeoutTracker::RunInActionTimeout(
+ send_message_loop_runner_.get());
+}
+
+void TestBrowserPluginGuest::RenderViewGone(base::TerminationStatus status) {
+ crash_observed_ = true;
+ LOG(INFO) << "Guest crashed";
+ if (crash_message_loop_runner_)
+ crash_message_loop_runner_->Quit();
+ BrowserPluginGuest::RenderViewGone(status);
+}
+
+void TestBrowserPluginGuest::WaitForCrashed() {
+ // Check if we already observed a guest crash, return immediately if so.
+ if (crash_observed_)
+ return;
+
+ crash_message_loop_runner_ = new MessageLoopRunner();
+ crash_message_loop_runner_->Run();
+}
+
+bool TestBrowserPluginGuest::WaitForFocus() {
+ if (focus_observed_)
+ return true;
+ focus_message_loop_runner_ = new MessageLoopRunner();
+ return TestTimeoutTracker::RunInActionTimeout(
+ focus_message_loop_runner_.get());
+}
+
+bool TestBrowserPluginGuest::WaitForAdvanceFocus() {
+ if (advance_focus_observed_)
+ return true;
+ advance_focus_message_loop_runner_ = new MessageLoopRunner();
+ return TestTimeoutTracker::RunInActionTimeout(
+ advance_focus_message_loop_runner_.get());
+}
+
+bool TestBrowserPluginGuest::WaitUntilHidden() {
+ if (was_hidden_observed_) {
+ was_hidden_observed_ = false;
+ return true;
+ }
+ was_hidden_message_loop_runner_ = new MessageLoopRunner();
+ bool action_observed = TestTimeoutTracker::RunInActionTimeout(
+ was_hidden_message_loop_runner_.get());
+ if (action_observed)
+ was_hidden_observed_ = false;
+ return action_observed;
+}
+
+void TestBrowserPluginGuest::SetFocus(bool focused) {
+ focus_observed_ = true;
+ if (focus_message_loop_runner_)
+ focus_message_loop_runner_->Quit();
+ BrowserPluginGuest::SetFocus(focused);
+}
+
+bool TestBrowserPluginGuest::ViewTakeFocus(bool reverse) {
+ advance_focus_observed_ = true;
+ if (advance_focus_message_loop_runner_)
+ advance_focus_message_loop_runner_->Quit();
+ return BrowserPluginGuest::ViewTakeFocus(reverse);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698