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

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