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 "base/test/test_timeouts.h" |
| 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 9 #include "content/browser/browser_plugin/test_timeout_tracker.h" |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/common/browser_plugin_messages.h" |
| 13 #include "content/public/test/test_utils.h" |
| 14 #include "ipc/ipc_channel_handle.h" |
| 15 #include "ipc/ipc_sync_message.h" |
| 16 #include "ui/gfx/size.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 class BrowserPluginGuest; |
| 21 |
| 22 TestBrowserPluginGuest::TestBrowserPluginGuest( |
| 23 int instance_id, |
| 24 WebContentsImpl* web_contents, |
| 25 RenderViewHost* render_view_host) |
| 26 : BrowserPluginGuest(instance_id, web_contents, render_view_host), |
| 27 update_rect_count_(0), |
| 28 crash_observed_(false), |
| 29 focus_observed_(false), |
| 30 advance_focus_observed_(false), |
| 31 last_update_rect_width_(-1), |
| 32 last_update_rect_height_(-1) { |
| 33 } |
| 34 |
| 35 TestBrowserPluginGuest::~TestBrowserPluginGuest() { |
| 36 } |
| 37 |
| 38 void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
| 39 if (msg->type() == BrowserPluginMsg_UpdateRect::ID) { |
| 40 PickleIterator iter(*msg); |
| 41 |
| 42 int instance_id; |
| 43 int message_id; |
| 44 BrowserPluginMsg_UpdateRect_Params update_rect_params; |
| 45 |
| 46 if (!IPC::ReadParam(msg, &iter, &instance_id) || |
| 47 !IPC::ReadParam(msg, &iter, &message_id) || |
| 48 !IPC::ReadParam(msg, &iter, &update_rect_params)) { |
| 49 NOTREACHED() << |
| 50 "Cannot read BrowserPluginMsg_UpdateRect params from ipc message"; |
| 51 } |
| 52 last_update_rect_width_ = update_rect_params.view_size.width(); |
| 53 last_update_rect_height_ = update_rect_params.view_size.height(); |
| 54 update_rect_count_++; |
| 55 if (waiting_for_update_rect_msg_with_size_ && |
| 56 expected_width_ == last_update_rect_width_ && |
| 57 expected_height_ == last_update_rect_height_) { |
| 58 waiting_for_update_rect_msg_with_size_ = false; |
| 59 if (send_message_loop_runner_) |
| 60 send_message_loop_runner_->Quit(); |
| 61 } else if (!waiting_for_update_rect_msg_with_size_) { |
| 62 if (send_message_loop_runner_) |
| 63 send_message_loop_runner_->Quit(); |
| 64 } |
| 65 } |
| 66 BrowserPluginGuest::SendMessageToEmbedder(msg); |
| 67 } |
| 68 |
| 69 bool TestBrowserPluginGuest::WaitForUpdateRectMsg() { |
| 70 // Check if we already got any UpdateRect message. |
| 71 if (update_rect_count_ > 0) |
| 72 return true; |
| 73 |
| 74 send_message_loop_runner_ = new MessageLoopRunner(); |
| 75 return TestTimeoutTracker::RunInActionTimeout( |
| 76 send_message_loop_runner_.get()); |
| 77 } |
| 78 |
| 79 bool TestBrowserPluginGuest::WaitForUpdateRectMsgWithSize(int width, |
| 80 int height) { |
| 81 if (update_rect_count_ > 0 && |
| 82 last_update_rect_width_ == width && |
| 83 last_update_rect_height_ == height) { |
| 84 // We already saw this message. |
| 85 return true; |
| 86 } |
| 87 waiting_for_update_rect_msg_with_size_ = true; |
| 88 expected_width_ = width; |
| 89 expected_height_ = height; |
| 90 |
| 91 send_message_loop_runner_ = new MessageLoopRunner(); |
| 92 return TestTimeoutTracker::RunInActionTimeout( |
| 93 send_message_loop_runner_.get()); |
| 94 } |
| 95 |
| 96 void TestBrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { |
| 97 crash_observed_ = true; |
| 98 LOG(INFO) << "Guest crashed"; |
| 99 if (crash_message_loop_runner_) |
| 100 crash_message_loop_runner_->Quit(); |
| 101 BrowserPluginGuest::RenderViewGone(status); |
| 102 } |
| 103 |
| 104 bool TestBrowserPluginGuest::WaitForCrashed() { |
| 105 // Check if we already observed a guest crash, return immediately if so. |
| 106 if (crash_observed_) |
| 107 return true; |
| 108 |
| 109 crash_message_loop_runner_ = new MessageLoopRunner(); |
| 110 return TestTimeoutTracker::RunInActionTimeout( |
| 111 crash_message_loop_runner_.get()); |
| 112 } |
| 113 |
| 114 bool TestBrowserPluginGuest::WaitForFocus() { |
| 115 if (focus_observed_) |
| 116 return true; |
| 117 focus_message_loop_runner_ = new MessageLoopRunner(); |
| 118 return TestTimeoutTracker::RunInActionTimeout( |
| 119 focus_message_loop_runner_.get()); |
| 120 } |
| 121 |
| 122 bool TestBrowserPluginGuest::WaitForAdvanceFocus() { |
| 123 if (advance_focus_observed_) |
| 124 return true; |
| 125 advance_focus_message_loop_runner_ = new MessageLoopRunner(); |
| 126 return TestTimeoutTracker::RunInActionTimeout( |
| 127 advance_focus_message_loop_runner_.get()); |
| 128 } |
| 129 |
| 130 void TestBrowserPluginGuest::SetFocus(bool focused) { |
| 131 focus_observed_ = true; |
| 132 if (focus_message_loop_runner_) |
| 133 focus_message_loop_runner_->Quit(); |
| 134 BrowserPluginGuest::SetFocus(focused); |
| 135 } |
| 136 |
| 137 bool TestBrowserPluginGuest::ViewTakeFocus(bool reverse) { |
| 138 advance_focus_observed_ = true; |
| 139 if (advance_focus_message_loop_runner_) |
| 140 advance_focus_message_loop_runner_->Quit(); |
| 141 return BrowserPluginGuest::ViewTakeFocus(reverse); |
| 142 } |
| 143 |
| 144 } // namespace content |
OLD | NEW |