Home | History | Annotate | Download | only in desktop_aura
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ui/views/test/views_test_base.h"
      6 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
      7 #include "ui/views/widget/widget.h"
      8 #include "ui/views/window/dialog_delegate.h"
      9 
     10 namespace views {
     11 
     12 typedef ViewsTestBase DesktopScreenPositionClientTest;
     13 
     14 // Verifies setting the bounds of a dialog parented to a Widget with a
     15 // DesktopNativeWidgetAura is positioned correctly.
     16 TEST_F(DesktopScreenPositionClientTest, PositionDialog) {
     17   Widget parent_widget;
     18   Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
     19   params.bounds = gfx::Rect(10, 11, 200, 200);
     20   params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
     21   params.native_widget = new DesktopNativeWidgetAura(&parent_widget);
     22   parent_widget.Init(params);
     23 
     24   // Owned by |dialog|.
     25   DialogDelegateView* dialog_delegate_view = new DialogDelegateView;
     26   // Owned by |parent_widget|.
     27   Widget* dialog = DialogDelegate::CreateDialogWidget(
     28       dialog_delegate_view, NULL, parent_widget.GetNativeView());
     29   dialog->SetBounds(gfx::Rect(11, 12, 200, 200));
     30   EXPECT_EQ("11,12", dialog->GetWindowBoundsInScreen().origin().ToString());
     31 }
     32 
     33 // Verifies that setting the bounds of a control parented to something other
     34 // than the root window is positioned correctly.
     35 TEST_F(DesktopScreenPositionClientTest, PositionControlWithNonRootParent) {
     36   Widget widget1;
     37   Widget widget2;
     38   Widget widget3;
     39   gfx::Point origin = gfx::Point(16, 16);
     40 
     41   // Use a custom frame type.  By default we will choose a native frame when
     42   // aero glass is enabled, and this complicates the logic surrounding origin
     43   // computation, making it difficult to compute the expected origin location.
     44   widget1.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM);
     45   widget2.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM);
     46   widget3.set_frame_type(Widget::FRAME_TYPE_FORCE_CUSTOM);
     47 
     48   // Create 3 windows.  A root window, an arbitrary window parented to the root
     49   // but NOT positioned at (0,0) relative to the root, and then a third window
     50   // parented to the second, also not positioned at (0,0).
     51   Widget::InitParams params1 =
     52       CreateParams(Widget::InitParams::TYPE_WINDOW);
     53   params1.bounds = gfx::Rect(origin, gfx::Size(700, 600));
     54   params1.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
     55   params1.native_widget = new DesktopNativeWidgetAura(&widget1);
     56   widget1.Init(params1);
     57 
     58   Widget::InitParams params2 =
     59     CreateParams(Widget::InitParams::TYPE_WINDOW);
     60   params2.bounds = gfx::Rect(origin, gfx::Size(600, 500));
     61   params2.parent = widget1.GetNativeView();
     62   params2.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
     63   params2.child = true;
     64   widget2.Init(params2);
     65 
     66   Widget::InitParams params3 =
     67       CreateParams(Widget::InitParams::TYPE_CONTROL);
     68   params3.parent = widget2.GetNativeView();
     69   params3.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
     70   params3.child = true;
     71   params3.bounds = gfx::Rect(origin, gfx::Size(500, 400));
     72   widget3.Init(params3);
     73 
     74   // The origin of the 3rd window should be the sum of all parent origins.
     75   gfx::Point expected_origin(origin.x() * 3, origin.y() * 3);
     76   gfx::Rect expected_bounds(expected_origin, gfx::Size(500, 400));
     77   gfx::Rect actual_bounds(widget3.GetWindowBoundsInScreen());
     78   EXPECT_EQ(expected_bounds.ToString(), actual_bounds.ToString());
     79 }
     80 
     81 }  // namespace views
     82