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

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: @tott + Address comments + fix win_rel trybot flakiness 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/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/browser/notification_observer.h"
14 #include "content/public/browser/notification_types.h"
15 #include "content/public/test/test_utils.h"
16 #include "ipc/ipc_channel_handle.h"
17 #include "ipc/ipc_sync_message.h"
18 #include "ui/gfx/size.h"
19
20 namespace content {
21
22 class BrowserPluginGuest;
23
24 TestBrowserPluginGuest::TestBrowserPluginGuest(
25 int instance_id,
26 WebContentsImpl* web_contents,
27 RenderViewHost* render_view_host)
28 : BrowserPluginGuest(instance_id, web_contents, render_view_host),
29 update_rect_count_(0),
30 crash_observed_(false),
31 focus_observed_(false),
32 advance_focus_observed_(false),
33 was_hidden_observed_(false),
34 waiting_for_update_rect_msg_with_size_(false),
35 last_update_rect_width_(-1),
36 last_update_rect_height_(-1) {
37 // Listen to visibility changes so that a test can wait for these changes.
38 registrar_.Add(this,
39 NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED,
40 Source<WebContents>(web_contents));
41 }
42
43 TestBrowserPluginGuest::~TestBrowserPluginGuest() {
44 }
45
46 void TestBrowserPluginGuest::Observe(int type,
47 const NotificationSource& source,
48 const NotificationDetails& details) {
49 switch (type) {
50 case NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED: {
51 bool visible = *Details<bool>(details).ptr();
52 if (!visible) {
53 was_hidden_observed_ = true;
54 if (was_hidden_message_loop_runner_)
55 was_hidden_message_loop_runner_->Quit();
56 }
57 break;
58 }
59 default:
60 NOTREACHED() << "Unexpected notification type: " << type;
61 }
62 }
63
64 void TestBrowserPluginGuest::SendMessageToEmbedder(IPC::Message* msg) {
65 if (msg->type() == BrowserPluginMsg_UpdateRect::ID) {
66 PickleIterator iter(*msg);
67
68 int instance_id;
69 int message_id;
70 BrowserPluginMsg_UpdateRect_Params update_rect_params;
71
72 if (!IPC::ReadParam(msg, &iter, &instance_id) ||
73 !IPC::ReadParam(msg, &iter, &message_id) ||
74 !IPC::ReadParam(msg, &iter, &update_rect_params)) {
75 NOTREACHED() <<
76 "Cannot read BrowserPluginMsg_UpdateRect params from ipc message";
77 }
78 last_update_rect_width_ = update_rect_params.view_size.width();
79 last_update_rect_height_ = update_rect_params.view_size.height();
80 update_rect_count_++;
81 if (waiting_for_update_rect_msg_with_size_ &&
82 expected_width_ == last_update_rect_width_ &&
83 expected_height_ == last_update_rect_height_) {
84 waiting_for_update_rect_msg_with_size_ = false;
85 if (send_message_loop_runner_)
86 send_message_loop_runner_->Quit();
87 } else if (!waiting_for_update_rect_msg_with_size_) {
88 if (send_message_loop_runner_)
89 send_message_loop_runner_->Quit();
90 }
91 }
92 BrowserPluginGuest::SendMessageToEmbedder(msg);
93 }
94
95 bool TestBrowserPluginGuest::WaitForUpdateRectMsg() {
96 // Check if we already got any UpdateRect message.
97 if (update_rect_count_ > 0)
98 return true;
99 send_message_loop_runner_ = new MessageLoopRunner();
100 return TestTimeoutTracker::RunInActionTimeout(
101 send_message_loop_runner_.get());
102 }
103
104 bool TestBrowserPluginGuest::WaitForUpdateRectMsgWithSize(int width,
105 int height) {
106 if (update_rect_count_ > 0 &&
107 last_update_rect_width_ == width &&
108 last_update_rect_height_ == height) {
109 // We already saw this message.
110 return true;
111 }
112 waiting_for_update_rect_msg_with_size_ = true;
113 expected_width_ = width;
114 expected_height_ = height;
115
116 send_message_loop_runner_ = new MessageLoopRunner();
117 return TestTimeoutTracker::RunInActionTimeout(
118 send_message_loop_runner_.get());
119 }
120
121 void TestBrowserPluginGuest::RenderViewGone(base::TerminationStatus status) {
122 crash_observed_ = true;
123 LOG(INFO) << "Guest crashed";
124 if (crash_message_loop_runner_)
125 crash_message_loop_runner_->Quit();
126 BrowserPluginGuest::RenderViewGone(status);
127 }
128
129 void TestBrowserPluginGuest::WaitForCrashed() {
130 // Check if we already observed a guest crash, return immediately if so.
131 if (crash_observed_)
132 return;
133
134 crash_message_loop_runner_ = new MessageLoopRunner();
135 crash_message_loop_runner_->Run();
136 }
137
138 bool TestBrowserPluginGuest::WaitForFocus() {
139 if (focus_observed_)
140 return true;
141 focus_message_loop_runner_ = new MessageLoopRunner();
142 return TestTimeoutTracker::RunInActionTimeout(
143 focus_message_loop_runner_.get());
144 }
145
146 bool TestBrowserPluginGuest::WaitForAdvanceFocus() {
147 if (advance_focus_observed_)
148 return true;
149 advance_focus_message_loop_runner_ = new MessageLoopRunner();
150 return TestTimeoutTracker::RunInActionTimeout(
151 advance_focus_message_loop_runner_.get());
152 }
153
154 bool TestBrowserPluginGuest::WaitUntilHidden() {
155 if (was_hidden_observed_) {
156 was_hidden_observed_ = false;
157 return true;
158 }
159 was_hidden_message_loop_runner_ = new MessageLoopRunner();
160 bool action_observed = TestTimeoutTracker::RunInActionTimeout(
161 was_hidden_message_loop_runner_.get());
162 if (action_observed)
163 was_hidden_observed_ = false;
164 return action_observed;
165 }
166
167 void TestBrowserPluginGuest::SetFocus(bool focused) {
168 focus_observed_ = true;
169 if (focus_message_loop_runner_)
170 focus_message_loop_runner_->Quit();
171 BrowserPluginGuest::SetFocus(focused);
172 }
173
174 bool TestBrowserPluginGuest::ViewTakeFocus(bool reverse) {
175 advance_focus_observed_ = true;
176 if (advance_focus_message_loop_runner_)
177 advance_focus_message_loop_runner_->Quit();
178 return BrowserPluginGuest::ViewTakeFocus(reverse);
179 }
180
181 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698