OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/test_browser_plugin_guest.h" |
6 | 6 |
7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | |
9 #include "content/browser/renderer_host/render_view_host_impl.h" | 8 #include "content/browser/renderer_host/render_view_host_impl.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
11 #include "content/common/browser_plugin_messages.h" | 10 #include "content/common/browser_plugin_messages.h" |
12 #include "content/public/browser/notification_observer.h" | |
13 #include "content/public/browser/notification_types.h" | 11 #include "content/public/browser/notification_types.h" |
14 #include "content/public/test/test_utils.h" | |
15 #include "ui/gfx/size.h" | |
16 | 12 |
17 namespace content { | 13 namespace content { |
18 | 14 |
19 class BrowserPluginGuest; | 15 class BrowserPluginGuest; |
20 | 16 |
21 TestBrowserPluginGuest::TestBrowserPluginGuest( | 17 TestBrowserPluginGuest::TestBrowserPluginGuest( |
22 int instance_id, | 18 int instance_id, |
23 WebContentsImpl* web_contents, | 19 WebContentsImpl* web_contents, |
24 RenderViewHost* render_view_host) | 20 RenderViewHost* render_view_host) |
25 : BrowserPluginGuest(instance_id, web_contents, render_view_host), | 21 : BrowserPluginGuest(instance_id, web_contents, render_view_host), |
26 update_rect_count_(0), | 22 update_rect_count_(0), |
| 23 damage_buffer_call_count_(0), |
27 crash_observed_(false), | 24 crash_observed_(false), |
28 focus_observed_(false), | 25 focus_observed_(false), |
29 advance_focus_observed_(false), | 26 advance_focus_observed_(false), |
30 was_hidden_observed_(false), | 27 was_hidden_observed_(false), |
31 stop_observed_(false), | 28 stop_observed_(false), |
32 reload_observed_(false), | 29 reload_observed_(false), |
33 waiting_for_update_rect_msg_with_size_(false), | 30 waiting_for_damage_buffer_with_size_(false), |
34 last_update_rect_width_(-1), | 31 last_damage_buffer_size_(gfx::Size(0, 0)) { |
35 last_update_rect_height_(-1) { | |
36 // Listen to visibility changes so that a test can wait for these changes. | 32 // Listen to visibility changes so that a test can wait for these changes. |
37 registrar_.Add(this, | 33 registrar_.Add(this, |
38 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, | 34 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
39 Source<WebContents>(web_contents)); | 35 Source<WebContents>(web_contents)); |
40 } | 36 } |
41 | 37 |
42 TestBrowserPluginGuest::~TestBrowserPluginGuest() { | 38 TestBrowserPluginGuest::~TestBrowserPluginGuest() { |
43 } | 39 } |
44 | 40 |
45 void TestBrowserPluginGuest::Observe(int type, | 41 void TestBrowserPluginGuest::Observe(int type, |
46 const NotificationSource& source, | 42 const NotificationSource& source, |
47 const NotificationDetails& details) { | 43 const NotificationDetails& details) { |
48 switch (type) { | 44 switch (type) { |
49 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { | 45 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: { |
50 bool visible = *Details<bool>(details).ptr(); | 46 bool visible = *Details<bool>(details).ptr(); |
51 if (!visible) { | 47 if (!visible) { |
52 was_hidden_observed_ = true; | 48 was_hidden_observed_ = true; |
53 if (was_hidden_message_loop_runner_) | 49 if (was_hidden_message_loop_runner_) |
54 was_hidden_message_loop_runner_->Quit(); | 50 was_hidden_message_loop_runner_->Quit(); |
55 } | 51 } |
56 break; | 52 break; |
57 } | 53 } |
58 default: | 54 default: |
59 NOTREACHED() << "Unexpected notification type: " << type; | 55 NOTREACHED() << "Unexpected notification type: " << type; |
60 } | 56 } |
61 } | 57 } |
62 | 58 |
63 void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { | 59 void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) { |
64 if (msg->type() == BrowserPluginMsg_UpdateRect::ID) { | 60 if (msg->type() == BrowserPluginMsg_UpdateRect::ID) { |
65 PickleIterator iter(*msg); | |
66 | |
67 int instance_id; | |
68 int message_id; | |
69 BrowserPluginMsg_UpdateRect_Params update_rect_params; | |
70 | |
71 if (!IPC::ReadParam(msg, &iter, &instance_id) || | |
72 !IPC::ReadParam(msg, &iter, &message_id) || | |
73 !IPC::ReadParam(msg, &iter, &update_rect_params)) { | |
74 NOTREACHED() << | |
75 "Cannot read BrowserPluginMsg_UpdateRect params from ipc message"; | |
76 } | |
77 last_update_rect_width_ = update_rect_params.view_size.width(); | |
78 last_update_rect_height_ = update_rect_params.view_size.height(); | |
79 update_rect_count_++; | 61 update_rect_count_++; |
80 if (waiting_for_update_rect_msg_with_size_ && | 62 if (send_message_loop_runner_) |
81 expected_width_ == last_update_rect_width_ && | 63 send_message_loop_runner_->Quit(); |
82 expected_height_ == last_update_rect_height_) { | |
83 waiting_for_update_rect_msg_with_size_ = false; | |
84 if (send_message_loop_runner_) | |
85 send_message_loop_runner_->Quit(); | |
86 } else if (!waiting_for_update_rect_msg_with_size_) { | |
87 if (send_message_loop_runner_) | |
88 send_message_loop_runner_->Quit(); | |
89 } | |
90 } | 64 } |
91 BrowserPluginGuest::SendMessageToEmbedder(msg); | 65 BrowserPluginGuest::SendMessageToEmbedder(msg); |
92 } | 66 } |
93 | 67 |
94 void TestBrowserPluginGuest::WaitForUpdateRectMsg() { | 68 void TestBrowserPluginGuest::WaitForUpdateRectMsg() { |
95 // Check if we already got any UpdateRect message. | 69 // Check if we already got any UpdateRect message. |
96 if (update_rect_count_ > 0) | 70 if (update_rect_count_ > 0) |
97 return; | 71 return; |
98 send_message_loop_runner_ = new MessageLoopRunner(); | 72 send_message_loop_runner_ = new MessageLoopRunner(); |
99 send_message_loop_runner_->Run(); | 73 send_message_loop_runner_->Run(); |
100 } | 74 } |
101 | 75 |
102 void TestBrowserPluginGuest::ResetUpdateRectCount() { | 76 void TestBrowserPluginGuest::ResetUpdateRectCount() { |
103 update_rect_count_ = 0; | 77 update_rect_count_ = 0; |
104 } | 78 } |
105 | 79 |
106 void TestBrowserPluginGuest::WaitForUpdateRectMsgWithSize(int width, | 80 void TestBrowserPluginGuest::WaitForDamageBufferWithSize( |
107 int height) { | 81 const gfx::Size& size) { |
108 if (update_rect_count_ > 0 && | 82 if (damage_buffer_call_count_ > 0 && last_damage_buffer_size_ == size) |
109 last_update_rect_width_ == width && | |
110 last_update_rect_height_ == height) { | |
111 // We already saw this message. | |
112 return; | 83 return; |
113 } | |
114 waiting_for_update_rect_msg_with_size_ = true; | |
115 expected_width_ = width; | |
116 expected_height_ = height; | |
117 | 84 |
118 send_message_loop_runner_ = new MessageLoopRunner(); | 85 expected_damage_buffer_size_ = size; |
119 send_message_loop_runner_->Run(); | 86 waiting_for_damage_buffer_with_size_ = true; |
| 87 damage_buffer_message_loop_runner_ = new MessageLoopRunner(); |
| 88 damage_buffer_message_loop_runner_->Run(); |
120 } | 89 } |
121 | 90 |
122 void TestBrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { | 91 void TestBrowserPluginGuest::RenderViewGone(base::TerminationStatus status) { |
123 crash_observed_ = true; | 92 crash_observed_ = true; |
124 LOG(INFO) << "Guest crashed"; | 93 LOG(INFO) << "Guest crashed"; |
125 if (crash_message_loop_runner_) | 94 if (crash_message_loop_runner_) |
126 crash_message_loop_runner_->Quit(); | 95 crash_message_loop_runner_->Quit(); |
127 BrowserPluginGuest::RenderViewGone(status); | 96 BrowserPluginGuest::RenderViewGone(status); |
128 } | 97 } |
129 | 98 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 if (stop_observed_) { | 144 if (stop_observed_) { |
176 stop_observed_ = false; | 145 stop_observed_ = false; |
177 return; | 146 return; |
178 } | 147 } |
179 | 148 |
180 stop_message_loop_runner_ = new MessageLoopRunner(); | 149 stop_message_loop_runner_ = new MessageLoopRunner(); |
181 stop_message_loop_runner_->Run(); | 150 stop_message_loop_runner_->Run(); |
182 stop_observed_ = false; | 151 stop_observed_ = false; |
183 } | 152 } |
184 | 153 |
185 | |
186 void TestBrowserPluginGuest::SetFocus(bool focused) { | 154 void TestBrowserPluginGuest::SetFocus(bool focused) { |
187 focus_observed_ = true; | 155 focus_observed_ = true; |
188 if (focus_message_loop_runner_) | 156 if (focus_message_loop_runner_) |
189 focus_message_loop_runner_->Quit(); | 157 focus_message_loop_runner_->Quit(); |
190 BrowserPluginGuest::SetFocus(focused); | 158 BrowserPluginGuest::SetFocus(focused); |
191 } | 159 } |
192 | 160 |
193 bool TestBrowserPluginGuest::ViewTakeFocus(bool reverse) { | 161 bool TestBrowserPluginGuest::ViewTakeFocus(bool reverse) { |
194 advance_focus_observed_ = true; | 162 advance_focus_observed_ = true; |
195 if (advance_focus_message_loop_runner_) | 163 if (advance_focus_message_loop_runner_) |
196 advance_focus_message_loop_runner_->Quit(); | 164 advance_focus_message_loop_runner_->Quit(); |
197 return BrowserPluginGuest::ViewTakeFocus(reverse); | 165 return BrowserPluginGuest::ViewTakeFocus(reverse); |
198 } | 166 } |
199 | 167 |
200 void TestBrowserPluginGuest::Reload() { | 168 void TestBrowserPluginGuest::Reload() { |
201 reload_observed_ = true; | 169 reload_observed_ = true; |
202 if (reload_message_loop_runner_) | 170 if (reload_message_loop_runner_) |
203 reload_message_loop_runner_->Quit(); | 171 reload_message_loop_runner_->Quit(); |
204 BrowserPluginGuest::Reload(); | 172 BrowserPluginGuest::Reload(); |
205 } | 173 } |
206 | 174 |
207 void TestBrowserPluginGuest::Stop() { | 175 void TestBrowserPluginGuest::Stop() { |
208 stop_observed_ = true; | 176 stop_observed_ = true; |
209 if (stop_message_loop_runner_) | 177 if (stop_message_loop_runner_) |
210 stop_message_loop_runner_->Quit(); | 178 stop_message_loop_runner_->Quit(); |
211 BrowserPluginGuest::Stop(); | 179 BrowserPluginGuest::Stop(); |
212 } | 180 } |
213 | 181 |
| 182 void TestBrowserPluginGuest::SetDamageBuffer( |
| 183 TransportDIB* damage_buffer, |
| 184 #if defined(OS_WIN) |
| 185 int damage_buffer_size, |
| 186 #endif |
| 187 const gfx::Size& damage_view_size, |
| 188 float scale_factor) { |
| 189 ++damage_buffer_call_count_; |
| 190 last_damage_buffer_size_ = damage_view_size; |
| 191 |
| 192 if (waiting_for_damage_buffer_with_size_ && |
| 193 expected_damage_buffer_size_ == damage_view_size && |
| 194 damage_buffer_message_loop_runner_) { |
| 195 damage_buffer_message_loop_runner_->Quit(); |
| 196 waiting_for_damage_buffer_with_size_ = false; |
| 197 } |
| 198 |
| 199 BrowserPluginGuest::SetDamageBuffer( |
| 200 damage_buffer, |
| 201 #if defined(OS_WIN) |
| 202 damage_buffer_size, |
| 203 #endif |
| 204 damage_view_size, |
| 205 scale_factor); |
| 206 } |
| 207 |
214 } // namespace content | 208 } // namespace content |
OLD | NEW |