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

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

Issue 2732383002: 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 void ReturnResources(const cc::ReturnedResourceArray& resources) { 423 void ReturnResources(const cc::ReturnedResourceArray& resources) {
424 GetDelegatedFrameHost()->ReturnResources(resources); 424 GetDelegatedFrameHost()->ReturnResources(resources);
425 } 425 }
426 426
427 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); } 427 void ResetCompositor() { GetDelegatedFrameHost()->ResetCompositor(); }
428 428
429 const ui::MotionEventAura& pointer_state_for_test() { 429 const ui::MotionEventAura& pointer_state_for_test() {
430 return event_handler()->pointer_state(); 430 return event_handler()->pointer_state();
431 } 431 }
432 432
433 // In this unit test, |window_| is directly added to the root and is
434 // toplevel.
435 aura::Window* GetToplevelWindow() override { return window(); }
436
437 gfx::Size last_frame_size_; 433 gfx::Size last_frame_size_;
438 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_; 434 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_;
439 FakeWindowEventDispatcher* dispatcher_; 435 FakeWindowEventDispatcher* dispatcher_;
440 436
441 private: 437 private:
442 FakeDelegatedFrameHostClientAura* delegated_frame_host_client_; 438 FakeDelegatedFrameHostClientAura* delegated_frame_host_client_;
443 439
444 DISALLOW_COPY_AND_ASSIGN(FakeRenderWidgetHostViewAura); 440 DISALLOW_COPY_AND_ASSIGN(FakeRenderWidgetHostViewAura);
445 }; 441 };
446 442
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 510
515 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) { 511 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) {
516 base::PickleIterator iter(message); 512 base::PickleIterator iter(message);
517 const char* data; 513 const char* data;
518 int data_length; 514 int data_length;
519 if (!iter.ReadData(&data, &data_length)) 515 if (!iter.ReadData(&data, &data_length))
520 return nullptr; 516 return nullptr;
521 return reinterpret_cast<const WebInputEvent*>(data); 517 return reinterpret_cast<const WebInputEvent*>(data);
522 } 518 }
523 519
524 class MockRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
525 public:
526 MockRenderWidgetHostViewAura(RenderWidgetHost* host, bool is_guest_view_hack)
527 : RenderWidgetHostViewAura(host, is_guest_view_hack) {}
528
529 ~MockRenderWidgetHostViewAura() override {}
530
531 protected:
532 aura::Window* GetToplevelWindow() override { return window(); }
533
534 private:
535 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostViewAura);
536 };
537
538 } // namespace 520 } // namespace
539 521
540 class RenderWidgetHostViewAuraTest : public testing::Test { 522 class RenderWidgetHostViewAuraTest : public testing::Test {
541 public: 523 public:
542 RenderWidgetHostViewAuraTest() 524 RenderWidgetHostViewAuraTest()
543 : widget_host_uses_shutdown_to_destroy_(false), 525 : widget_host_uses_shutdown_to_destroy_(false),
544 is_guest_view_hack_(false) {} 526 is_guest_view_hack_(false) {}
545 527
546 static void InstallDelegatedFrameHostClient( 528 static void InstallDelegatedFrameHostClient(
547 RenderWidgetHostViewAura* render_widget_host_view, 529 RenderWidgetHostViewAura* render_widget_host_view,
548 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client) { 530 std::unique_ptr<DelegatedFrameHostClient> delegated_frame_host_client) {
549 render_widget_host_view->delegated_frame_host_client_ = 531 render_widget_host_view->delegated_frame_host_client_ =
550 std::move(delegated_frame_host_client); 532 std::move(delegated_frame_host_client);
551 } 533 }
552 534
553 void SetUpEnvironment() { 535 void SetUpEnvironment() {
554 ImageTransportFactory::InitializeForUnitTests( 536 ImageTransportFactory::InitializeForUnitTests(
555 std::unique_ptr<ImageTransportFactory>( 537 std::unique_ptr<ImageTransportFactory>(
556 new NoTransportImageTransportFactory)); 538 new NoTransportImageTransportFactory));
557 aura_test_helper_.reset( 539 aura_test_helper_.reset(
558 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); 540 new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
559 aura_test_helper_->SetUp( 541 aura_test_helper_->SetUp(
560 ImageTransportFactory::GetInstance()->GetContextFactory(), 542 ImageTransportFactory::GetInstance()->GetContextFactory(),
561 ImageTransportFactory::GetInstance()->GetContextFactoryPrivate()); 543 ImageTransportFactory::GetInstance()->GetContextFactoryPrivate());
562 new wm::DefaultActivationClient(aura_test_helper_->root_window()); 544 new wm::DefaultActivationClient(aura_test_helper_->root_window());
563 aura::client::SetScreenPositionClient(aura_test_helper_->root_window(),
564 &screen_position_client_);
565 545
566 browser_context_.reset(new TestBrowserContext); 546 browser_context_.reset(new TestBrowserContext);
567 process_host_ = new MockRenderProcessHost(browser_context_.get()); 547 process_host_ = new MockRenderProcessHost(browser_context_.get());
568 process_host_->Init(); 548 process_host_->Init();
569 549
570 sink_ = &process_host_->sink(); 550 sink_ = &process_host_->sink();
571 551
572 int32_t routing_id = process_host_->GetNextRoutingID(); 552 int32_t routing_id = process_host_->GetNextRoutingID();
573 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate)); 553 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate));
574 parent_host_ = new RenderWidgetHostImpl(delegates_.back().get(), 554 parent_host_ = new RenderWidgetHostImpl(delegates_.back().get(),
575 process_host_, routing_id, false); 555 process_host_, routing_id, false);
576 delegates_.back()->set_widget_host(parent_host_); 556 delegates_.back()->set_widget_host(parent_host_);
577 parent_view_ = 557 parent_view_ =
578 new MockRenderWidgetHostViewAura(parent_host_, is_guest_view_hack_); 558 new RenderWidgetHostViewAura(parent_host_, is_guest_view_hack_);
579 parent_view_->InitAsChild(nullptr); 559 parent_view_->InitAsChild(nullptr);
580 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), 560 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(),
581 aura_test_helper_->root_window(), 561 aura_test_helper_->root_window(),
582 gfx::Rect()); 562 gfx::Rect());
583 563
584 routing_id = process_host_->GetNextRoutingID(); 564 routing_id = process_host_->GetNextRoutingID();
585 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate)); 565 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate));
586 widget_host_ = new MockRenderWidgetHostImpl(delegates_.back().get(), 566 widget_host_ = new MockRenderWidgetHostImpl(delegates_.back().get(),
587 process_host_, routing_id); 567 process_host_, routing_id);
588 delegates_.back()->set_widget_host(widget_host_); 568 delegates_.back()->set_widget_host(widget_host_);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 706
727 // If true, then calls RWH::Shutdown() instead of deleting RWH. 707 // If true, then calls RWH::Shutdown() instead of deleting RWH.
728 bool widget_host_uses_shutdown_to_destroy_; 708 bool widget_host_uses_shutdown_to_destroy_;
729 709
730 bool is_guest_view_hack_; 710 bool is_guest_view_hack_;
731 711
732 TestBrowserThreadBundle thread_bundle_; 712 TestBrowserThreadBundle thread_bundle_;
733 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; 713 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_;
734 std::unique_ptr<BrowserContext> browser_context_; 714 std::unique_ptr<BrowserContext> browser_context_;
735 std::vector<std::unique_ptr<MockRenderWidgetHostDelegate>> delegates_; 715 std::vector<std::unique_ptr<MockRenderWidgetHostDelegate>> delegates_;
736 wm::DefaultScreenPositionClient screen_position_client_;
737 MockRenderProcessHost* process_host_; 716 MockRenderProcessHost* process_host_;
738 717
739 // Tests should set these to nullptr if they've already triggered their 718 // Tests should set these to nullptr if they've already triggered their
740 // destruction. 719 // destruction.
741 RenderWidgetHostImpl* parent_host_; 720 RenderWidgetHostImpl* parent_host_;
742 RenderWidgetHostViewAura* parent_view_; 721 RenderWidgetHostViewAura* parent_view_;
743 722
744 // Tests should set these to nullptr if they've already triggered their 723 // Tests should set these to nullptr if they've already triggered their
745 // destruction. 724 // destruction.
746 MockRenderWidgetHostImpl* widget_host_; 725 MockRenderWidgetHostImpl* widget_host_;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 EXPECT_TRUE(window->HasFocus()); 995 EXPECT_TRUE(window->HasFocus());
1017 996
1018 // Check that we'll also say it's okay to activate the window when there's an 997 // Check that we'll also say it's okay to activate the window when there's an
1019 // ActivationClient defined. 998 // ActivationClient defined.
1020 EXPECT_TRUE(view_->ShouldActivate()); 999 EXPECT_TRUE(view_->ShouldActivate());
1021 } 1000 }
1022 1001
1023 // Checks that a popup is positioned correctly relative to its parent using 1002 // Checks that a popup is positioned correctly relative to its parent using
1024 // screen coordinates. 1003 // screen coordinates.
1025 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) { 1004 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) {
1005 wm::DefaultScreenPositionClient screen_position_client;
1026 1006
1027 aura::Window* window = parent_view_->GetNativeView(); 1007 aura::Window* window = parent_view_->GetNativeView();
1028 aura::Window* root = window->GetRootWindow(); 1008 aura::Window* root = window->GetRootWindow();
1009 aura::client::SetScreenPositionClient(root, &screen_position_client);
1029 1010
1030 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600)); 1011 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600));
1031 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds(); 1012 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds();
1032 int horiz = bounds_in_screen.width() / 4; 1013 int horiz = bounds_in_screen.width() / 4;
1033 int vert = bounds_in_screen.height() / 4; 1014 int vert = bounds_in_screen.height() / 4;
1034 bounds_in_screen.Inset(horiz, vert); 1015 bounds_in_screen.Inset(horiz, vert);
1035 1016
1036 // Verify that when the popup is initialized for the first time, it correctly 1017 // Verify that when the popup is initialized for the first time, it correctly
1037 // treats the input bounds as screen coordinates. 1018 // treats the input bounds as screen coordinates.
1038 view_->InitAsPopup(parent_view_, bounds_in_screen); 1019 view_->InitAsPopup(parent_view_, bounds_in_screen);
(...skipping 3173 matching lines...) Expand 10 before | Expand all | Expand 10 after
4212 : view_(nullptr) {} 4193 : view_(nullptr) {}
4213 ~RenderWidgetHostViewAuraWithViewHarnessTest() override {} 4194 ~RenderWidgetHostViewAuraWithViewHarnessTest() override {}
4214 4195
4215 protected: 4196 protected:
4216 void SetUp() override { 4197 void SetUp() override {
4217 RenderViewHostImplTestHarness::SetUp(); 4198 RenderViewHostImplTestHarness::SetUp();
4218 // Delete the current RenderWidgetHostView instance before setting 4199 // Delete the current RenderWidgetHostView instance before setting
4219 // the RWHVA as the view. 4200 // the RWHVA as the view.
4220 delete contents()->GetRenderViewHost()->GetWidget()->GetView(); 4201 delete contents()->GetRenderViewHost()->GetWidget()->GetView();
4221 // This instance is destroyed in the TearDown method below. 4202 // This instance is destroyed in the TearDown method below.
4222 view_ = new MockRenderWidgetHostViewAura( 4203 view_ = new RenderWidgetHostViewAura(
4223 contents()->GetRenderViewHost()->GetWidget(), false); 4204 contents()->GetRenderViewHost()->GetWidget(), false);
4224 } 4205 }
4225 4206
4226 void TearDown() override { 4207 void TearDown() override {
4227 view_->Destroy(); 4208 view_->Destroy();
4228 RenderViewHostImplTestHarness::TearDown(); 4209 RenderViewHostImplTestHarness::TearDown();
4229 } 4210 }
4230 4211
4231 RenderWidgetHostViewAura* view() { 4212 RenderWidgetHostViewAura* view() {
4232 return view_; 4213 return view_;
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
4759 // There is no composition in the beginning. 4740 // There is no composition in the beginning.
4760 EXPECT_FALSE(has_composition_text()); 4741 EXPECT_FALSE(has_composition_text());
4761 SetHasCompositionTextToTrue(); 4742 SetHasCompositionTextToTrue();
4762 view->ImeCancelComposition(); 4743 view->ImeCancelComposition();
4763 // The composition must have been canceled. 4744 // The composition must have been canceled.
4764 EXPECT_FALSE(has_composition_text()); 4745 EXPECT_FALSE(has_composition_text());
4765 } 4746 }
4766 } 4747 }
4767 4748
4768 } // namespace content 4749 } // 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