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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc

Issue 2747723004: Revert of Correctly update the popup window position (patchset #6 id:160001 of https://codereview.c… (Closed)
Patch Set: Created 3 years, 9 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 | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | ui/aura/window.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <tuple> 10 #include <tuple>
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 void ReclaimResources(const cc::ReturnedResourceArray& resources) { 432 void ReclaimResources(const cc::ReturnedResourceArray& resources) {
433 GetDelegatedFrameHost()->ReclaimResources(resources); 433 GetDelegatedFrameHost()->ReclaimResources(resources);
434 } 434 }
435 435
436 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); } 436 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); }
437 437
438 const ui::MotionEventAura& pointer_state_for_test() { 438 const ui::MotionEventAura& pointer_state_for_test() {
439 return event_handler()->pointer_state(); 439 return event_handler()->pointer_state();
440 } 440 }
441 441
442 // In this unit test, |window_| is directly added to the root and is
443 // toplevel.
444 aura::Window* GetToplevelWindow() override { return window(); }
445
446 gfx::Size last_frame_size_; 442 gfx::Size last_frame_size_;
447 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_; 443 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_;
448 FakeWindowEventDispatcher* dispatcher_; 444 FakeWindowEventDispatcher* dispatcher_;
449 445
450 private: 446 private:
451 FakeDelegatedFrameHostClientAura* delegated_frame_host_client_; 447 FakeDelegatedFrameHostClientAura* delegated_frame_host_client_;
452 448
453 DISALLOW_COPY_AND_ASSIGN(FakeRenderWidgetHostViewAura); 449 DISALLOW_COPY_AND_ASSIGN(FakeRenderWidgetHostViewAura);
454 }; 450 };
455 451
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 519
524 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) { 520 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) {
525 base::PickleIterator iter(message); 521 base::PickleIterator iter(message);
526 const char* data; 522 const char* data;
527 int data_length; 523 int data_length;
528 if (!iter.ReadData(&data, &data_length)) 524 if (!iter.ReadData(&data, &data_length))
529 return nullptr; 525 return nullptr;
530 return reinterpret_cast<const WebInputEvent*>(data); 526 return reinterpret_cast<const WebInputEvent*>(data);
531 } 527 }
532 528
533 class MockRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
534 public:
535 MockRenderWidgetHostViewAura(RenderWidgetHost* host, bool is_guest_view_hack)
536 : RenderWidgetHostViewAura(host, is_guest_view_hack) {}
537
538 ~MockRenderWidgetHostViewAura() override {}
539
540 protected:
541 aura::Window* GetToplevelWindow() override { return window(); }
542
543 private:
544 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostViewAura);
545 };
546
547 } // namespace 529 } // namespace
548 530
549 class RenderWidgetHostViewAuraTest : public testing::Test { 531 class RenderWidgetHostViewAuraTest : public testing::Test {
550 public: 532 public:
551 RenderWidgetHostViewAuraTest() 533 RenderWidgetHostViewAuraTest()
552 : widget_host_uses_shutdown_to_destroy_(false), 534 : widget_host_uses_shutdown_to_destroy_(false),
553 is_guest_view_hack_(false) {} 535 is_guest_view_hack_(false) {}
554 536
555 static void InstallDelegatedFrameHostClient( 537 static void InstallDelegatedFrameHostClient(
556 RenderWidgetHostViewAura* render_widget_host_view, 538 RenderWidgetHostViewAura* render_widget_host_view,
557 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client) { 539 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client) {
558 render_widget_host_view->delegated_frame_host_client_ = 540 render_widget_host_view->delegated_frame_host_client_ =
559 std::move(delegated_frame_host_client); 541 std::move(delegated_frame_host_client);
560 } 542 }
561 543
562 void SetUpEnvironment() { 544 void SetUpEnvironment() {
563 ImageTransportFactory::InitializeForUnitTests( 545 ImageTransportFactory::InitializeForUnitTests(
564 std::unique_ptr<ImageTransportFactory>( 546 std::unique_ptr<ImageTransportFactory>(
565 new NoTransportImageTransportFactory)); 547 new NoTransportImageTransportFactory));
566 aura_test_helper_.reset( 548 aura_test_helper_.reset(
567 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); 549 new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
568 aura_test_helper_->SetUp( 550 aura_test_helper_->SetUp(
569 ImageTransportFactory::GetInstance()->GetContextFactory(), 551 ImageTransportFactory::GetInstance()->GetContextFactory(),
570 ImageTransportFactory::GetInstance()->GetContextFactoryPrivate()); 552 ImageTransportFactory::GetInstance()->GetContextFactoryPrivate());
571 new wm::DefaultActivationClient(aura_test_helper_->root_window()); 553 new wm::DefaultActivationClient(aura_test_helper_->root_window());
572 aura::client::SetScreenPositionClient(aura_test_helper_->root_window(),
573 &screen_position_client_);
574 554
575 browser_context_.reset(new TestBrowserContext); 555 browser_context_.reset(new TestBrowserContext);
576 process_host_ = new MockRenderProcessHost(browser_context_.get()); 556 process_host_ = new MockRenderProcessHost(browser_context_.get());
577 process_host_->Init(); 557 process_host_->Init();
578 558
579 sink_ = &process_host_->sink(); 559 sink_ = &process_host_->sink();
580 560
581 int32_t routing_id = process_host_->GetNextRoutingID(); 561 int32_t routing_id = process_host_->GetNextRoutingID();
582 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate)); 562 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate));
583 parent_host_ = new RenderWidgetHostImpl(delegates_.back().get(), 563 parent_host_ = new RenderWidgetHostImpl(delegates_.back().get(),
584 process_host_, routing_id, false); 564 process_host_, routing_id, false);
585 delegates_.back()->set_widget_host(parent_host_); 565 delegates_.back()->set_widget_host(parent_host_);
586 parent_view_ = 566 parent_view_ =
587 new MockRenderWidgetHostViewAura(parent_host_, is_guest_view_hack_); 567 new RenderWidgetHostViewAura(parent_host_, is_guest_view_hack_);
588 parent_view_->InitAsChild(nullptr); 568 parent_view_->InitAsChild(nullptr);
589 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), 569 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(),
590 aura_test_helper_->root_window(), 570 aura_test_helper_->root_window(),
591 gfx::Rect()); 571 gfx::Rect());
592 572
593 routing_id = process_host_->GetNextRoutingID(); 573 routing_id = process_host_->GetNextRoutingID();
594 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate)); 574 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate));
595 widget_host_ = new MockRenderWidgetHostImpl(delegates_.back().get(), 575 widget_host_ = new MockRenderWidgetHostImpl(delegates_.back().get(),
596 process_host_, routing_id); 576 process_host_, routing_id);
597 delegates_.back()->set_widget_host(widget_host_); 577 delegates_.back()->set_widget_host(widget_host_);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 715
736 // If true, then calls RWH::Shutdown() instead of deleting RWH. 716 // If true, then calls RWH::Shutdown() instead of deleting RWH.
737 bool widget_host_uses_shutdown_to_destroy_; 717 bool widget_host_uses_shutdown_to_destroy_;
738 718
739 bool is_guest_view_hack_; 719 bool is_guest_view_hack_;
740 720
741 TestBrowserThreadBundle thread_bundle_; 721 TestBrowserThreadBundle thread_bundle_;
742 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; 722 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_;
743 std::unique_ptr<BrowserContext> browser_context_; 723 std::unique_ptr<BrowserContext> browser_context_;
744 std::vector<std::unique_ptr<MockRenderWidgetHostDelegate>> delegates_; 724 std::vector<std::unique_ptr<MockRenderWidgetHostDelegate>> delegates_;
745 wm::DefaultScreenPositionClient screen_position_client_;
746 MockRenderProcessHost* process_host_; 725 MockRenderProcessHost* process_host_;
747 726
748 // Tests should set these to nullptr if they've already triggered their 727 // Tests should set these to nullptr if they've already triggered their
749 // destruction. 728 // destruction.
750 RenderWidgetHostImpl* parent_host_; 729 RenderWidgetHostImpl* parent_host_;
751 RenderWidgetHostViewAura* parent_view_; 730 RenderWidgetHostViewAura* parent_view_;
752 731
753 // Tests should set these to nullptr if they've already triggered their 732 // Tests should set these to nullptr if they've already triggered their
754 // destruction. 733 // destruction.
755 MockRenderWidgetHostImpl* widget_host_; 734 MockRenderWidgetHostImpl* widget_host_;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 EXPECT_TRUE(window->HasFocus()); 1004 EXPECT_TRUE(window->HasFocus());
1026 1005
1027 // Check that we'll also say it's okay to activate the window when there's an 1006 // Check that we'll also say it's okay to activate the window when there's an
1028 // ActivationClient defined. 1007 // ActivationClient defined.
1029 EXPECT_TRUE(view_->ShouldActivate()); 1008 EXPECT_TRUE(view_->ShouldActivate());
1030 } 1009 }
1031 1010
1032 // Checks that a popup is positioned correctly relative to its parent using 1011 // Checks that a popup is positioned correctly relative to its parent using
1033 // screen coordinates. 1012 // screen coordinates.
1034 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) { 1013 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) {
1014 wm::DefaultScreenPositionClient screen_position_client;
1035 1015
1036 aura::Window* window = parent_view_->GetNativeView(); 1016 aura::Window* window = parent_view_->GetNativeView();
1037 aura::Window* root = window->GetRootWindow(); 1017 aura::Window* root = window->GetRootWindow();
1018 aura::client::SetScreenPositionClient(root, &screen_position_client);
1038 1019
1039 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600)); 1020 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600));
1040 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds(); 1021 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds();
1041 int horiz = bounds_in_screen.width() / 4; 1022 int horiz = bounds_in_screen.width() / 4;
1042 int vert = bounds_in_screen.height() / 4; 1023 int vert = bounds_in_screen.height() / 4;
1043 bounds_in_screen.Inset(horiz, vert); 1024 bounds_in_screen.Inset(horiz, vert);
1044 1025
1045 // Verify that when the popup is initialized for the first time, it correctly 1026 // Verify that when the popup is initialized for the first time, it correctly
1046 // treats the input bounds as screen coordinates. 1027 // treats the input bounds as screen coordinates.
1047 view_->InitAsPopup(parent_view_, bounds_in_screen); 1028 view_->InitAsPopup(parent_view_, bounds_in_screen);
(...skipping 3122 matching lines...) Expand 10 before | Expand all | Expand 10 after
4170 : view_(nullptr) {} 4151 : view_(nullptr) {}
4171 ~RenderWidgetHostViewAuraWithViewHarnessTest() override {} 4152 ~RenderWidgetHostViewAuraWithViewHarnessTest() override {}
4172 4153
4173 protected: 4154 protected:
4174 void SetUp() override { 4155 void SetUp() override {
4175 RenderViewHostImplTestHarness::SetUp(); 4156 RenderViewHostImplTestHarness::SetUp();
4176 // Delete the current RenderWidgetHostView instance before setting 4157 // Delete the current RenderWidgetHostView instance before setting
4177 // the RWHVA as the view. 4158 // the RWHVA as the view.
4178 delete contents()->GetRenderViewHost()->GetWidget()->GetView(); 4159 delete contents()->GetRenderViewHost()->GetWidget()->GetView();
4179 // This instance is destroyed in the TearDown method below. 4160 // This instance is destroyed in the TearDown method below.
4180 view_ = new MockRenderWidgetHostViewAura( 4161 view_ = new RenderWidgetHostViewAura(
4181 contents()->GetRenderViewHost()->GetWidget(), false); 4162 contents()->GetRenderViewHost()->GetWidget(), false);
4182 } 4163 }
4183 4164
4184 void TearDown() override { 4165 void TearDown() override {
4185 view_->Destroy(); 4166 view_->Destroy();
4186 RenderViewHostImplTestHarness::TearDown(); 4167 RenderViewHostImplTestHarness::TearDown();
4187 } 4168 }
4188 4169
4189 RenderWidgetHostViewAura* view() { 4170 RenderWidgetHostViewAura* view() {
4190 return view_; 4171 return view_;
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
4717 // There is no composition in the beginning. 4698 // There is no composition in the beginning.
4718 EXPECT_FALSE(has_composition_text()); 4699 EXPECT_FALSE(has_composition_text());
4719 SetHasCompositionTextToTrue(); 4700 SetHasCompositionTextToTrue();
4720 view->ImeCancelComposition(); 4701 view->ImeCancelComposition();
4721 // The composition must have been canceled. 4702 // The composition must have been canceled.
4722 EXPECT_FALSE(has_composition_text()); 4703 EXPECT_FALSE(has_composition_text());
4723 } 4704 }
4724 } 4705 }
4725 4706
4726 } // namespace content 4707 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | ui/aura/window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698