OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/web_view/frame.h" | 5 #include "components/web_view/frame.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 scoped_ptr<FrameConnection> frame_connection(new FrameConnection); | 74 scoped_ptr<FrameConnection> frame_connection(new FrameConnection); |
75 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 75 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
76 request->url = mojo::String::From(app->url()); | 76 request->url = mojo::String::From(app->url()); |
77 base::RunLoop run_loop; | 77 base::RunLoop run_loop; |
78 frame_connection->Init(app, request.Pass(), | 78 frame_connection->Init(app, request.Pass(), |
79 base::Bind(&OnGotIdCallback, &run_loop)); | 79 base::Bind(&OnGotIdCallback, &run_loop)); |
80 run_loop.Run(); | 80 run_loop.Run(); |
81 return frame_connection; | 81 return frame_connection; |
82 } | 82 } |
83 | 83 |
84 class TestFrameTreeClient : public FrameTreeClient { | 84 class TestFrameClient : public mojom::FrameClient { |
85 public: | 85 public: |
86 TestFrameTreeClient() | 86 TestFrameClient() |
87 : connect_count_(0), last_dispatch_load_event_frame_id_(0) {} | 87 : connect_count_(0), last_dispatch_load_event_frame_id_(0) {} |
88 ~TestFrameTreeClient() override {} | 88 ~TestFrameClient() override {} |
89 | 89 |
90 int connect_count() const { return connect_count_; } | 90 int connect_count() const { return connect_count_; } |
91 | 91 |
92 mojo::Array<FrameDataPtr> connect_frames() { return connect_frames_.Pass(); } | 92 mojo::Array<mojom::FrameDataPtr> connect_frames() { |
| 93 return connect_frames_.Pass(); |
| 94 } |
93 | 95 |
94 mojo::Array<FrameDataPtr> adds() { return adds_.Pass(); } | 96 mojo::Array<mojom::FrameDataPtr> adds() { return adds_.Pass(); } |
95 | 97 |
96 // Sets a callback to run once OnConnect() is received. | 98 // Sets a callback to run once OnConnect() is received. |
97 void set_on_connect_callback(const base::Closure& closure) { | 99 void set_on_connect_callback(const base::Closure& closure) { |
98 on_connect_callback_ = closure; | 100 on_connect_callback_ = closure; |
99 } | 101 } |
100 | 102 |
101 void set_on_loading_state_changed_callback(const base::Closure& closure) { | 103 void set_on_loading_state_changed_callback(const base::Closure& closure) { |
102 on_loading_state_changed_callback_ = closure; | 104 on_loading_state_changed_callback_ = closure; |
103 } | 105 } |
104 | 106 |
105 void set_on_dispatch_load_event_callback(const base::Closure& closure) { | 107 void set_on_dispatch_load_event_callback(const base::Closure& closure) { |
106 on_dispatch_load_event_callback_ = closure; | 108 on_dispatch_load_event_callback_ = closure; |
107 } | 109 } |
108 | 110 |
109 FrameTreeServer* server() { return server_.get(); } | 111 mojom::Frame* server_frame() { return server_frame_.get(); } |
110 | 112 |
111 mojo::InterfaceRequest<FrameTreeServer> GetFrameTreeServerRequest() { | 113 mojo::InterfaceRequest<mojom::Frame> GetServerFrameRequest() { |
112 return GetProxy(&server_); | 114 return GetProxy(&server_frame_); |
113 } | 115 } |
114 | 116 |
115 void last_loading_state_changed_notification(uint32_t* frame_id, | 117 void last_loading_state_changed_notification(uint32_t* frame_id, |
116 bool* loading) const { | 118 bool* loading) const { |
117 *frame_id = last_loading_state_changed_notification_.frame_id; | 119 *frame_id = last_loading_state_changed_notification_.frame_id; |
118 *loading = last_loading_state_changed_notification_.loading; | 120 *loading = last_loading_state_changed_notification_.loading; |
119 } | 121 } |
120 | 122 |
121 uint32_t last_dispatch_load_event_frame_id() const { | 123 uint32_t last_dispatch_load_event_frame_id() const { |
122 return last_dispatch_load_event_frame_id_; | 124 return last_dispatch_load_event_frame_id_; |
123 } | 125 } |
124 | 126 |
125 // TestFrameTreeClient: | 127 // mojom::FrameClient: |
126 void OnConnect(FrameTreeServerPtr server, | 128 void OnConnect(mojom::FramePtr frame, |
127 uint32_t change_id, | 129 uint32_t change_id, |
128 uint32_t view_id, | 130 uint32_t view_id, |
129 ViewConnectType view_connect_type, | 131 mojom::ViewConnectType view_connect_type, |
130 mojo::Array<FrameDataPtr> frames, | 132 mojo::Array<mojom::FrameDataPtr> frames, |
131 const OnConnectCallback& callback) override { | 133 const OnConnectCallback& callback) override { |
132 connect_count_++; | 134 connect_count_++; |
133 connect_frames_ = frames.Pass(); | 135 connect_frames_ = frames.Pass(); |
134 if (server) | 136 if (frame) |
135 server_ = server.Pass(); | 137 server_frame_ = frame.Pass(); |
136 callback.Run(); | 138 callback.Run(); |
137 if (!on_connect_callback_.is_null()) | 139 if (!on_connect_callback_.is_null()) |
138 on_connect_callback_.Run(); | 140 on_connect_callback_.Run(); |
139 } | 141 } |
140 void OnFrameAdded(uint32_t change_id, FrameDataPtr frame) override { | 142 void OnFrameAdded(uint32_t change_id, mojom::FrameDataPtr frame) override { |
141 adds_.push_back(frame.Pass()); | 143 adds_.push_back(frame.Pass()); |
142 } | 144 } |
143 void OnFrameRemoved(uint32_t change_id, uint32_t frame_id) override {} | 145 void OnFrameRemoved(uint32_t change_id, uint32_t frame_id) override {} |
144 void OnFrameClientPropertyChanged(uint32_t frame_id, | 146 void OnFrameClientPropertyChanged(uint32_t frame_id, |
145 const mojo::String& name, | 147 const mojo::String& name, |
146 mojo::Array<uint8_t> new_data) override {} | 148 mojo::Array<uint8_t> new_data) override {} |
147 void OnPostMessageEvent(uint32_t source_frame_id, | 149 void OnPostMessageEvent(uint32_t source_frame_id, |
148 uint32_t target_frame_id, | 150 uint32_t target_frame_id, |
149 HTMLMessageEventPtr event) override {} | 151 mojom::HTMLMessageEventPtr event) override {} |
150 void OnWillNavigate() override {} | 152 void OnWillNavigate() override {} |
151 void OnFrameLoadingStateChanged(uint32_t frame_id, bool loading) override { | 153 void OnFrameLoadingStateChanged(uint32_t frame_id, bool loading) override { |
152 last_loading_state_changed_notification_.frame_id = frame_id; | 154 last_loading_state_changed_notification_.frame_id = frame_id; |
153 last_loading_state_changed_notification_.loading = loading; | 155 last_loading_state_changed_notification_.loading = loading; |
154 | 156 |
155 if (!on_loading_state_changed_callback_.is_null()) | 157 if (!on_loading_state_changed_callback_.is_null()) |
156 on_loading_state_changed_callback_.Run(); | 158 on_loading_state_changed_callback_.Run(); |
157 } | 159 } |
158 void OnDispatchFrameLoadEvent(uint32_t frame_id) override { | 160 void OnDispatchFrameLoadEvent(uint32_t frame_id) override { |
159 last_dispatch_load_event_frame_id_ = frame_id; | 161 last_dispatch_load_event_frame_id_ = frame_id; |
160 | 162 |
161 if (!on_dispatch_load_event_callback_.is_null()) | 163 if (!on_dispatch_load_event_callback_.is_null()) |
162 on_dispatch_load_event_callback_.Run(); | 164 on_dispatch_load_event_callback_.Run(); |
163 } | 165 } |
164 | 166 |
165 private: | 167 private: |
166 struct LoadingStateChangedNotification { | 168 struct LoadingStateChangedNotification { |
167 LoadingStateChangedNotification() : frame_id(0), loading(false) {} | 169 LoadingStateChangedNotification() : frame_id(0), loading(false) {} |
168 ~LoadingStateChangedNotification() {} | 170 ~LoadingStateChangedNotification() {} |
169 | 171 |
170 uint32_t frame_id; | 172 uint32_t frame_id; |
171 bool loading; | 173 bool loading; |
172 }; | 174 }; |
173 | 175 |
174 int connect_count_; | 176 int connect_count_; |
175 mojo::Array<FrameDataPtr> connect_frames_; | 177 mojo::Array<mojom::FrameDataPtr> connect_frames_; |
176 FrameTreeServerPtr server_; | 178 mojom::FramePtr server_frame_; |
177 mojo::Array<FrameDataPtr> adds_; | 179 mojo::Array<mojom::FrameDataPtr> adds_; |
178 base::Closure on_connect_callback_; | 180 base::Closure on_connect_callback_; |
179 base::Closure on_loading_state_changed_callback_; | 181 base::Closure on_loading_state_changed_callback_; |
180 base::Closure on_dispatch_load_event_callback_; | 182 base::Closure on_dispatch_load_event_callback_; |
181 LoadingStateChangedNotification last_loading_state_changed_notification_; | 183 LoadingStateChangedNotification last_loading_state_changed_notification_; |
182 uint32_t last_dispatch_load_event_frame_id_; | 184 uint32_t last_dispatch_load_event_frame_id_; |
183 | 185 |
184 DISALLOW_COPY_AND_ASSIGN(TestFrameTreeClient); | 186 DISALLOW_COPY_AND_ASSIGN(TestFrameClient); |
185 }; | 187 }; |
186 | 188 |
187 class FrameTest; | 189 class FrameTest; |
188 | 190 |
189 // ViewAndFrame maintains the View and TestFrameTreeClient associated with | 191 // ViewAndFrame maintains the View and TestFrameClient associated with |
190 // a single FrameTreeClient. In other words this maintains the data structures | 192 // a single FrameClient. In other words this maintains the data structures |
191 // needed to represent a client side frame. To obtain one use | 193 // needed to represent a client side frame. To obtain one use |
192 // FrameTest::WaitForViewAndFrame(). | 194 // FrameTest::WaitForViewAndFrame(). |
193 class ViewAndFrame : public mus::ViewTreeDelegate { | 195 class ViewAndFrame : public mus::ViewTreeDelegate { |
194 public: | 196 public: |
195 ~ViewAndFrame() override { | 197 ~ViewAndFrame() override { |
196 if (view_) | 198 if (view_) |
197 delete view_->connection(); | 199 delete view_->connection(); |
198 } | 200 } |
199 | 201 |
200 // The View associated with the frame. | 202 // The View associated with the frame. |
201 mus::View* view() { return view_; } | 203 mus::View* view() { return view_; } |
202 TestFrameTreeClient* test_frame_tree_client() { | 204 TestFrameClient* test_frame_client() { return &test_frame_tree_client_; } |
203 return &test_frame_tree_client_; | 205 mojom::Frame* server_frame() { |
204 } | 206 return test_frame_tree_client_.server_frame(); |
205 FrameTreeServer* frame_tree_server() { | |
206 return test_frame_tree_client_.server(); | |
207 } | 207 } |
208 | 208 |
209 private: | 209 private: |
210 friend class FrameTest; | 210 friend class FrameTest; |
211 | 211 |
212 ViewAndFrame() | 212 ViewAndFrame() |
213 : view_(nullptr), frame_tree_binding_(&test_frame_tree_client_) {} | 213 : view_(nullptr), frame_client_binding_(&test_frame_tree_client_) {} |
214 | 214 |
215 void set_view(View* view) { view_ = view; } | 215 void set_view(View* view) { view_ = view; } |
216 | 216 |
217 // Runs a message loop until the view and frame data have been received. | 217 // Runs a message loop until the view and frame data have been received. |
218 void WaitForViewAndFrame() { run_loop_.Run(); } | 218 void WaitForViewAndFrame() { run_loop_.Run(); } |
219 | 219 |
220 mojo::InterfaceRequest<FrameTreeServer> GetFrameTreeServerRequest() { | 220 mojo::InterfaceRequest<mojom::Frame> GetServerFrameRequest() { |
221 return test_frame_tree_client_.GetFrameTreeServerRequest(); | 221 return test_frame_tree_client_.GetServerFrameRequest(); |
222 } | 222 } |
223 | 223 |
224 FrameTreeClientPtr GetFrameTreeClientPtr() { | 224 mojom::FrameClientPtr GetFrameClientPtr() { |
225 FrameTreeClientPtr client_ptr; | 225 mojom::FrameClientPtr client_ptr; |
226 frame_tree_binding_.Bind(GetProxy(&client_ptr)); | 226 frame_client_binding_.Bind(GetProxy(&client_ptr)); |
227 return client_ptr.Pass(); | 227 return client_ptr.Pass(); |
228 } | 228 } |
229 | 229 |
230 void Bind(mojo::InterfaceRequest<FrameTreeClient> request) { | 230 void Bind(mojo::InterfaceRequest<mojom::FrameClient> request) { |
231 ASSERT_FALSE(frame_tree_binding_.is_bound()); | 231 ASSERT_FALSE(frame_client_binding_.is_bound()); |
232 test_frame_tree_client_.set_on_connect_callback( | 232 test_frame_tree_client_.set_on_connect_callback( |
233 base::Bind(&ViewAndFrame::OnGotConnect, base::Unretained(this))); | 233 base::Bind(&ViewAndFrame::OnGotConnect, base::Unretained(this))); |
234 frame_tree_binding_.Bind(request.Pass()); | 234 frame_client_binding_.Bind(request.Pass()); |
235 } | 235 } |
236 | 236 |
237 void OnGotConnect() { QuitRunLoopIfNecessary(); } | 237 void OnGotConnect() { QuitRunLoopIfNecessary(); } |
238 | 238 |
239 void QuitRunLoopIfNecessary() { | 239 void QuitRunLoopIfNecessary() { |
240 if (view_ && test_frame_tree_client_.connect_count()) | 240 if (view_ && test_frame_tree_client_.connect_count()) |
241 run_loop_.Quit(); | 241 run_loop_.Quit(); |
242 } | 242 } |
243 | 243 |
244 // Overridden from ViewTreeDelegate: | 244 // Overridden from ViewTreeDelegate: |
245 void OnEmbed(View* root) override { | 245 void OnEmbed(View* root) override { |
246 view_ = root; | 246 view_ = root; |
247 QuitRunLoopIfNecessary(); | 247 QuitRunLoopIfNecessary(); |
248 } | 248 } |
249 void OnConnectionLost(ViewTreeConnection* connection) override { | 249 void OnConnectionLost(ViewTreeConnection* connection) override { |
250 view_ = nullptr; | 250 view_ = nullptr; |
251 } | 251 } |
252 | 252 |
253 mus::View* view_; | 253 mus::View* view_; |
254 base::RunLoop run_loop_; | 254 base::RunLoop run_loop_; |
255 TestFrameTreeClient test_frame_tree_client_; | 255 TestFrameClient test_frame_tree_client_; |
256 mojo::Binding<FrameTreeClient> frame_tree_binding_; | 256 mojo::Binding<mojom::FrameClient> frame_client_binding_; |
257 | 257 |
258 DISALLOW_COPY_AND_ASSIGN(ViewAndFrame); | 258 DISALLOW_COPY_AND_ASSIGN(ViewAndFrame); |
259 }; | 259 }; |
260 | 260 |
261 class FrameTest : public mojo::test::ApplicationTestBase, | 261 class FrameTest : public mojo::test::ApplicationTestBase, |
262 public mojo::ApplicationDelegate, | 262 public mojo::ApplicationDelegate, |
263 public mus::ViewTreeDelegate, | 263 public mus::ViewTreeDelegate, |
264 public mojo::InterfaceFactory<mojo::ViewTreeClient>, | 264 public mojo::InterfaceFactory<mojo::ViewTreeClient>, |
265 public mojo::InterfaceFactory<FrameTreeClient> { | 265 public mojo::InterfaceFactory<mojom::FrameClient> { |
266 public: | 266 public: |
267 FrameTest() : most_recent_connection_(nullptr), window_manager_(nullptr) {} | 267 FrameTest() : most_recent_connection_(nullptr), window_manager_(nullptr) {} |
268 | 268 |
269 ViewTreeConnection* most_recent_connection() { | 269 ViewTreeConnection* most_recent_connection() { |
270 return most_recent_connection_; | 270 return most_recent_connection_; |
271 } | 271 } |
272 | 272 |
273 protected: | 273 protected: |
274 ViewTreeConnection* window_manager() { return window_manager_; } | 274 ViewTreeConnection* window_manager() { return window_manager_; } |
275 TestFrameTreeDelegate* frame_tree_delegate() { | 275 TestFrameTreeDelegate* frame_tree_delegate() { |
276 return frame_tree_delegate_.get(); | 276 return frame_tree_delegate_.get(); |
277 } | 277 } |
278 FrameTree* frame_tree() { return frame_tree_.get(); } | 278 FrameTree* frame_tree() { return frame_tree_.get(); } |
279 ViewAndFrame* root_view_and_frame() { return root_view_and_frame_.get(); } | 279 ViewAndFrame* root_view_and_frame() { return root_view_and_frame_.get(); } |
280 | 280 |
281 mojo::Binding<FrameTreeServer>* frame_tree_server_binding(Frame* frame) { | |
282 return frame->frame_tree_server_binding_.get(); | |
283 } | |
284 | |
285 scoped_ptr<ViewAndFrame> NavigateFrame(ViewAndFrame* view_and_frame) { | 281 scoped_ptr<ViewAndFrame> NavigateFrame(ViewAndFrame* view_and_frame) { |
286 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 282 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
287 request->url = mojo::String::From(application_impl()->url()); | 283 request->url = mojo::String::From(application_impl()->url()); |
288 view_and_frame->frame_tree_server()->RequestNavigate( | 284 view_and_frame->server_frame()->RequestNavigate( |
289 NAVIGATION_TARGET_TYPE_EXISTING_FRAME, view_and_frame->view()->id(), | 285 mojom::NAVIGATION_TARGET_TYPE_EXISTING_FRAME, |
290 request.Pass()); | 286 view_and_frame->view()->id(), request.Pass()); |
291 return WaitForViewAndFrame(); | 287 return WaitForViewAndFrame(); |
292 } | 288 } |
293 | 289 |
294 // Creates a new shared frame as a child of |parent|. | 290 // Creates a new shared frame as a child of |parent|. |
295 scoped_ptr<ViewAndFrame> CreateChildViewAndFrame(ViewAndFrame* parent) { | 291 scoped_ptr<ViewAndFrame> CreateChildViewAndFrame(ViewAndFrame* parent) { |
296 mus::View* child_frame_view = parent->view()->connection()->CreateView(); | 292 mus::View* child_frame_view = parent->view()->connection()->CreateView(); |
297 parent->view()->AddChild(child_frame_view); | 293 parent->view()->AddChild(child_frame_view); |
298 | 294 |
299 scoped_ptr<ViewAndFrame> view_and_frame(new ViewAndFrame); | 295 scoped_ptr<ViewAndFrame> view_and_frame(new ViewAndFrame); |
300 view_and_frame->set_view(child_frame_view); | 296 view_and_frame->set_view(child_frame_view); |
301 | 297 |
302 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; | 298 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties; |
303 client_properties.mark_non_null(); | 299 client_properties.mark_non_null(); |
304 parent->frame_tree_server()->OnCreatedFrame( | 300 parent->server_frame()->OnCreatedFrame( |
305 view_and_frame->GetFrameTreeServerRequest(), | 301 view_and_frame->GetServerFrameRequest(), |
306 view_and_frame->GetFrameTreeClientPtr(), child_frame_view->id(), | 302 view_and_frame->GetFrameClientPtr(), child_frame_view->id(), |
307 client_properties.Pass()); | 303 client_properties.Pass()); |
308 frame_tree_delegate()->WaitForCreateFrame(); | 304 frame_tree_delegate()->WaitForCreateFrame(); |
309 return HasFatalFailure() ? nullptr : view_and_frame.Pass(); | 305 return HasFatalFailure() ? nullptr : view_and_frame.Pass(); |
310 } | 306 } |
311 | 307 |
312 // Runs a message loop until the data necessary to represent to a client side | 308 // Runs a message loop until the data necessary to represent to a client side |
313 // frame has been obtained. | 309 // frame has been obtained. |
314 scoped_ptr<ViewAndFrame> WaitForViewAndFrame() { | 310 scoped_ptr<ViewAndFrame> WaitForViewAndFrame() { |
315 DCHECK(!view_and_frame_); | 311 DCHECK(!view_and_frame_); |
316 view_and_frame_.reset(new ViewAndFrame); | 312 view_and_frame_.reset(new ViewAndFrame); |
317 view_and_frame_->WaitForViewAndFrame(); | 313 view_and_frame_->WaitForViewAndFrame(); |
318 return view_and_frame_.Pass(); | 314 return view_and_frame_.Pass(); |
319 } | 315 } |
320 | 316 |
321 private: | 317 private: |
322 // ApplicationTestBase: | 318 // ApplicationTestBase: |
323 ApplicationDelegate* GetApplicationDelegate() override { return this; } | 319 ApplicationDelegate* GetApplicationDelegate() override { return this; } |
324 | 320 |
325 // ApplicationDelegate implementation. | 321 // ApplicationDelegate implementation. |
326 bool ConfigureIncomingConnection( | 322 bool ConfigureIncomingConnection( |
327 mojo::ApplicationConnection* connection) override { | 323 mojo::ApplicationConnection* connection) override { |
328 connection->AddService<mojo::ViewTreeClient>(this); | 324 connection->AddService<mojo::ViewTreeClient>(this); |
329 connection->AddService<FrameTreeClient>(this); | 325 connection->AddService<mojom::FrameClient>(this); |
330 return true; | 326 return true; |
331 } | 327 } |
332 | 328 |
333 // Overridden from ViewTreeDelegate: | 329 // Overridden from ViewTreeDelegate: |
334 void OnEmbed(View* root) override { | 330 void OnEmbed(View* root) override { |
335 most_recent_connection_ = root->connection(); | 331 most_recent_connection_ = root->connection(); |
336 QuitRunLoop(); | 332 QuitRunLoop(); |
337 } | 333 } |
338 void OnConnectionLost(ViewTreeConnection* connection) override {} | 334 void OnConnectionLost(ViewTreeConnection* connection) override {} |
339 | 335 |
340 // Overridden from testing::Test: | 336 // Overridden from testing::Test: |
341 void SetUp() override { | 337 void SetUp() override { |
342 ApplicationTestBase::SetUp(); | 338 ApplicationTestBase::SetUp(); |
343 | 339 |
344 mus::CreateSingleViewTreeHost(application_impl(), this, &host_); | 340 mus::CreateSingleViewTreeHost(application_impl(), this, &host_); |
345 | 341 |
346 ASSERT_TRUE(DoRunLoopWithTimeout()); | 342 ASSERT_TRUE(DoRunLoopWithTimeout()); |
347 std::swap(window_manager_, most_recent_connection_); | 343 std::swap(window_manager_, most_recent_connection_); |
348 | 344 |
349 // Creates a FrameTree, which creates a single frame. Wait for the | 345 // Creates a FrameTree, which creates a single frame. Wait for the |
350 // FrameTreeClient to be connected to. | 346 // FrameClient to be connected to. |
351 frame_tree_delegate_.reset(new TestFrameTreeDelegate(application_impl())); | 347 frame_tree_delegate_.reset(new TestFrameTreeDelegate(application_impl())); |
352 scoped_ptr<FrameConnection> frame_connection = | 348 scoped_ptr<FrameConnection> frame_connection = |
353 CreateFrameConnection(application_impl()); | 349 CreateFrameConnection(application_impl()); |
354 FrameTreeClient* frame_tree_client = frame_connection->frame_tree_client(); | 350 mojom::FrameClient* frame_client = frame_connection->frame_client(); |
355 mojo::ViewTreeClientPtr view_tree_client = | 351 mojo::ViewTreeClientPtr view_tree_client = |
356 frame_connection->GetViewTreeClient(); | 352 frame_connection->GetViewTreeClient(); |
357 mus::View* frame_root_view = window_manager()->CreateView(); | 353 mus::View* frame_root_view = window_manager()->CreateView(); |
358 window_manager()->GetRoot()->AddChild(frame_root_view); | 354 window_manager()->GetRoot()->AddChild(frame_root_view); |
359 frame_tree_.reset( | 355 frame_tree_.reset( |
360 new FrameTree(0u, frame_root_view, view_tree_client.Pass(), | 356 new FrameTree(0u, frame_root_view, view_tree_client.Pass(), |
361 frame_tree_delegate_.get(), frame_tree_client, | 357 frame_tree_delegate_.get(), frame_client, |
362 frame_connection.Pass(), Frame::ClientPropertyMap())); | 358 frame_connection.Pass(), Frame::ClientPropertyMap())); |
363 root_view_and_frame_ = WaitForViewAndFrame(); | 359 root_view_and_frame_ = WaitForViewAndFrame(); |
364 } | 360 } |
365 | 361 |
366 // Overridden from testing::Test: | 362 // Overridden from testing::Test: |
367 void TearDown() override { | 363 void TearDown() override { |
368 root_view_and_frame_.reset(); | 364 root_view_and_frame_.reset(); |
369 frame_tree_.reset(); | 365 frame_tree_.reset(); |
370 frame_tree_delegate_.reset(); | 366 frame_tree_delegate_.reset(); |
371 ApplicationTestBase::TearDown(); | 367 ApplicationTestBase::TearDown(); |
372 } | 368 } |
373 | 369 |
374 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>: | 370 // Overridden from mojo::InterfaceFactory<mojo::ViewTreeClient>: |
375 void Create( | 371 void Create( |
376 mojo::ApplicationConnection* connection, | 372 mojo::ApplicationConnection* connection, |
377 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override { | 373 mojo::InterfaceRequest<mojo::ViewTreeClient> request) override { |
378 if (view_and_frame_) { | 374 if (view_and_frame_) { |
379 mus::ViewTreeConnection::Create(view_and_frame_.get(), request.Pass()); | 375 mus::ViewTreeConnection::Create(view_and_frame_.get(), request.Pass()); |
380 } else { | 376 } else { |
381 mus::ViewTreeConnection::Create(this, request.Pass()); | 377 mus::ViewTreeConnection::Create(this, request.Pass()); |
382 } | 378 } |
383 } | 379 } |
384 | 380 |
385 // Overridden from mojo::InterfaceFactory<FrameTreeClient>: | 381 // Overridden from mojo::InterfaceFactory<mojom::FrameClient>: |
386 void Create(mojo::ApplicationConnection* connection, | 382 void Create(mojo::ApplicationConnection* connection, |
387 mojo::InterfaceRequest<FrameTreeClient> request) override { | 383 mojo::InterfaceRequest<mojom::FrameClient> request) override { |
388 ASSERT_TRUE(view_and_frame_); | 384 ASSERT_TRUE(view_and_frame_); |
389 view_and_frame_->Bind(request.Pass()); | 385 view_and_frame_->Bind(request.Pass()); |
390 } | 386 } |
391 | 387 |
392 scoped_ptr<TestFrameTreeDelegate> frame_tree_delegate_; | 388 scoped_ptr<TestFrameTreeDelegate> frame_tree_delegate_; |
393 scoped_ptr<FrameTree> frame_tree_; | 389 scoped_ptr<FrameTree> frame_tree_; |
394 scoped_ptr<ViewAndFrame> root_view_and_frame_; | 390 scoped_ptr<ViewAndFrame> root_view_and_frame_; |
395 | 391 |
396 mojo::ViewTreeHostPtr host_; | 392 mojo::ViewTreeHostPtr host_; |
397 | 393 |
398 // Used to receive the most recent view manager loaded by an embed action. | 394 // Used to receive the most recent view manager loaded by an embed action. |
399 ViewTreeConnection* most_recent_connection_; | 395 ViewTreeConnection* most_recent_connection_; |
400 // The View Manager connection held by the window manager (app running at the | 396 // The View Manager connection held by the window manager (app running at the |
401 // root view). | 397 // root view). |
402 ViewTreeConnection* window_manager_; | 398 ViewTreeConnection* window_manager_; |
403 | 399 |
404 scoped_ptr<ViewAndFrame> view_and_frame_; | 400 scoped_ptr<ViewAndFrame> view_and_frame_; |
405 | 401 |
406 MOJO_DISALLOW_COPY_AND_ASSIGN(FrameTest); | 402 MOJO_DISALLOW_COPY_AND_ASSIGN(FrameTest); |
407 }; | 403 }; |
408 | 404 |
409 // Verifies the FrameData supplied to the root FrameTreeClient::OnConnect(). | 405 // Verifies the FrameData supplied to the root FrameClient::OnConnect(). |
410 TEST_F(FrameTest, RootFrameClientConnectData) { | 406 TEST_F(FrameTest, RootFrameClientConnectData) { |
411 mojo::Array<FrameDataPtr> frames = | 407 mojo::Array<mojom::FrameDataPtr> frames = |
412 root_view_and_frame()->test_frame_tree_client()->connect_frames(); | 408 root_view_and_frame()->test_frame_client()->connect_frames(); |
413 ASSERT_EQ(1u, frames.size()); | 409 ASSERT_EQ(1u, frames.size()); |
414 EXPECT_EQ(root_view_and_frame()->view()->id(), frames[0]->frame_id); | 410 EXPECT_EQ(root_view_and_frame()->view()->id(), frames[0]->frame_id); |
415 EXPECT_EQ(0u, frames[0]->parent_id); | 411 EXPECT_EQ(0u, frames[0]->parent_id); |
416 } | 412 } |
417 | 413 |
418 // Verifies the FrameData supplied to a child FrameTreeClient::OnConnect(). | 414 // Verifies the FrameData supplied to a child FrameClient::OnConnect(). |
419 TEST_F(FrameTest, ChildFrameClientConnectData) { | 415 TEST_F(FrameTest, ChildFrameClientConnectData) { |
420 scoped_ptr<ViewAndFrame> child_view_and_frame( | 416 scoped_ptr<ViewAndFrame> child_view_and_frame( |
421 CreateChildViewAndFrame(root_view_and_frame())); | 417 CreateChildViewAndFrame(root_view_and_frame())); |
422 ASSERT_TRUE(child_view_and_frame); | 418 ASSERT_TRUE(child_view_and_frame); |
423 // Initially created child frames don't get OnConnect(). | 419 // Initially created child frames don't get OnConnect(). |
424 EXPECT_EQ(0, | 420 EXPECT_EQ(0, child_view_and_frame->test_frame_client()->connect_count()); |
425 child_view_and_frame->test_frame_tree_client()->connect_count()); | |
426 | 421 |
427 scoped_ptr<ViewAndFrame> navigated_child_view_and_frame = | 422 scoped_ptr<ViewAndFrame> navigated_child_view_and_frame = |
428 NavigateFrame(child_view_and_frame.get()).Pass(); | 423 NavigateFrame(child_view_and_frame.get()).Pass(); |
429 | 424 |
430 mojo::Array<FrameDataPtr> frames_in_child = | 425 mojo::Array<mojom::FrameDataPtr> frames_in_child = |
431 navigated_child_view_and_frame->test_frame_tree_client() | 426 navigated_child_view_and_frame->test_frame_client()->connect_frames(); |
432 ->connect_frames(); | |
433 EXPECT_EQ(child_view_and_frame->view()->id(), | 427 EXPECT_EQ(child_view_and_frame->view()->id(), |
434 navigated_child_view_and_frame->view()->id()); | 428 navigated_child_view_and_frame->view()->id()); |
435 // We expect 2 frames. One for the root, one for the child. | 429 // We expect 2 frames. One for the root, one for the child. |
436 ASSERT_EQ(2u, frames_in_child.size()); | 430 ASSERT_EQ(2u, frames_in_child.size()); |
437 EXPECT_EQ(frame_tree()->root()->id(), frames_in_child[0]->frame_id); | 431 EXPECT_EQ(frame_tree()->root()->id(), frames_in_child[0]->frame_id); |
438 EXPECT_EQ(0u, frames_in_child[0]->parent_id); | 432 EXPECT_EQ(0u, frames_in_child[0]->parent_id); |
439 EXPECT_EQ(navigated_child_view_and_frame->view()->id(), | 433 EXPECT_EQ(navigated_child_view_and_frame->view()->id(), |
440 frames_in_child[1]->frame_id); | 434 frames_in_child[1]->frame_id); |
441 EXPECT_EQ(frame_tree()->root()->id(), frames_in_child[1]->parent_id); | 435 EXPECT_EQ(frame_tree()->root()->id(), frames_in_child[1]->parent_id); |
442 } | 436 } |
(...skipping 16 matching lines...) Expand all Loading... |
459 } | 453 } |
460 | 454 |
461 TEST_F(FrameTest, NotifyRemoteParentWithLoadingState) { | 455 TEST_F(FrameTest, NotifyRemoteParentWithLoadingState) { |
462 scoped_ptr<ViewAndFrame> child_view_and_frame( | 456 scoped_ptr<ViewAndFrame> child_view_and_frame( |
463 CreateChildViewAndFrame(root_view_and_frame())); | 457 CreateChildViewAndFrame(root_view_and_frame())); |
464 uint32_t child_frame_id = child_view_and_frame->view()->id(); | 458 uint32_t child_frame_id = child_view_and_frame->view()->id(); |
465 | 459 |
466 { | 460 { |
467 base::RunLoop run_loop; | 461 base::RunLoop run_loop; |
468 root_view_and_frame() | 462 root_view_and_frame() |
469 ->test_frame_tree_client() | 463 ->test_frame_client() |
470 ->set_on_loading_state_changed_callback(run_loop.QuitClosure()); | 464 ->set_on_loading_state_changed_callback(run_loop.QuitClosure()); |
471 | 465 |
472 child_view_and_frame->frame_tree_server()->LoadingStateChanged(true, .5); | 466 child_view_and_frame->server_frame()->LoadingStateChanged(true, .5); |
473 | 467 |
474 run_loop.Run(); | 468 run_loop.Run(); |
475 | 469 |
476 uint32_t frame_id = 0; | 470 uint32_t frame_id = 0; |
477 bool loading = false; | 471 bool loading = false; |
478 root_view_and_frame() | 472 root_view_and_frame() |
479 ->test_frame_tree_client() | 473 ->test_frame_client() |
480 ->last_loading_state_changed_notification(&frame_id, &loading); | 474 ->last_loading_state_changed_notification(&frame_id, &loading); |
481 EXPECT_EQ(child_frame_id, frame_id); | 475 EXPECT_EQ(child_frame_id, frame_id); |
482 EXPECT_TRUE(loading); | 476 EXPECT_TRUE(loading); |
483 } | 477 } |
484 { | 478 { |
485 base::RunLoop run_loop; | 479 base::RunLoop run_loop; |
486 root_view_and_frame() | 480 root_view_and_frame() |
487 ->test_frame_tree_client() | 481 ->test_frame_client() |
488 ->set_on_loading_state_changed_callback(run_loop.QuitClosure()); | 482 ->set_on_loading_state_changed_callback(run_loop.QuitClosure()); |
489 | 483 |
490 ASSERT_TRUE(child_view_and_frame); | 484 ASSERT_TRUE(child_view_and_frame); |
491 ASSERT_TRUE(child_view_and_frame->frame_tree_server()); | 485 ASSERT_TRUE(child_view_and_frame->server_frame()); |
492 | 486 |
493 child_view_and_frame->frame_tree_server()->LoadingStateChanged(false, 1); | 487 child_view_and_frame->server_frame()->LoadingStateChanged(false, 1); |
494 | 488 |
495 run_loop.Run(); | 489 run_loop.Run(); |
496 | 490 |
497 uint32_t frame_id = 0; | 491 uint32_t frame_id = 0; |
498 bool loading = false; | 492 bool loading = false; |
499 root_view_and_frame() | 493 root_view_and_frame() |
500 ->test_frame_tree_client() | 494 ->test_frame_client() |
501 ->last_loading_state_changed_notification(&frame_id, &loading); | 495 ->last_loading_state_changed_notification(&frame_id, &loading); |
502 EXPECT_EQ(child_frame_id, frame_id); | 496 EXPECT_EQ(child_frame_id, frame_id); |
503 EXPECT_FALSE(loading); | 497 EXPECT_FALSE(loading); |
504 } | 498 } |
505 } | 499 } |
506 | 500 |
507 TEST_F(FrameTest, NotifyRemoteParentWithLoadEvent) { | 501 TEST_F(FrameTest, NotifyRemoteParentWithLoadEvent) { |
508 scoped_ptr<ViewAndFrame> child_view_and_frame( | 502 scoped_ptr<ViewAndFrame> child_view_and_frame( |
509 CreateChildViewAndFrame(root_view_and_frame())); | 503 CreateChildViewAndFrame(root_view_and_frame())); |
510 uint32_t child_frame_id = child_view_and_frame->view()->id(); | 504 uint32_t child_frame_id = child_view_and_frame->view()->id(); |
511 | 505 |
512 base::RunLoop run_loop; | 506 base::RunLoop run_loop; |
513 root_view_and_frame() | 507 root_view_and_frame() |
514 ->test_frame_tree_client() | 508 ->test_frame_client() |
515 ->set_on_dispatch_load_event_callback(run_loop.QuitClosure()); | 509 ->set_on_dispatch_load_event_callback(run_loop.QuitClosure()); |
516 | 510 |
517 child_view_and_frame->frame_tree_server()->DispatchLoadEventToParent(); | 511 child_view_and_frame->server_frame()->DispatchLoadEventToParent(); |
518 | 512 |
519 run_loop.Run(); | 513 run_loop.Run(); |
520 | 514 |
521 uint32_t frame_id = root_view_and_frame() | 515 uint32_t frame_id = root_view_and_frame() |
522 ->test_frame_tree_client() | 516 ->test_frame_client() |
523 ->last_dispatch_load_event_frame_id(); | 517 ->last_dispatch_load_event_frame_id(); |
524 EXPECT_EQ(child_frame_id, frame_id); | 518 EXPECT_EQ(child_frame_id, frame_id); |
525 } | 519 } |
526 } // namespace web_view | 520 } // namespace web_view |
OLD | NEW |