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 "content/browser/browser_plugin/test_browser_plugin_guest.h" |
| 6 |
| 7 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/common/browser_plugin_messages.h" |
| 11 #include "content/public/test/test_utils.h" |
| 12 #include "ipc/ipc_channel_handle.h" |
| 13 #include "ipc/ipc_sync_message.h" |
| 14 #include "ui/gfx/size.h" |
| 15 |
| 16 namespace content { |
| 17 |
| 18 class BrowserPluginGuest; |
| 19 |
| 20 TestBrowserPluginGuest::TestBrowserPluginGuest( |
| 21 int instance_id, |
| 22 WebContentsImpl* web_contents, |
| 23 RenderViewHost* render_view_host) |
| 24 : BrowserPluginGuest(instance_id, web_contents, render_view_host), |
| 25 update_rect_count_(0), |
| 26 crash_observed_(false), |
| 27 last_update_rect_width_(-1), |
| 28 last_update_rect_height_(-1) { |
| 29 } |
| 30 |
| 31 TestBrowserPluginGuest::~TestBrowserPluginGuest() { |
| 32 } |
| 33 |
| 34 void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 35 if (msg->type() == BrowserPluginMsg_UpdateRect::ID) { |
| 36 PickleIterator iter(*msg); |
| 37 |
| 38 int instance_id; |
| 39 int message_id; |
| 40 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
| 41 |
| 42 if (!IPC::ReadParam(msg, &iter, &instance_id) || |
| 43 !IPC::ReadParam(msg, &iter, &message_id) || |
| 44 !IPC::ReadParam(msg, &iter, &update_rect_params)) { |
| 45 NOTREACHED() << |
| 46 "Cannot read BrowserPluginMsg_UpdateRect params from ipc message"; |
| 47 } |
| 48 last_update_rect_width_ = update_rect_params.view_size.width(); |
| 49 last_update_rect_height_ = update_rect_params.view_size.height(); |
| 50 update_rect_count_++; |
| 51 if (waiting_for_update_rect_msg_with_size_ && |
| 52 expected_width_ == last_update_rect_width_ && |
| 53 expected_height_ == last_update_rect_height_) { |
| 54 waiting_for_update_rect_msg_with_size_ = false; |
| 55 if (send_message_loop_runner_) |
| 56 send_message_loop_runner_->Quit(); |
| 57 } else if (!waiting_for_update_rect_msg_with_size_) { |
| 58 if (send_message_loop_runner_) |
| 59 send_message_loop_runner_->Quit(); |
| 60 } |
| 61 } |
| 62 BrowserPluginGuest::SendMessageToEmbedder(msg); |
| 63 } |
| 64 |
| 65 void TestBrowserPluginGuest::WaitForUpdateRectMsg() { |
| 66 // Check if we already got any UpdateRect message. |
| 67 if (update_rect_count_ > 0) |
| 68 return; |
| 69 send_message_loop_runner_= new MessageLoopRunner(); |
| 70 send_message_loop_runner_->Run(); |
| 71 } |
| 72 |
| 73 void TestBrowserPluginGuest::WaitForUpdateRectMsgWithSize(int width, |
| 74 int height) { |
| 75 if (update_rect_count_ > 0 && |
| 76 last_update_rect_width_ == width && |
| 77 last_update_rect_height_ == height) { |
| 78 // We already saw this message. |
| 79 return; |
| 80 } |
| 81 waiting_for_update_rect_msg_with_size_ = true; |
| 82 expected_width_ = width; |
| 83 expected_height_ = height; |
| 84 send_message_loop_runner_= new MessageLoopRunner(); |
| 85 send_message_loop_runner_->Run(); |
| 86 } |
| 87 |
| 88 void TestBrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { |
| 89 crash_observed_ = true; |
| 90 if (crash_message_loop_runner_) |
| 91 crash_message_loop_runner_->Quit(); |
| 92 BrowserPluginGuest::RenderViewGone(status); |
| 93 } |
| 94 |
| 95 void TestBrowserPluginGuest::WaitForCrashed() { |
| 96 // Check if we already observed a guest crash, return immediately if so. |
| 97 if (crash_observed_) |
| 98 return; |
| 99 crash_message_loop_runner_ = new MessageLoopRunner(); |
| 100 crash_message_loop_runner_->Run(); |
| 101 } |
| 102 |
| 103 } // namespace content |
OLD | NEW |