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

Side by Side 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: Remove TestTimeoutTracker and wait indefinitely in tests instead, fix one include. 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 unified diff | Download patch
OLDNEW
(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/renderer_host/render_view_host_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h"
11 #include "content/common/browser_plugin_messages.h"
12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_types.h"
14 #include "content/public/test/test_utils.h"
15 #include "ipc/ipc_channel_handle.h"
16 #include "ipc/ipc_sync_message.h"
17 #include "ui/gfx/size.h"
18
19 namespace content {
20
21 class BrowserPluginGuest;
22
23 TestBrowserPluginGuest::TestBrowserPluginGuest(
24 int instance_id,
25 WebContentsImpl* web_contents,
26 RenderViewHost* render_view_host)
27 : BrowserPluginGuest(instance_id, web_contents, render_view_host),
28 update_rect_count_(0),
29 crash_observed_(false),
30 focus_observed_(false),
31 advance_focus_observed_(false),
32 was_hidden_observed_(false),
33 waiting_for_update_rect_msg_with_size_(false),
34 last_update_rect_width_(-1),
35 last_update_rect_height_(-1) {
36 // Listen to visibility changes so that a test can wait for these changes.
37 registrar_.Add(this,
38 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
39 Source<WebContents>(web_contents));
40 }
41
42 TestBrowserPluginGuest::~TestBrowserPluginGuest() {
43 }
44
45 void TestBrowserPluginGuest::Observe(int type,
46 const NotificationSource& source,
47 const NotificationDetails& details) {
48 switch (type) {
49 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
50 bool visible = *Details<bool>(details).ptr();
51 if (!visible) {
52 was_hidden_observed_ = true;
53 if (was_hidden_message_loop_runner_)
54 was_hidden_message_loop_runner_->Quit();
55 }
56 break;
57 }
58 default:
59 NOTREACHED() << "Unexpected notification type: " << type;
60 }
61 }
62
63 void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
64 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_++;
80 if (waiting_for_update_rect_msg_with_size_ &&
81 expected_width_ == last_update_rect_width_ &&
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 }
91 BrowserPluginGuest::SendMessageToEmbedder(msg);
92 }
93
94 void TestBrowserPluginGuest::WaitForUpdateRectMsg() {
95 // Check if we already got any UpdateRect message.
96 if (update_rect_count_ > 0)
97 return;
98 send_message_loop_runner_ = new MessageLoopRunner();
99 send_message_loop_runner_->Run();
100 }
101
102 void TestBrowserPluginGuest::WaitForUpdateRectMsgWithSize(int width,
103 int height) {
104 if (update_rect_count_ > 0 &&
105 last_update_rect_width_ == width &&
106 last_update_rect_height_ == height) {
107 // We already saw this message.
108 return;
109 }
110 waiting_for_update_rect_msg_with_size_ = true;
111 expected_width_ = width;
112 expected_height_ = height;
113
114 send_message_loop_runner_ = new MessageLoopRunner();
115 send_message_loop_runner_->Run();
116 }
117
118 void TestBrowserPluginGuest::RenderViewGone(base::TerminationStatus status) {
119 crash_observed_ = true;
120 LOG(INFO) << "Guest crashed";
121 if (crash_message_loop_runner_)
122 crash_message_loop_runner_->Quit();
123 BrowserPluginGuest::RenderViewGone(status);
124 }
125
126 void TestBrowserPluginGuest::WaitForCrashed() {
127 // Check if we already observed a guest crash, return immediately if so.
128 if (crash_observed_)
129 return;
130
131 crash_message_loop_runner_ = new MessageLoopRunner();
132 crash_message_loop_runner_->Run();
133 }
134
135 void TestBrowserPluginGuest::WaitForFocus() {
136 if (focus_observed_)
137 return;
138 focus_message_loop_runner_ = new MessageLoopRunner();
139 focus_message_loop_runner_->Run();
140 }
141
142 void TestBrowserPluginGuest::WaitForAdvanceFocus() {
143 if (advance_focus_observed_)
144 return;
145 advance_focus_message_loop_runner_ = new MessageLoopRunner();
146 advance_focus_message_loop_runner_->Run();
147 }
148
149 void TestBrowserPluginGuest::WaitUntilHidden() {
150 if (was_hidden_observed_) {
151 was_hidden_observed_ = false;
152 return;
153 }
154 was_hidden_message_loop_runner_ = new MessageLoopRunner();
155 was_hidden_message_loop_runner_->Run();
156 was_hidden_observed_ = false;
157 }
158
159 void TestBrowserPluginGuest::SetFocus(bool focused) {
160 focus_observed_ = true;
161 if (focus_message_loop_runner_)
162 focus_message_loop_runner_->Quit();
163 BrowserPluginGuest::SetFocus(focused);
164 }
165
166 bool TestBrowserPluginGuest::ViewTakeFocus(bool reverse) {
167 advance_focus_observed_ = true;
168 if (advance_focus_message_loop_runner_)
169 advance_focus_message_loop_runner_->Quit();
170 return BrowserPluginGuest::ViewTakeFocus(reverse);
171 }
172
173 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698