15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/autofill/popup_controller_common.h" 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/ui/autofill/test_popup_controller_common.h" 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/test/base/chrome_render_view_host_test_harness.h" 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/display.h" 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/rect.h" 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace autofill { 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class PopupControllerBaseTest : public ChromeRenderViewHostTestHarness { 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PopupControllerBaseTest() {} 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~PopupControllerBaseTest() {} 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(PopupControllerBaseTest); 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(PopupControllerBaseTest, GetPopupBoundsTest) { 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int desired_width = 40; 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int desired_height = 16; 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set up the visible screen space. 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Display display(0, 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect(0, 0, 2 * desired_width, 2 * desired_height)); 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Store the possible element bounds and the popup bounds they should result 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // in. 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<gfx::RectF> element_bounds; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<gfx::Rect> expected_popup_bounds; 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The popup grows down and to the right. 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) element_bounds.push_back(gfx::RectF(0, 0, 0, 0)); 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_popup_bounds.push_back( 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect(0, 0, desired_width, desired_height)); 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The popup grows down and to the left. 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) element_bounds.push_back(gfx::RectF(2 * desired_width, 0, 0, 0)); 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_popup_bounds.push_back( 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect(desired_width, 0, desired_width, desired_height)); 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The popup grows up and to the right. 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) element_bounds.push_back(gfx::RectF(0, 2 * desired_height, 0, 0)); 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_popup_bounds.push_back( 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect(0, desired_height, desired_width, desired_height)); 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The popup grows up and to the left. 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) element_bounds.push_back( 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::RectF(2 * desired_width, 2 * desired_height, 0, 0)); 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_popup_bounds.push_back( 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect(desired_width, desired_height, desired_width, desired_height)); 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The popup would be partial off the top and left side of the screen. 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) element_bounds.push_back( 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::RectF(-desired_width / 2, -desired_height / 2, 0, 0)); 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_popup_bounds.push_back( 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect(0, 0, desired_width, desired_height)); 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The popup would be partially off the bottom and the right side of 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // the screen. 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) element_bounds.push_back( 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::RectF(desired_width * 1.5, desired_height * 1.5, 0, 0)); 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_popup_bounds.push_back( 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect((desired_width + 1) / 2, (desired_height + 1) / 2, 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) desired_width, desired_height)); 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (size_t i = 0; i < element_bounds.size(); ++i) { 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_ptr<TestPopupControllerCommon> popup_controller( 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) new TestPopupControllerCommon(element_bounds[i])); 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) popup_controller->set_display(display); 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gfx::Rect actual_popup_bounds = 77116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch popup_controller->GetPopupBounds(desired_width, desired_height); 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(expected_popup_bounds[i].ToString(), 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) actual_popup_bounds.ToString()) << 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) "Popup bounds failed to match for test " << i; 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} // namespace autofill 86