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

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

Issue 2583873002: Correctly update the popup window position (Closed)
Patch Set: . Created 4 years 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
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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 class FakeResizeLock : public ResizeLock { 393 class FakeResizeLock : public ResizeLock {
394 public: 394 public:
395 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock) 395 FakeResizeLock(const gfx::Size new_size, bool defer_compositor_lock)
396 : ResizeLock(new_size, defer_compositor_lock) {} 396 : ResizeLock(new_size, defer_compositor_lock) {}
397 }; 397 };
398 398
399 const ui::MotionEventAura& pointer_state_for_test() { 399 const ui::MotionEventAura& pointer_state_for_test() {
400 return event_handler()->pointer_state(); 400 return event_handler()->pointer_state();
401 } 401 }
402 402
403 // In this unit test, |window_| is directly added to the root and is
404 // toplevel.
405 aura::Window* GetToplevelWindow() override { return window(); }
406
403 bool can_create_resize_lock_; 407 bool can_create_resize_lock_;
404 gfx::Size last_frame_size_; 408 gfx::Size last_frame_size_;
405 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_; 409 std::unique_ptr<cc::CopyOutputRequest> last_copy_request_;
406 FakeWindowEventDispatcher* dispatcher_; 410 FakeWindowEventDispatcher* dispatcher_;
407 }; 411 };
408 412
409 // A layout manager that always resizes a child to the root window size. 413 // A layout manager that always resizes a child to the root window size.
410 class FullscreenLayoutManager : public aura::LayoutManager { 414 class FullscreenLayoutManager : public aura::LayoutManager {
411 public: 415 public:
412 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {} 416 explicit FullscreenLayoutManager(aura::Window* owner) : owner_(owner) {}
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 480
477 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) { 481 const WebInputEvent* GetInputEventFromMessage(const IPC::Message& message) {
478 base::PickleIterator iter(message); 482 base::PickleIterator iter(message);
479 const char* data; 483 const char* data;
480 int data_length; 484 int data_length;
481 if (!iter.ReadData(&data, &data_length)) 485 if (!iter.ReadData(&data, &data_length))
482 return nullptr; 486 return nullptr;
483 return reinterpret_cast<const WebInputEvent*>(data); 487 return reinterpret_cast<const WebInputEvent*>(data);
484 } 488 }
485 489
490 class MockRenderWidgetHostViewAura : public RenderWidgetHostViewAura {
491 public:
492 MockRenderWidgetHostViewAura(RenderWidgetHost* host, bool is_guest_view_hack)
493 : RenderWidgetHostViewAura(host, is_guest_view_hack) {}
494
495 ~MockRenderWidgetHostViewAura() override {}
496
497 protected:
498 aura::Window* GetToplevelWindow() override { return window(); }
499
500 private:
501 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHostViewAura);
502 };
503
486 } // namespace 504 } // namespace
487 505
488 class RenderWidgetHostViewAuraTest : public testing::Test { 506 class RenderWidgetHostViewAuraTest : public testing::Test {
489 public: 507 public:
490 RenderWidgetHostViewAuraTest() 508 RenderWidgetHostViewAuraTest()
491 : widget_host_uses_shutdown_to_destroy_(false), 509 : widget_host_uses_shutdown_to_destroy_(false),
492 is_guest_view_hack_(false) {} 510 is_guest_view_hack_(false) {}
493 511
494 void SetUpEnvironment() { 512 void SetUpEnvironment() {
495 ImageTransportFactory::InitializeForUnitTests( 513 ImageTransportFactory::InitializeForUnitTests(
496 std::unique_ptr<ImageTransportFactory>( 514 std::unique_ptr<ImageTransportFactory>(
497 new NoTransportImageTransportFactory)); 515 new NoTransportImageTransportFactory));
498 aura_test_helper_.reset( 516 aura_test_helper_.reset(
499 new aura::test::AuraTestHelper(base::MessageLoopForUI::current())); 517 new aura::test::AuraTestHelper(base::MessageLoopForUI::current()));
500 aura_test_helper_->SetUp( 518 aura_test_helper_->SetUp(
501 ImageTransportFactory::GetInstance()->GetContextFactory()); 519 ImageTransportFactory::GetInstance()->GetContextFactory());
502 new wm::DefaultActivationClient(aura_test_helper_->root_window()); 520 new wm::DefaultActivationClient(aura_test_helper_->root_window());
521 aura::client::SetScreenPositionClient(aura_test_helper_->root_window(),
522 &screen_position_client_);
503 523
504 browser_context_.reset(new TestBrowserContext); 524 browser_context_.reset(new TestBrowserContext);
505 process_host_ = new MockRenderProcessHost(browser_context_.get()); 525 process_host_ = new MockRenderProcessHost(browser_context_.get());
506 process_host_->Init(); 526 process_host_->Init();
507 527
508 sink_ = &process_host_->sink(); 528 sink_ = &process_host_->sink();
509 529
510 int32_t routing_id = process_host_->GetNextRoutingID(); 530 int32_t routing_id = process_host_->GetNextRoutingID();
511 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate)); 531 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate));
512 parent_host_ = new RenderWidgetHostImpl(delegates_.back().get(), 532 parent_host_ = new RenderWidgetHostImpl(delegates_.back().get(),
513 process_host_, routing_id, false); 533 process_host_, routing_id, false);
514 delegates_.back()->set_widget_host(parent_host_); 534 delegates_.back()->set_widget_host(parent_host_);
515 parent_view_ = new RenderWidgetHostViewAura(parent_host_, 535 parent_view_ =
516 is_guest_view_hack_); 536 new MockRenderWidgetHostViewAura(parent_host_, is_guest_view_hack_);
517 parent_view_->InitAsChild(nullptr); 537 parent_view_->InitAsChild(nullptr);
518 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(), 538 aura::client::ParentWindowWithContext(parent_view_->GetNativeView(),
519 aura_test_helper_->root_window(), 539 aura_test_helper_->root_window(),
520 gfx::Rect()); 540 gfx::Rect());
521 541
522 routing_id = process_host_->GetNextRoutingID(); 542 routing_id = process_host_->GetNextRoutingID();
523 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate)); 543 delegates_.push_back(base::WrapUnique(new MockRenderWidgetHostDelegate));
524 widget_host_ = new MockRenderWidgetHostImpl(delegates_.back().get(), 544 widget_host_ = new MockRenderWidgetHostImpl(delegates_.back().get(),
525 process_host_, routing_id); 545 process_host_, routing_id);
526 delegates_.back()->set_widget_host(widget_host_); 546 delegates_.back()->set_widget_host(widget_host_);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 684
665 // If true, then calls RWH::Shutdown() instead of deleting RWH. 685 // If true, then calls RWH::Shutdown() instead of deleting RWH.
666 bool widget_host_uses_shutdown_to_destroy_; 686 bool widget_host_uses_shutdown_to_destroy_;
667 687
668 bool is_guest_view_hack_; 688 bool is_guest_view_hack_;
669 689
670 TestBrowserThreadBundle thread_bundle_; 690 TestBrowserThreadBundle thread_bundle_;
671 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_; 691 std::unique_ptr<aura::test::AuraTestHelper> aura_test_helper_;
672 std::unique_ptr<BrowserContext> browser_context_; 692 std::unique_ptr<BrowserContext> browser_context_;
673 std::vector<std::unique_ptr<MockRenderWidgetHostDelegate>> delegates_; 693 std::vector<std::unique_ptr<MockRenderWidgetHostDelegate>> delegates_;
694 wm::DefaultScreenPositionClient screen_position_client_;
674 MockRenderProcessHost* process_host_; 695 MockRenderProcessHost* process_host_;
675 696
676 // Tests should set these to nullptr if they've already triggered their 697 // Tests should set these to nullptr if they've already triggered their
677 // destruction. 698 // destruction.
678 RenderWidgetHostImpl* parent_host_; 699 RenderWidgetHostImpl* parent_host_;
679 RenderWidgetHostViewAura* parent_view_; 700 RenderWidgetHostViewAura* parent_view_;
680 701
681 // Tests should set these to nullptr if they've already triggered their 702 // Tests should set these to nullptr if they've already triggered their
682 // destruction. 703 // destruction.
683 MockRenderWidgetHostImpl* widget_host_; 704 MockRenderWidgetHostImpl* widget_host_;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 EXPECT_TRUE(window->HasFocus()); 967 EXPECT_TRUE(window->HasFocus());
947 968
948 // Check that we'll also say it's okay to activate the window when there's an 969 // Check that we'll also say it's okay to activate the window when there's an
949 // ActivationClient defined. 970 // ActivationClient defined.
950 EXPECT_TRUE(view_->ShouldActivate()); 971 EXPECT_TRUE(view_->ShouldActivate());
951 } 972 }
952 973
953 // Checks that a popup is positioned correctly relative to its parent using 974 // Checks that a popup is positioned correctly relative to its parent using
954 // screen coordinates. 975 // screen coordinates.
955 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) { 976 TEST_F(RenderWidgetHostViewAuraTest, PositionChildPopup) {
956 wm::DefaultScreenPositionClient screen_position_client;
957 977
958 aura::Window* window = parent_view_->GetNativeView(); 978 aura::Window* window = parent_view_->GetNativeView();
959 aura::Window* root = window->GetRootWindow(); 979 aura::Window* root = window->GetRootWindow();
960 aura::client::SetScreenPositionClient(root, &screen_position_client);
961 980
962 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600)); 981 parent_view_->SetBounds(gfx::Rect(10, 10, 800, 600));
963 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds(); 982 gfx::Rect bounds_in_screen = parent_view_->GetViewBounds();
964 int horiz = bounds_in_screen.width() / 4; 983 int horiz = bounds_in_screen.width() / 4;
965 int vert = bounds_in_screen.height() / 4; 984 int vert = bounds_in_screen.height() / 4;
966 bounds_in_screen.Inset(horiz, vert); 985 bounds_in_screen.Inset(horiz, vert);
967 986
968 // Verify that when the popup is initialized for the first time, it correctly 987 // Verify that when the popup is initialized for the first time, it correctly
969 // treats the input bounds as screen coordinates. 988 // treats the input bounds as screen coordinates.
970 view_->InitAsPopup(parent_view_, bounds_in_screen); 989 view_->InitAsPopup(parent_view_, bounds_in_screen);
(...skipping 3170 matching lines...) Expand 10 before | Expand all | Expand 10 after
4141 : view_(nullptr) {} 4160 : view_(nullptr) {}
4142 ~RenderWidgetHostViewAuraWithViewHarnessTest() override {} 4161 ~RenderWidgetHostViewAuraWithViewHarnessTest() override {}
4143 4162
4144 protected: 4163 protected:
4145 void SetUp() override { 4164 void SetUp() override {
4146 RenderViewHostImplTestHarness::SetUp(); 4165 RenderViewHostImplTestHarness::SetUp();
4147 // Delete the current RenderWidgetHostView instance before setting 4166 // Delete the current RenderWidgetHostView instance before setting
4148 // the RWHVA as the view. 4167 // the RWHVA as the view.
4149 delete contents()->GetRenderViewHost()->GetWidget()->GetView(); 4168 delete contents()->GetRenderViewHost()->GetWidget()->GetView();
4150 // This instance is destroyed in the TearDown method below. 4169 // This instance is destroyed in the TearDown method below.
4151 view_ = new RenderWidgetHostViewAura( 4170 view_ = new MockRenderWidgetHostViewAura(
4152 contents()->GetRenderViewHost()->GetWidget(), 4171 contents()->GetRenderViewHost()->GetWidget(), false);
4153 false);
4154 } 4172 }
4155 4173
4156 void TearDown() override { 4174 void TearDown() override {
4157 view_->Destroy(); 4175 view_->Destroy();
4158 RenderViewHostImplTestHarness::TearDown(); 4176 RenderViewHostImplTestHarness::TearDown();
4159 } 4177 }
4160 4178
4161 RenderWidgetHostViewAura* view() { 4179 RenderWidgetHostViewAura* view() {
4162 return view_; 4180 return view_;
4163 } 4181 }
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
4674 4692
4675 // Retrieve the selected text from clipboard and verify it is as expected. 4693 // Retrieve the selected text from clipboard and verify it is as expected.
4676 base::string16 result_text; 4694 base::string16 result_text;
4677 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text); 4695 clipboard->ReadText(ui::CLIPBOARD_TYPE_SELECTION, &result_text);
4678 EXPECT_EQ(expected_text, result_text); 4696 EXPECT_EQ(expected_text, result_text);
4679 } 4697 }
4680 } 4698 }
4681 #endif 4699 #endif
4682 4700
4683 } // namespace content 4701 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698