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 last_update_rect_width_(-1), | |
30 last_update_rect_height_(-1) { | |
31 // Override guest hang timeout for testing. | |
32 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.
| |
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 } // namespace content | |
OLD | NEW |