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

Side by Side Diff: third_party/WebKit/Source/web/tests/WebFrameTest.cpp

Issue 2837523002: Add ASSERTs to WebFrameTest to ensure frame parameters are correct (Closed)
Patch Set: Rebase Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 4431 matching lines...) Expand 10 before | Expand all | Expand 10 after
4442 bool Equals(Notification* other) { 4442 bool Equals(Notification* other) {
4443 return other && frame == other->frame && context == other->context && 4443 return other && frame == other->frame && context == other->context &&
4444 world_id == other->world_id; 4444 world_id == other->world_id;
4445 } 4445 }
4446 4446
4447 WebLocalFrame* frame; 4447 WebLocalFrame* frame;
4448 v8::Persistent<v8::Context> context; 4448 v8::Persistent<v8::Context> context;
4449 int world_id; 4449 int world_id;
4450 }; 4450 };
4451 4451
4452 ContextLifetimeTestWebFrameClient(
4453 Vector<std::unique_ptr<Notification>>& create_notifications,
4454 Vector<std::unique_ptr<Notification>>& release_notifications)
4455 : create_notifications_(create_notifications),
4456 release_notifications_(release_notifications) {}
4457
4452 ~ContextLifetimeTestWebFrameClient() override { Reset(); } 4458 ~ContextLifetimeTestWebFrameClient() override { Reset(); }
4453 4459
4454 void Reset() { 4460 void Reset() {
4455 create_notifications.clear(); 4461 create_notifications_.clear();
4456 release_notifications.clear(); 4462 release_notifications_.clear();
4457 } 4463 }
4458 4464
4459 Vector<std::unique_ptr<Notification>> create_notifications; 4465 private:
4460 Vector<std::unique_ptr<Notification>> release_notifications; 4466 Vector<std::unique_ptr<Notification>>& create_notifications_;
4467 Vector<std::unique_ptr<Notification>>& release_notifications_;
4461 4468
4462 private:
4463 void DidCreateScriptContext(WebLocalFrame* frame, 4469 void DidCreateScriptContext(WebLocalFrame* frame,
4464 v8::Local<v8::Context> context, 4470 v8::Local<v8::Context> context,
4465 int world_id) override { 4471 int world_id) override {
4466 create_notifications.push_back( 4472 ASSERT_EQ(Frame(), frame);
4473 create_notifications_.push_back(
4467 WTF::MakeUnique<Notification>(frame, context, world_id)); 4474 WTF::MakeUnique<Notification>(frame, context, world_id));
4468 } 4475 }
4469 4476
4470 void WillReleaseScriptContext(WebLocalFrame* frame, 4477 void WillReleaseScriptContext(WebLocalFrame* frame,
4471 v8::Local<v8::Context> context, 4478 v8::Local<v8::Context> context,
4472 int world_id) override { 4479 int world_id) override {
4473 release_notifications.push_back( 4480 ASSERT_EQ(Frame(), frame);
4481 release_notifications_.push_back(
4474 WTF::MakeUnique<Notification>(frame, context, world_id)); 4482 WTF::MakeUnique<Notification>(frame, context, world_id));
4475 } 4483 }
4476 }; 4484 };
4477 4485
4486 class ContextLifetimeTestMainFrameClient
4487 : public ContextLifetimeTestWebFrameClient {
4488 public:
4489 ContextLifetimeTestMainFrameClient(
4490 Vector<std::unique_ptr<Notification>>& create_notifications,
4491 Vector<std::unique_ptr<Notification>>& release_notifications)
4492 : ContextLifetimeTestWebFrameClient(create_notifications,
4493 release_notifications),
4494 child_client_(create_notifications, release_notifications) {}
4495
4496 WebLocalFrame* CreateChildFrame(
4497 WebLocalFrame* parent,
4498 WebTreeScopeType scope,
4499 const WebString& name,
4500 const WebString& fallback_name,
4501 WebSandboxFlags sandbox_flags,
4502 const WebParsedFeaturePolicy& container_policy,
4503 const WebFrameOwnerProperties&) override {
4504 WebLocalFrame* frame =
4505 WebLocalFrame::Create(scope, &child_client_, nullptr, nullptr);
4506 child_client_.SetFrame(frame);
4507 parent->AppendChild(frame);
4508 return frame;
4509 }
4510
4511 ContextLifetimeTestWebFrameClient& ChildClient() { return child_client_; }
4512
4513 private:
4514 ContextLifetimeTestWebFrameClient child_client_;
4515 };
4516
4478 TEST_P(ParameterizedWebFrameTest, ContextNotificationsLoadUnload) { 4517 TEST_P(ParameterizedWebFrameTest, ContextNotificationsLoadUnload) {
4479 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 4518 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
4480 4519
4481 RegisterMockedHttpURLLoad("context_notifications_test.html"); 4520 RegisterMockedHttpURLLoad("context_notifications_test.html");
4482 RegisterMockedHttpURLLoad("context_notifications_test_frame.html"); 4521 RegisterMockedHttpURLLoad("context_notifications_test_frame.html");
4483 4522
4484 // Load a frame with an iframe, make sure we get the right create 4523 // Load a frame with an iframe, make sure we get the right create
4485 // notifications. 4524 // notifications.
4486 ContextLifetimeTestWebFrameClient web_frame_client; 4525 Vector<std::unique_ptr<ContextLifetimeTestWebFrameClient::Notification>>
4526 create_notifications;
4527 Vector<std::unique_ptr<ContextLifetimeTestWebFrameClient::Notification>>
4528 release_notifications;
4529 ContextLifetimeTestMainFrameClient web_frame_client(create_notifications,
4530 release_notifications);
4487 FrameTestHelpers::WebViewHelper web_view_helper; 4531 FrameTestHelpers::WebViewHelper web_view_helper;
4488 web_view_helper.InitializeAndLoad( 4532 web_view_helper.InitializeAndLoad(
4489 base_url_ + "context_notifications_test.html", true, &web_frame_client); 4533 base_url_ + "context_notifications_test.html", true, &web_frame_client);
4490 4534
4491 WebFrame* main_frame = web_view_helper.WebView()->MainFrame(); 4535 WebFrame* main_frame = web_view_helper.WebView()->MainFrame();
4492 WebFrame* child_frame = main_frame->FirstChild(); 4536 WebFrame* child_frame = main_frame->FirstChild();
4493 4537
4494 ASSERT_EQ(2u, web_frame_client.create_notifications.size()); 4538 ASSERT_EQ(2u, create_notifications.size());
4495 EXPECT_EQ(0u, web_frame_client.release_notifications.size()); 4539 EXPECT_EQ(0u, release_notifications.size());
4496 4540
4497 auto& first_create_notification = web_frame_client.create_notifications[0]; 4541 auto& first_create_notification = create_notifications[0];
4498 auto& second_create_notification = web_frame_client.create_notifications[1]; 4542 auto& second_create_notification = create_notifications[1];
4499 4543
4500 EXPECT_EQ(main_frame, first_create_notification->frame); 4544 EXPECT_EQ(main_frame, first_create_notification->frame);
4501 EXPECT_EQ(main_frame->MainWorldScriptContext(), 4545 EXPECT_EQ(main_frame->MainWorldScriptContext(),
4502 first_create_notification->context); 4546 first_create_notification->context);
4503 EXPECT_EQ(0, first_create_notification->world_id); 4547 EXPECT_EQ(0, first_create_notification->world_id);
4504 4548
4505 EXPECT_EQ(child_frame, second_create_notification->frame); 4549 EXPECT_EQ(child_frame, second_create_notification->frame);
4506 EXPECT_EQ(child_frame->MainWorldScriptContext(), 4550 EXPECT_EQ(child_frame->MainWorldScriptContext(),
4507 second_create_notification->context); 4551 second_create_notification->context);
4508 EXPECT_EQ(0, second_create_notification->world_id); 4552 EXPECT_EQ(0, second_create_notification->world_id);
4509 4553
4510 // Close the view. We should get two release notifications that are exactly 4554 // Close the view. We should get two release notifications that are exactly
4511 // the same as the create ones, in reverse order. 4555 // the same as the create ones, in reverse order.
4512 web_view_helper.Reset(); 4556 web_view_helper.Reset();
4513 4557
4514 ASSERT_EQ(2u, web_frame_client.release_notifications.size()); 4558 ASSERT_EQ(2u, release_notifications.size());
4515 auto& first_release_notification = web_frame_client.release_notifications[0]; 4559 auto& first_release_notification = release_notifications[0];
4516 auto& second_release_notification = web_frame_client.release_notifications[1]; 4560 auto& second_release_notification = release_notifications[1];
4517 4561
4518 ASSERT_TRUE( 4562 ASSERT_TRUE(
4519 first_create_notification->Equals(second_release_notification.get())); 4563 first_create_notification->Equals(second_release_notification.get()));
4520 ASSERT_TRUE( 4564 ASSERT_TRUE(
4521 second_create_notification->Equals(first_release_notification.get())); 4565 second_create_notification->Equals(first_release_notification.get()));
4522 } 4566 }
4523 4567
4524 TEST_P(ParameterizedWebFrameTest, ContextNotificationsReload) { 4568 TEST_P(ParameterizedWebFrameTest, ContextNotificationsReload) {
4525 v8::HandleScope handle_scope(v8::Isolate::GetCurrent()); 4569 v8::HandleScope handle_scope(v8::Isolate::GetCurrent());
4526 4570
4527 RegisterMockedHttpURLLoad("context_notifications_test.html"); 4571 RegisterMockedHttpURLLoad("context_notifications_test.html");
4528 RegisterMockedHttpURLLoad("context_notifications_test_frame.html"); 4572 RegisterMockedHttpURLLoad("context_notifications_test_frame.html");
4529 4573
4530 ContextLifetimeTestWebFrameClient web_frame_client; 4574 Vector<std::unique_ptr<ContextLifetimeTestWebFrameClient::Notification>>
4575 create_notifications;
4576 Vector<std::unique_ptr<ContextLifetimeTestWebFrameClient::Notification>>
4577 release_notifications;
4578 ContextLifetimeTestMainFrameClient web_frame_client(create_notifications,
4579 release_notifications);
4531 FrameTestHelpers::WebViewHelper web_view_helper; 4580 FrameTestHelpers::WebViewHelper web_view_helper;
4532 web_view_helper.InitializeAndLoad( 4581 web_view_helper.InitializeAndLoad(
4533 base_url_ + "context_notifications_test.html", true, &web_frame_client); 4582 base_url_ + "context_notifications_test.html", true, &web_frame_client);
4534 4583
4535 // Refresh, we should get two release notifications and two more create 4584 // Refresh, we should get two release notifications and two more create
4536 // notifications. 4585 // notifications.
4537 FrameTestHelpers::ReloadFrame(web_view_helper.WebView()->MainFrame()); 4586 FrameTestHelpers::ReloadFrame(web_view_helper.WebView()->MainFrame());
4538 ASSERT_EQ(4u, web_frame_client.create_notifications.size()); 4587 ASSERT_EQ(4u, create_notifications.size());
4539 ASSERT_EQ(2u, web_frame_client.release_notifications.size()); 4588 ASSERT_EQ(2u, release_notifications.size());
4540 4589
4541 // The two release notifications we got should be exactly the same as the 4590 // The two release notifications we got should be exactly the same as the
4542 // first two create notifications. 4591 // first two create notifications.
4543 for (size_t i = 0; i < web_frame_client.release_notifications.size(); ++i) { 4592 for (size_t i = 0; i < release_notifications.size(); ++i) {
4544 EXPECT_TRUE(web_frame_client.release_notifications[i]->Equals( 4593 EXPECT_TRUE(release_notifications[i]->Equals(
4545 web_frame_client 4594 create_notifications[create_notifications.size() - 3 - i].get()));
4546 .create_notifications[web_frame_client.create_notifications.size() -
4547 3 - i]
4548 .get()));
4549 } 4595 }
4550 4596
4551 // The last two create notifications should be for the current frames and 4597 // The last two create notifications should be for the current frames and
4552 // context. 4598 // context.
4553 WebFrame* main_frame = web_view_helper.WebView()->MainFrame(); 4599 WebFrame* main_frame = web_view_helper.WebView()->MainFrame();
4554 WebFrame* child_frame = main_frame->FirstChild(); 4600 WebFrame* child_frame = main_frame->FirstChild();
4555 auto& first_refresh_notification = web_frame_client.create_notifications[2]; 4601 auto& first_refresh_notification = create_notifications[2];
4556 auto& second_refresh_notification = web_frame_client.create_notifications[3]; 4602 auto& second_refresh_notification = create_notifications[3];
4557 4603
4558 EXPECT_EQ(main_frame, first_refresh_notification->frame); 4604 EXPECT_EQ(main_frame, first_refresh_notification->frame);
4559 EXPECT_EQ(main_frame->MainWorldScriptContext(), 4605 EXPECT_EQ(main_frame->MainWorldScriptContext(),
4560 first_refresh_notification->context); 4606 first_refresh_notification->context);
4561 EXPECT_EQ(0, first_refresh_notification->world_id); 4607 EXPECT_EQ(0, first_refresh_notification->world_id);
4562 4608
4563 EXPECT_EQ(child_frame, second_refresh_notification->frame); 4609 EXPECT_EQ(child_frame, second_refresh_notification->frame);
4564 EXPECT_EQ(child_frame->MainWorldScriptContext(), 4610 EXPECT_EQ(child_frame->MainWorldScriptContext(),
4565 second_refresh_notification->context); 4611 second_refresh_notification->context);
4566 EXPECT_EQ(0, second_refresh_notification->world_id); 4612 EXPECT_EQ(0, second_refresh_notification->world_id);
4567 } 4613 }
4568 4614
4569 TEST_P(ParameterizedWebFrameTest, ContextNotificationsIsolatedWorlds) { 4615 TEST_P(ParameterizedWebFrameTest, ContextNotificationsIsolatedWorlds) {
4570 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 4616 v8::Isolate* isolate = v8::Isolate::GetCurrent();
4571 v8::HandleScope handle_scope(isolate); 4617 v8::HandleScope handle_scope(isolate);
4572 4618
4573 RegisterMockedHttpURLLoad("context_notifications_test.html"); 4619 RegisterMockedHttpURLLoad("context_notifications_test.html");
4574 RegisterMockedHttpURLLoad("context_notifications_test_frame.html"); 4620 RegisterMockedHttpURLLoad("context_notifications_test_frame.html");
4575 4621
4576 ContextLifetimeTestWebFrameClient web_frame_client; 4622 Vector<std::unique_ptr<ContextLifetimeTestWebFrameClient::Notification>>
4623 create_notifications;
4624 Vector<std::unique_ptr<ContextLifetimeTestWebFrameClient::Notification>>
4625 release_notifications;
4626 ContextLifetimeTestMainFrameClient web_frame_client(create_notifications,
4627 release_notifications);
4577 FrameTestHelpers::WebViewHelper web_view_helper; 4628 FrameTestHelpers::WebViewHelper web_view_helper;
4578 web_view_helper.InitializeAndLoad( 4629 web_view_helper.InitializeAndLoad(
4579 base_url_ + "context_notifications_test.html", true, &web_frame_client); 4630 base_url_ + "context_notifications_test.html", true, &web_frame_client);
4580 4631
4581 // Add an isolated world. 4632 // Add an isolated world.
4582 web_frame_client.Reset(); 4633 web_frame_client.Reset();
4583 4634
4584 int isolated_world_id = 42; 4635 int isolated_world_id = 42;
4585 WebScriptSource script_source("hi!"); 4636 WebScriptSource script_source("hi!");
4586 int num_sources = 1; 4637 int num_sources = 1;
4587 web_view_helper.WebView()->MainFrame()->ExecuteScriptInIsolatedWorld( 4638 web_view_helper.WebView()->MainFrame()->ExecuteScriptInIsolatedWorld(
4588 isolated_world_id, &script_source, num_sources); 4639 isolated_world_id, &script_source, num_sources);
4589 4640
4590 // We should now have a new create notification. 4641 // We should now have a new create notification.
4591 ASSERT_EQ(1u, web_frame_client.create_notifications.size()); 4642 ASSERT_EQ(1u, create_notifications.size());
4592 auto& notification = web_frame_client.create_notifications[0]; 4643 auto& notification = create_notifications[0];
4593 ASSERT_EQ(isolated_world_id, notification->world_id); 4644 ASSERT_EQ(isolated_world_id, notification->world_id);
4594 ASSERT_EQ(web_view_helper.WebView()->MainFrame(), notification->frame); 4645 ASSERT_EQ(web_view_helper.WebView()->MainFrame(), notification->frame);
4595 4646
4596 // We don't have an API to enumarate isolated worlds for a frame, but we can 4647 // We don't have an API to enumarate isolated worlds for a frame, but we can
4597 // at least assert that the context we got is *not* the main world's context. 4648 // at least assert that the context we got is *not* the main world's context.
4598 ASSERT_NE(web_view_helper.WebView()->MainFrame()->MainWorldScriptContext(), 4649 ASSERT_NE(web_view_helper.WebView()->MainFrame()->MainWorldScriptContext(),
4599 v8::Local<v8::Context>::New(isolate, notification->context)); 4650 v8::Local<v8::Context>::New(isolate, notification->context));
4600 4651
4601 web_view_helper.Reset(); 4652 web_view_helper.Reset();
4602 4653
4603 // We should have gotten three release notifications (one for each of the 4654 // We should have gotten three release notifications (one for each of the
4604 // frames, plus one for the isolated context). 4655 // frames, plus one for the isolated context).
4605 ASSERT_EQ(3u, web_frame_client.release_notifications.size()); 4656 ASSERT_EQ(3u, release_notifications.size());
4606 4657
4607 // And one of them should be exactly the same as the create notification for 4658 // And one of them should be exactly the same as the create notification for
4608 // the isolated context. 4659 // the isolated context.
4609 int match_count = 0; 4660 int match_count = 0;
4610 for (size_t i = 0; i < web_frame_client.release_notifications.size(); ++i) { 4661 for (size_t i = 0; i < release_notifications.size(); ++i) {
4611 if (web_frame_client.release_notifications[i]->Equals( 4662 if (release_notifications[i]->Equals(create_notifications[0].get()))
4612 web_frame_client.create_notifications[0].get()))
4613 ++match_count; 4663 ++match_count;
4614 } 4664 }
4615 EXPECT_EQ(1, match_count); 4665 EXPECT_EQ(1, match_count);
4616 } 4666 }
4617 4667
4618 TEST_P(ParameterizedWebFrameTest, FindInPage) { 4668 TEST_P(ParameterizedWebFrameTest, FindInPage) {
4619 RegisterMockedHttpURLLoad("find.html"); 4669 RegisterMockedHttpURLLoad("find.html");
4620 FrameTestHelpers::WebViewHelper web_view_helper; 4670 FrameTestHelpers::WebViewHelper web_view_helper;
4621 web_view_helper.InitializeAndLoad(base_url_ + "find.html"); 4671 web_view_helper.InitializeAndLoad(base_url_ + "find.html");
4622 ASSERT_TRUE(web_view_helper.WebView()->MainFrameImpl()); 4672 ASSERT_TRUE(web_view_helper.WebView()->MainFrameImpl());
(...skipping 7374 matching lines...) Expand 10 before | Expand all | Expand 10 after
11997 12047
11998 // Failing the original child frame navigation and trying to render fallback 12048 // Failing the original child frame navigation and trying to render fallback
11999 // content shouldn't crash. It should return NoLoadInProgress. This is so the 12049 // content shouldn't crash. It should return NoLoadInProgress. This is so the
12000 // caller won't attempt to replace the correctly empty frame with an error 12050 // caller won't attempt to replace the correctly empty frame with an error
12001 // page. 12051 // page.
12002 EXPECT_EQ(WebLocalFrame::NoLoadInProgress, 12052 EXPECT_EQ(WebLocalFrame::NoLoadInProgress,
12003 child->MaybeRenderFallbackContent(WebURLError())); 12053 child->MaybeRenderFallbackContent(WebURLError()));
12004 } 12054 }
12005 12055
12006 } // namespace blink 12056 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698