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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const char kAddFrameWithEmptyPageScript[] = | 45 const char kAddFrameWithEmptyPageScript[] = |
46 "var iframe = document.createElement(\"iframe\");" | 46 "var iframe = document.createElement(\"iframe\");" |
47 "iframe.src = \"http://127.0.0.1:%u/empty_page.html\";" | 47 "iframe.src = \"http://127.0.0.1:%u/empty_page.html\";" |
48 "document.body.appendChild(iframe);"; | 48 "document.body.appendChild(iframe);"; |
49 | 49 |
50 void OnGotContentHandlerForRoot(bool* got_callback) { | 50 void OnGotContentHandlerForRoot(bool* got_callback) { |
51 *got_callback = true; | 51 *got_callback = true; |
52 ignore_result(WindowServerTestBase::QuitRunLoop()); | 52 ignore_result(WindowServerTestBase::QuitRunLoop()); |
53 } | 53 } |
54 | 54 |
55 mojo::ApplicationConnection* ApplicationConnectionForFrame(Frame* frame) { | 55 mojo::Connection* ConnectionForFrame(Frame* frame) { |
56 return static_cast<FrameConnection*>(frame->user_data()) | 56 return static_cast<FrameConnection*>(frame->user_data())->connection(); |
57 ->application_connection(); | |
58 } | 57 } |
59 | 58 |
60 std::string GetFrameText(ApplicationConnection* connection) { | 59 std::string GetFrameText(Connection* connection) { |
61 html_viewer::TestHTMLViewerPtr test_html_viewer; | 60 html_viewer::TestHTMLViewerPtr test_html_viewer; |
62 connection->ConnectToService(&test_html_viewer); | 61 connection->ConnectToService(&test_html_viewer); |
63 std::string result; | 62 std::string result; |
64 test_html_viewer->GetContentAsText([&result](const String& mojo_string) { | 63 test_html_viewer->GetContentAsText([&result](const String& mojo_string) { |
65 result = mojo_string; | 64 result = mojo_string; |
66 ASSERT_TRUE(WindowServerTestBase::QuitRunLoop()); | 65 ASSERT_TRUE(WindowServerTestBase::QuitRunLoop()); |
67 }); | 66 }); |
68 if (!WindowServerTestBase::DoRunLoopWithTimeout()) | 67 if (!WindowServerTestBase::DoRunLoopWithTimeout()) |
69 ADD_FAILURE() << "Timed out waiting for execute to complete"; | 68 ADD_FAILURE() << "Timed out waiting for execute to complete"; |
70 // test_html_viewer.WaitForIncomingResponse(); | 69 // test_html_viewer.WaitForIncomingResponse(); |
71 return result; | 70 return result; |
72 } | 71 } |
73 | 72 |
74 scoped_ptr<base::Value> ExecuteScript(ApplicationConnection* connection, | 73 scoped_ptr<base::Value> ExecuteScript(Connection* connection, |
75 const std::string& script) { | 74 const std::string& script) { |
76 html_viewer::TestHTMLViewerPtr test_html_viewer; | 75 html_viewer::TestHTMLViewerPtr test_html_viewer; |
77 connection->ConnectToService(&test_html_viewer); | 76 connection->ConnectToService(&test_html_viewer); |
78 scoped_ptr<base::Value> result; | 77 scoped_ptr<base::Value> result; |
79 test_html_viewer->ExecuteScript(script, [&result](const String& json_string) { | 78 test_html_viewer->ExecuteScript(script, [&result](const String& json_string) { |
80 result = base::JSONReader::Read(json_string.To<std::string>()); | 79 result = base::JSONReader::Read(json_string.To<std::string>()); |
81 ASSERT_TRUE(WindowServerTestBase::QuitRunLoop()); | 80 ASSERT_TRUE(WindowServerTestBase::QuitRunLoop()); |
82 }); | 81 }); |
83 if (!WindowServerTestBase::DoRunLoopWithTimeout()) | 82 if (!WindowServerTestBase::DoRunLoopWithTimeout()) |
84 ADD_FAILURE() << "Timed out waiting for execute to complete"; | 83 ADD_FAILURE() << "Timed out waiting for execute to complete"; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // script) a frame showing the same empty page. | 174 // script) a frame showing the same empty page. |
176 Frame* LoadEmptyPageAndCreateFrame() { | 175 Frame* LoadEmptyPageAndCreateFrame() { |
177 mus::Window* embed_window = window_manager()->NewWindow(); | 176 mus::Window* embed_window = window_manager()->NewWindow(); |
178 frame_tree_delegate_.reset(new TestFrameTreeDelegateImpl(shell())); | 177 frame_tree_delegate_.reset(new TestFrameTreeDelegateImpl(shell())); |
179 FrameConnection* root_connection = InitFrameTree( | 178 FrameConnection* root_connection = InitFrameTree( |
180 embed_window, "http://127.0.0.1:%u/empty_page2.html"); | 179 embed_window, "http://127.0.0.1:%u/empty_page2.html"); |
181 if (!root_connection) { | 180 if (!root_connection) { |
182 ADD_FAILURE() << "unable to establish root connection"; | 181 ADD_FAILURE() << "unable to establish root connection"; |
183 return nullptr; | 182 return nullptr; |
184 } | 183 } |
185 const std::string frame_text = | 184 const std::string frame_text = GetFrameText(root_connection->connection()); |
186 GetFrameText(root_connection->application_connection()); | |
187 if (frame_text != "child2") { | 185 if (frame_text != "child2") { |
188 ADD_FAILURE() << "unexpected text " << frame_text; | 186 ADD_FAILURE() << "unexpected text " << frame_text; |
189 return nullptr; | 187 return nullptr; |
190 } | 188 } |
191 | 189 |
192 return CreateEmptyChildFrame(frame_tree_->root()); | 190 return CreateEmptyChildFrame(frame_tree_->root()); |
193 } | 191 } |
194 | 192 |
195 Frame* CreateEmptyChildFrame(Frame* parent) { | 193 Frame* CreateEmptyChildFrame(Frame* parent) { |
196 const size_t initial_frame_count = parent->children().size(); | 194 const size_t initial_frame_count = parent->children().size(); |
197 // Dynamically add a new frame. | 195 // Dynamically add a new frame. |
198 ExecuteScript(ApplicationConnectionForFrame(parent), | 196 ExecuteScript(ConnectionForFrame(parent), |
199 AddPortToString(kAddFrameWithEmptyPageScript)); | 197 AddPortToString(kAddFrameWithEmptyPageScript)); |
200 | 198 |
201 frame_tree_delegate_->WaitForChildFrameCount(parent, | 199 frame_tree_delegate_->WaitForChildFrameCount(parent, |
202 initial_frame_count + 1); | 200 initial_frame_count + 1); |
203 if (HasFatalFailure()) | 201 if (HasFatalFailure()) |
204 return nullptr; | 202 return nullptr; |
205 | 203 |
206 return parent->FindFrame(parent->window()->children().back()->id()); | 204 return parent->FindFrame(parent->window()->children().back()->id()); |
207 } | 205 } |
208 | 206 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 #define MAYBE_PageWithSingleFrame PageWithSingleFrame | 269 #define MAYBE_PageWithSingleFrame PageWithSingleFrame |
272 #endif | 270 #endif |
273 TEST_F(HTMLFrameTest, MAYBE_PageWithSingleFrame) { | 271 TEST_F(HTMLFrameTest, MAYBE_PageWithSingleFrame) { |
274 mus::Window* embed_window = window_manager()->NewWindow(); | 272 mus::Window* embed_window = window_manager()->NewWindow(); |
275 | 273 |
276 FrameConnection* root_connection = InitFrameTree( | 274 FrameConnection* root_connection = InitFrameTree( |
277 embed_window, "http://127.0.0.1:%u/page_with_single_frame.html"); | 275 embed_window, "http://127.0.0.1:%u/page_with_single_frame.html"); |
278 ASSERT_TRUE(root_connection); | 276 ASSERT_TRUE(root_connection); |
279 | 277 |
280 ASSERT_EQ("Page with single frame", | 278 ASSERT_EQ("Page with single frame", |
281 GetFrameText(root_connection->application_connection())); | 279 GetFrameText(root_connection->connection())); |
282 | 280 |
283 ASSERT_NO_FATAL_FAILURE( | 281 ASSERT_NO_FATAL_FAILURE( |
284 frame_tree_delegate_->WaitForChildFrameCount(frame_tree_->root(), 1u)); | 282 frame_tree_delegate_->WaitForChildFrameCount(frame_tree_->root(), 1u)); |
285 | 283 |
286 ASSERT_EQ(1u, embed_window->children().size()); | 284 ASSERT_EQ(1u, embed_window->children().size()); |
287 Frame* child_frame = | 285 Frame* child_frame = |
288 frame_tree_->root()->FindFrame(embed_window->children()[0]->id()); | 286 frame_tree_->root()->FindFrame(embed_window->children()[0]->id()); |
289 ASSERT_TRUE(child_frame); | 287 ASSERT_TRUE(child_frame); |
290 | 288 |
291 ASSERT_EQ("child", | 289 ASSERT_EQ("child", |
292 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) | 290 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) |
293 ->application_connection())); | 291 ->connection())); |
294 } | 292 } |
295 | 293 |
296 // Creates two frames. The parent navigates the child frame by way of changing | 294 // Creates two frames. The parent navigates the child frame by way of changing |
297 // the location of the child frame. | 295 // the location of the child frame. |
298 // Crashes on linux_chromium_rel_ng only. http://crbug.com/567337 | 296 // Crashes on linux_chromium_rel_ng only. http://crbug.com/567337 |
299 #if defined(OS_LINUX) | 297 #if defined(OS_LINUX) |
300 #define MAYBE_ChangeLocationOfChildFrame DISABLED_ChangeLocationOfChildFrame | 298 #define MAYBE_ChangeLocationOfChildFrame DISABLED_ChangeLocationOfChildFrame |
301 #else | 299 #else |
302 #define MAYBE_ChangeLocationOfChildFrame ChangeLocationOfChildFrame | 300 #define MAYBE_ChangeLocationOfChildFrame ChangeLocationOfChildFrame |
303 #endif | 301 #endif |
304 TEST_F(HTMLFrameTest, MAYBE_ChangeLocationOfChildFrame) { | 302 TEST_F(HTMLFrameTest, MAYBE_ChangeLocationOfChildFrame) { |
305 mus::Window* embed_window = window_manager()->NewWindow(); | 303 mus::Window* embed_window = window_manager()->NewWindow(); |
306 | 304 |
307 ASSERT_TRUE(InitFrameTree( | 305 ASSERT_TRUE(InitFrameTree( |
308 embed_window, "http://127.0.0.1:%u/page_with_single_frame.html")); | 306 embed_window, "http://127.0.0.1:%u/page_with_single_frame.html")); |
309 | 307 |
310 // page_with_single_frame contains a child frame. The child frame should | 308 // page_with_single_frame contains a child frame. The child frame should |
311 // create a new View and Frame. | 309 // create a new View and Frame. |
312 ASSERT_NO_FATAL_FAILURE( | 310 ASSERT_NO_FATAL_FAILURE( |
313 frame_tree_delegate_->WaitForChildFrameCount(frame_tree_->root(), 1u)); | 311 frame_tree_delegate_->WaitForChildFrameCount(frame_tree_->root(), 1u)); |
314 | 312 |
315 Frame* child_frame = frame_tree_->root()->children().back(); | 313 Frame* child_frame = frame_tree_->root()->children().back(); |
316 | 314 |
317 ASSERT_EQ("child", | 315 ASSERT_EQ("child", |
318 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) | 316 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) |
319 ->application_connection())); | 317 ->connection())); |
320 | 318 |
321 // Change the location and wait for the navigation to occur. | 319 // Change the location and wait for the navigation to occur. |
322 const char kNavigateFrame[] = | 320 const char kNavigateFrame[] = |
323 "window.frames[0].location = " | 321 "window.frames[0].location = " |
324 "'http://127.0.0.1:%u/empty_page2.html'"; | 322 "'http://127.0.0.1:%u/empty_page2.html'"; |
325 frame_tree_delegate_->ClearGotNavigate(child_frame); | 323 frame_tree_delegate_->ClearGotNavigate(child_frame); |
326 ExecuteScript(ApplicationConnectionForFrame(frame_tree_->root()), | 324 ExecuteScript(ConnectionForFrame(frame_tree_->root()), |
327 AddPortToString(kNavigateFrame)); | 325 AddPortToString(kNavigateFrame)); |
328 ASSERT_TRUE(frame_tree_delegate_->WaitForFrameNavigation(child_frame)); | 326 ASSERT_TRUE(frame_tree_delegate_->WaitForFrameNavigation(child_frame)); |
329 | 327 |
330 // There should still only be one frame. | 328 // There should still only be one frame. |
331 ASSERT_EQ(1u, frame_tree_->root()->children().size()); | 329 ASSERT_EQ(1u, frame_tree_->root()->children().size()); |
332 | 330 |
333 // The navigation should have changed the text of the frame. | 331 // The navigation should have changed the text of the frame. |
334 ASSERT_TRUE(child_frame->user_data()); | 332 ASSERT_TRUE(child_frame->user_data()); |
335 ASSERT_EQ("child2", | 333 ASSERT_EQ("child2", |
336 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) | 334 GetFrameText(static_cast<FrameConnection*>(child_frame->user_data()) |
337 ->application_connection())); | 335 ->connection())); |
338 } | 336 } |
339 | 337 |
340 TEST_F(HTMLFrameTest, DynamicallyAddFrameAndVerifyParent) { | 338 TEST_F(HTMLFrameTest, DynamicallyAddFrameAndVerifyParent) { |
341 Frame* child_frame = LoadEmptyPageAndCreateFrame(); | 339 Frame* child_frame = LoadEmptyPageAndCreateFrame(); |
342 ASSERT_TRUE(child_frame); | 340 ASSERT_TRUE(child_frame); |
343 | 341 |
344 mojo::ApplicationConnection* child_frame_connection = | 342 mojo::Connection* child_frame_connection = ConnectionForFrame(child_frame); |
345 ApplicationConnectionForFrame(child_frame); | |
346 | 343 |
347 ASSERT_EQ("child", GetFrameText(child_frame_connection)); | 344 ASSERT_EQ("child", GetFrameText(child_frame_connection)); |
348 // The child's parent should not be itself: | 345 // The child's parent should not be itself: |
349 const char kGetWindowParentNameScript[] = | 346 const char kGetWindowParentNameScript[] = |
350 "window.parent == window ? 'parent is self' : 'parent not self';"; | 347 "window.parent == window ? 'parent is self' : 'parent not self';"; |
351 scoped_ptr<base::Value> parent_value( | 348 scoped_ptr<base::Value> parent_value( |
352 ExecuteScript(child_frame_connection, kGetWindowParentNameScript)); | 349 ExecuteScript(child_frame_connection, kGetWindowParentNameScript)); |
353 ASSERT_TRUE(parent_value->IsType(base::Value::TYPE_LIST)); | 350 ASSERT_TRUE(parent_value->IsType(base::Value::TYPE_LIST)); |
354 base::ListValue* parent_list; | 351 base::ListValue* parent_list; |
355 ASSERT_TRUE(parent_value->GetAsList(&parent_list)); | 352 ASSERT_TRUE(parent_value->GetAsList(&parent_list)); |
356 ASSERT_EQ(1u, parent_list->GetSize()); | 353 ASSERT_EQ(1u, parent_list->GetSize()); |
357 std::string parent_name; | 354 std::string parent_name; |
358 ASSERT_TRUE(parent_list->GetString(0u, &parent_name)); | 355 ASSERT_TRUE(parent_list->GetString(0u, &parent_name)); |
359 EXPECT_EQ("parent not self", parent_name); | 356 EXPECT_EQ("parent not self", parent_name); |
360 } | 357 } |
361 | 358 |
362 TEST_F(HTMLFrameTest, DynamicallyAddFrameAndSeeNameChange) { | 359 TEST_F(HTMLFrameTest, DynamicallyAddFrameAndSeeNameChange) { |
363 Frame* child_frame = LoadEmptyPageAndCreateFrame(); | 360 Frame* child_frame = LoadEmptyPageAndCreateFrame(); |
364 ASSERT_TRUE(child_frame); | 361 ASSERT_TRUE(child_frame); |
365 | 362 |
366 mojo::ApplicationConnection* child_frame_connection = | 363 mojo::Connection* child_frame_connection = ConnectionForFrame(child_frame); |
367 ApplicationConnectionForFrame(child_frame); | |
368 | 364 |
369 // Change the name of the child's window. | 365 // Change the name of the child's window. |
370 ExecuteScript(child_frame_connection, "window.name = 'new_child';"); | 366 ExecuteScript(child_frame_connection, "window.name = 'new_child';"); |
371 | 367 |
372 // Eventually the parent should see the change. There is no convenient way | 368 // Eventually the parent should see the change. There is no convenient way |
373 // to observe this change, so we repeatedly ask for it and timeout if we | 369 // to observe this change, so we repeatedly ask for it and timeout if we |
374 // never get the right value. | 370 // never get the right value. |
375 const base::TimeTicks start_time(base::TimeTicks::Now()); | 371 const base::TimeTicks start_time(base::TimeTicks::Now()); |
376 std::string find_window_result; | 372 std::string find_window_result; |
377 do { | 373 do { |
378 find_window_result.clear(); | 374 find_window_result.clear(); |
379 scoped_ptr<base::Value> script_value( | 375 scoped_ptr<base::Value> script_value( |
380 ExecuteScript(ApplicationConnectionForFrame(frame_tree_->root()), | 376 ExecuteScript(ConnectionForFrame(frame_tree_->root()), |
381 "window.frames['new_child'] != null ? 'found frame' : " | 377 "window.frames['new_child'] != null ? 'found frame' : " |
382 "'unable to find frame';")); | 378 "'unable to find frame';")); |
383 if (script_value->IsType(base::Value::TYPE_LIST)) { | 379 if (script_value->IsType(base::Value::TYPE_LIST)) { |
384 base::ListValue* script_value_as_list; | 380 base::ListValue* script_value_as_list; |
385 if (script_value->GetAsList(&script_value_as_list) && | 381 if (script_value->GetAsList(&script_value_as_list) && |
386 script_value_as_list->GetSize() == 1) { | 382 script_value_as_list->GetSize() == 1) { |
387 script_value_as_list->GetString(0u, &find_window_result); | 383 script_value_as_list->GetString(0u, &find_window_result); |
388 } | 384 } |
389 } | 385 } |
390 } while (find_window_result != "found frame" && | 386 } while (find_window_result != "found frame" && |
(...skipping 16 matching lines...) Expand all Loading... |
407 const char kGetChildChildFrameCount[] = | 403 const char kGetChildChildFrameCount[] = |
408 "if (window.frames.length > 0)" | 404 "if (window.frames.length > 0)" |
409 " window.frames[0].frames.length.toString();" | 405 " window.frames[0].frames.length.toString();" |
410 "else" | 406 "else" |
411 " '0';"; | 407 " '0';"; |
412 const base::TimeTicks start_time(base::TimeTicks::Now()); | 408 const base::TimeTicks start_time(base::TimeTicks::Now()); |
413 std::string child_child_frame_count; | 409 std::string child_child_frame_count; |
414 do { | 410 do { |
415 child_child_frame_count.clear(); | 411 child_child_frame_count.clear(); |
416 scoped_ptr<base::Value> script_value( | 412 scoped_ptr<base::Value> script_value( |
417 ExecuteScript(ApplicationConnectionForFrame(frame_tree_->root()), | 413 ExecuteScript(ConnectionForFrame(frame_tree_->root()), |
418 kGetChildChildFrameCount)); | 414 kGetChildChildFrameCount)); |
419 if (script_value->IsType(base::Value::TYPE_LIST)) { | 415 if (script_value->IsType(base::Value::TYPE_LIST)) { |
420 base::ListValue* script_value_as_list; | 416 base::ListValue* script_value_as_list; |
421 if (script_value->GetAsList(&script_value_as_list) && | 417 if (script_value->GetAsList(&script_value_as_list) && |
422 script_value_as_list->GetSize() == 1) { | 418 script_value_as_list->GetSize() == 1) { |
423 script_value_as_list->GetString(0u, &child_child_frame_count); | 419 script_value_as_list->GetString(0u, &child_child_frame_count); |
424 } | 420 } |
425 } | 421 } |
426 } while (child_child_frame_count != "1" && | 422 } while (child_child_frame_count != "1" && |
427 base::TimeTicks::Now() - start_time < | 423 base::TimeTicks::Now() - start_time < |
428 TestTimeouts::action_timeout()); | 424 TestTimeouts::action_timeout()); |
429 EXPECT_EQ("1", child_child_frame_count); | 425 EXPECT_EQ("1", child_child_frame_count); |
430 | 426 |
431 // Remove the child's child and make sure the root doesn't see it anymore. | 427 // Remove the child's child and make sure the root doesn't see it anymore. |
432 const char kRemoveLastIFrame[] = | 428 const char kRemoveLastIFrame[] = |
433 "document.body.removeChild(document.body.lastChild);"; | 429 "document.body.removeChild(document.body.lastChild);"; |
434 ExecuteScript(ApplicationConnectionForFrame(child_frame), kRemoveLastIFrame); | 430 ExecuteScript(ConnectionForFrame(child_frame), kRemoveLastIFrame); |
435 do { | 431 do { |
436 child_child_frame_count.clear(); | 432 child_child_frame_count.clear(); |
437 scoped_ptr<base::Value> script_value( | 433 scoped_ptr<base::Value> script_value( |
438 ExecuteScript(ApplicationConnectionForFrame(frame_tree_->root()), | 434 ExecuteScript(ConnectionForFrame(frame_tree_->root()), |
439 kGetChildChildFrameCount)); | 435 kGetChildChildFrameCount)); |
440 if (script_value->IsType(base::Value::TYPE_LIST)) { | 436 if (script_value->IsType(base::Value::TYPE_LIST)) { |
441 base::ListValue* script_value_as_list; | 437 base::ListValue* script_value_as_list; |
442 if (script_value->GetAsList(&script_value_as_list) && | 438 if (script_value->GetAsList(&script_value_as_list) && |
443 script_value_as_list->GetSize() == 1) { | 439 script_value_as_list->GetSize() == 1) { |
444 script_value_as_list->GetString(0u, &child_child_frame_count); | 440 script_value_as_list->GetString(0u, &child_child_frame_count); |
445 } | 441 } |
446 } | 442 } |
447 } while (child_child_frame_count != "0" && | 443 } while (child_child_frame_count != "0" && |
448 base::TimeTicks::Now() - start_time < | 444 base::TimeTicks::Now() - start_time < |
449 TestTimeouts::action_timeout()); | 445 TestTimeouts::action_timeout()); |
450 ASSERT_EQ("0", child_child_frame_count); | 446 ASSERT_EQ("0", child_child_frame_count); |
451 } | 447 } |
452 | 448 |
453 // Verifies PostMessage() works across frames. | 449 // Verifies PostMessage() works across frames. |
454 TEST_F(HTMLFrameTest, PostMessage) { | 450 TEST_F(HTMLFrameTest, PostMessage) { |
455 Frame* child_frame = LoadEmptyPageAndCreateFrame(); | 451 Frame* child_frame = LoadEmptyPageAndCreateFrame(); |
456 ASSERT_TRUE(child_frame); | 452 ASSERT_TRUE(child_frame); |
457 | 453 |
458 mojo::ApplicationConnection* child_frame_connection = | 454 mojo::Connection* child_frame_connection = ConnectionForFrame(child_frame); |
459 ApplicationConnectionForFrame(child_frame); | |
460 ASSERT_EQ("child", GetFrameText(child_frame_connection)); | 455 ASSERT_EQ("child", GetFrameText(child_frame_connection)); |
461 | 456 |
462 // Register an event handler in the child frame. | 457 // Register an event handler in the child frame. |
463 const char kRegisterPostMessageHandler[] = | 458 const char kRegisterPostMessageHandler[] = |
464 "window.messageData = null;" | 459 "window.messageData = null;" |
465 "function messageFunction(event) {" | 460 "function messageFunction(event) {" |
466 " window.messageData = event.data;" | 461 " window.messageData = event.data;" |
467 "}" | 462 "}" |
468 "window.addEventListener('message', messageFunction, false);"; | 463 "window.addEventListener('message', messageFunction, false);"; |
469 ExecuteScript(child_frame_connection, kRegisterPostMessageHandler); | 464 ExecuteScript(child_frame_connection, kRegisterPostMessageHandler); |
470 | 465 |
471 // Post a message from the parent to the child. | 466 // Post a message from the parent to the child. |
472 const char kPostMessageFromParent[] = | 467 const char kPostMessageFromParent[] = |
473 "window.frames[0].postMessage('hello from parent', '*');"; | 468 "window.frames[0].postMessage('hello from parent', '*');"; |
474 ExecuteScript(ApplicationConnectionForFrame(frame_tree_->root()), | 469 ExecuteScript(ConnectionForFrame(frame_tree_->root()), |
475 kPostMessageFromParent); | 470 kPostMessageFromParent); |
476 | 471 |
477 // Wait for the child frame to see the message. | 472 // Wait for the child frame to see the message. |
478 const base::TimeTicks start_time(base::TimeTicks::Now()); | 473 const base::TimeTicks start_time(base::TimeTicks::Now()); |
479 std::string message_in_child; | 474 std::string message_in_child; |
480 do { | 475 do { |
481 const char kGetMessageData[] = "window.messageData;"; | 476 const char kGetMessageData[] = "window.messageData;"; |
482 scoped_ptr<base::Value> script_value( | 477 scoped_ptr<base::Value> script_value( |
483 ExecuteScript(child_frame_connection, kGetMessageData)); | 478 ExecuteScript(child_frame_connection, kGetMessageData)); |
484 if (script_value->IsType(base::Value::TYPE_LIST)) { | 479 if (script_value->IsType(base::Value::TYPE_LIST)) { |
485 base::ListValue* script_value_as_list; | 480 base::ListValue* script_value_as_list; |
486 if (script_value->GetAsList(&script_value_as_list) && | 481 if (script_value->GetAsList(&script_value_as_list) && |
487 script_value_as_list->GetSize() == 1) { | 482 script_value_as_list->GetSize() == 1) { |
488 script_value_as_list->GetString(0u, &message_in_child); | 483 script_value_as_list->GetString(0u, &message_in_child); |
489 } | 484 } |
490 } | 485 } |
491 } while (message_in_child != "hello from parent" && | 486 } while (message_in_child != "hello from parent" && |
492 base::TimeTicks::Now() - start_time < | 487 base::TimeTicks::Now() - start_time < |
493 TestTimeouts::action_timeout()); | 488 TestTimeouts::action_timeout()); |
494 EXPECT_EQ("hello from parent", message_in_child); | 489 EXPECT_EQ("hello from parent", message_in_child); |
495 } | 490 } |
496 | 491 |
497 } // namespace mojo | 492 } // namespace mojo |
OLD | NEW |