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

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: Rework tests to use timeouts instead of waiting indefinitely, not store any Guest* in embedder. 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..1101214e32c8f56966223537c10679da0ab34fd6
--- /dev/null
+++ b/content/browser/browser_plugin/test_browser_plugin_guest.cc
@@ -0,0 +1,114 @@
+// 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/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),
+ last_update_rect_width_(-1),
+ last_update_rect_height_(-1) {
+ // Override guest hang timeout for testing.
+ guest_hang_timeout_ms_ = (int)TestTimeouts::tiny_timeout().InMilliseconds();
awong 2012/09/10 23:57:32 Store guest_hang_timeout_ms_ as just a TimeDelta t
lazyboy 2012/09/11 19:58:39 Done.
+}
+
+TestBrowserPluginGuest::~TestBrowserPluginGuest() {
+}
+
+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);
+}
+
+bool TestBrowserPluginGuest::WaitForCrashed() {
+ // Check if we already observed a guest crash, return immediately if so.
+ if (crash_observed_)
+ return true;
+
+ crash_message_loop_runner_ = new MessageLoopRunner();
+ return TestTimeoutTracker::RunInActionTimeout(
+ crash_message_loop_runner_.get());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698