diff options
author | scottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-20 22:33:51 +0000 |
---|---|---|
committer | scottbyer@chromium.org <scottbyer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-20 22:33:51 +0000 |
commit | 101747a964502501506c2903983b14b2e741d230 (patch) | |
tree | 0e952fa7ca99fb91dbfa58982afe49076d5d0464 /chrome | |
parent | c6a7b86c54d8b920943c97d990268ba1aee7b04b (diff) | |
download | chromium_src-101747a964502501506c2903983b14b2e741d230.zip chromium_src-101747a964502501506c2903983b14b2e741d230.tar.gz chromium_src-101747a964502501506c2903983b14b2e741d230.tar.bz2 |
Add in a browser test for dialog resizing, which was catching an issue with the way we were using GTK in toolkit views. Possibly related to 27365 or 38785.
http://code.google.com/p/chromium-os/issues/detail?id=4126
BUG=chromium-os:4126
TEST=HtmlDialogBrowserTest.SizeWindow
Review URL: http://codereview.chromium.org/2768006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56919 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/views/html_dialog_view_browsertest.cc | 204 | ||||
-rw-r--r-- | chrome/browser/views/tab_contents/tab_contents_view_gtk.cc | 11 | ||||
-rw-r--r-- | chrome/browser/views/tabs/dragged_tab_view.cc | 3 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 |
4 files changed, 212 insertions, 8 deletions
diff --git a/chrome/browser/views/html_dialog_view_browsertest.cc b/chrome/browser/views/html_dialog_view_browsertest.cc new file mode 100644 index 0000000..7bb9977 --- /dev/null +++ b/chrome/browser/views/html_dialog_view_browsertest.cc @@ -0,0 +1,204 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/ui/ui_test.h" + +#include "base/file_path.h" +#include "base/message_loop.h" +#include "chrome/browser/chrome_thread.h" +#include "chrome/browser/dom_ui/html_dialog_ui.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/browser/renderer_host/render_widget_host_view.h" +#include "chrome/browser/views/html_dialog_view.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/in_process_browser_test.h" +#include "chrome/test/ui_test_utils.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "testing/gmock/include/gmock/gmock.h" +#include "views/widget/widget.h" +#include "views/window/window.h" + +using testing::Eq; + +namespace { + +// Window non-client-area means that the minimum size for the window +// won't be the actual minimum size - our layout and resizing code +// makes sure the chrome is always visible. +const int kMinimumWidthToTestFor = 20; +const int kMinimumHeightToTestFor = 30; + +class TestHtmlDialogUIDelegate : public HtmlDialogUIDelegate { + public: + TestHtmlDialogUIDelegate() {} + virtual ~TestHtmlDialogUIDelegate() {} + + // HTMLDialogUIDelegate implementation: + virtual bool IsDialogModal() const { + return true; + } + virtual std::wstring GetDialogTitle() const { + return std::wstring(L"Test"); + } + virtual GURL GetDialogContentURL() const { + return GURL(chrome::kAboutBlankURL); + } + virtual void GetDOMMessageHandlers( + std::vector<DOMMessageHandler*>* handlers) const { } + virtual void GetDialogSize(gfx::Size* size) const { + size->set_width(40); + size->set_height(40); + } + virtual std::string GetDialogArgs() const { + return std::string(); + } + virtual void OnDialogClosed(const std::string& json_retval) { } + virtual void OnCloseContents(TabContents* source, bool* out_close_dialog) { + if (out_close_dialog) + *out_close_dialog = true; + } +}; + +} // namespace + +class HtmlDialogBrowserTest : public InProcessBrowserTest { + public: + HtmlDialogBrowserTest() {} + +#if defined(OS_WIN) + class WindowChangedObserver : public base::MessagePumpForUI::Observer { + public: + WindowChangedObserver() {} + + static WindowChangedObserver* Get() { + return Singleton<WindowChangedObserver>::get(); + } + + // This method is called before processing a message. + virtual void WillProcessMessage(const MSG& msg) {} + + // This method is called after processing a message. + virtual void DidProcessMessage(const MSG& msg) { + // Either WM_PAINT or WM_TIMER indicates the actual work of + // pushing through the window resizing messages is done since + // they are lower priority (we don't get to see the + // WM_WINDOWPOSCHANGED message here). + if (msg.message == WM_PAINT || msg.message == WM_TIMER) + MessageLoop::current()->Quit(); + } + }; +#elif !defined(OS_MACOSX) + class WindowChangedObserver : public base::MessagePumpForUI::Observer { + public: + WindowChangedObserver() {} + + static WindowChangedObserver* Get() { + return Singleton<WindowChangedObserver>::get(); + } + + // This method is called before processing a message. + virtual void WillProcessEvent(GdkEvent* event) {} + + // This method is called after processing a message. + virtual void DidProcessEvent(GdkEvent* event) { + // Quit once the GDK_CONFIGURE event has been processed - seeing + // this means the window sizing request that was made actually + // happened. + if (event->type == GDK_CONFIGURE) + MessageLoop::current()->Quit(); + } + }; +#endif +}; + +#if defined(OS_LINUX) +#define MAYBE_SizeWindow SizeWindow +#else +// http://code.google.com/p/chromium/issues/detail?id=52602 +// Windows has some issues resizing windows- an off by one problem, +// and a minimum size that seems too big. This file isn't included in +// Mac builds yet. +#define MAYBE_SizeWindow DISABLED_SizeWindow +#endif + +IN_PROC_BROWSER_TEST_F(HtmlDialogBrowserTest, MAYBE_SizeWindow) { + HtmlDialogUIDelegate* delegate = new TestHtmlDialogUIDelegate(); + + HtmlDialogView* html_view = + new HtmlDialogView(browser()->profile(), delegate); + TabContents* tab_contents = browser()->GetSelectedTabContents(); + ASSERT_TRUE(tab_contents != NULL); + views::Window::CreateChromeWindow(tab_contents->GetMessageBoxRootWindow(), + gfx::Rect(), html_view); + html_view->InitDialog(); + html_view->window()->Show(); + + MessageLoopForUI::current()->AddObserver(WindowChangedObserver::Get()); + + gfx::Rect bounds; + html_view->GetWidget()->GetBounds(&bounds, false); + + gfx::Rect set_bounds = bounds; + gfx::Rect actual_bounds, rwhv_bounds; + + // Bigger than the default in both dimensions. + set_bounds.set_width(400); + set_bounds.set_height(300); + + html_view->MoveContents(tab_contents, set_bounds); + ui_test_utils::RunMessageLoop(); + html_view->GetWidget()->GetBounds(&actual_bounds, false); + EXPECT_EQ(set_bounds, actual_bounds); + + rwhv_bounds = + html_view->tab_contents()->GetRenderWidgetHostView()->GetViewBounds(); + EXPECT_LT(0, rwhv_bounds.width()); + EXPECT_LT(0, rwhv_bounds.height()); + EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); + EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); + + // Larger in one dimension and smaller in the other. + set_bounds.set_width(550); + set_bounds.set_height(250); + + html_view->MoveContents(tab_contents, set_bounds); + ui_test_utils::RunMessageLoop(); + html_view->GetWidget()->GetBounds(&actual_bounds, false); + EXPECT_EQ(set_bounds, actual_bounds); + + rwhv_bounds = + html_view->tab_contents()->GetRenderWidgetHostView()->GetViewBounds(); + EXPECT_LT(0, rwhv_bounds.width()); + EXPECT_LT(0, rwhv_bounds.height()); + EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); + EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); + + // Get very small. + set_bounds.set_width(kMinimumWidthToTestFor); + set_bounds.set_height(kMinimumHeightToTestFor); + + html_view->MoveContents(tab_contents, set_bounds); + ui_test_utils::RunMessageLoop(); + html_view->GetWidget()->GetBounds(&actual_bounds, false); + EXPECT_EQ(set_bounds, actual_bounds); + + rwhv_bounds = + html_view->tab_contents()->GetRenderWidgetHostView()->GetViewBounds(); + EXPECT_LT(0, rwhv_bounds.width()); + EXPECT_LT(0, rwhv_bounds.height()); + EXPECT_GE(set_bounds.width(), rwhv_bounds.width()); + EXPECT_GE(set_bounds.height(), rwhv_bounds.height()); + + // Check to make sure we can't get to 0x0 + set_bounds.set_width(0); + set_bounds.set_height(0); + + html_view->MoveContents(tab_contents, set_bounds); + ui_test_utils::RunMessageLoop(); + html_view->GetWidget()->GetBounds(&actual_bounds, false); + EXPECT_LT(0, actual_bounds.width()); + EXPECT_LT(0, actual_bounds.height()); + + MessageLoopForUI::current()->RemoveObserver(WindowChangedObserver::Get()); +} diff --git a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc index e8265cb..c261600 100644 --- a/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/views/tab_contents/tab_contents_view_gtk.cc @@ -213,14 +213,13 @@ gfx::NativeWindow TabContentsViewGtk::GetTopLevelNativeWindow() const { } void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const { - GetBounds(out, false); - // Callers expect the requested bounds not the actual bounds. For example, // during init callers expect 0x0, but Gtk layout enforces a min size of 1x1. - GtkRequisition requisition; - gtk_widget_get_child_requisition(GetNativeView(), &requisition); - out->set_width(requisition.width); - out->set_height(requisition.height); + GetBounds(out, false); + + gfx::Size size; + WidgetGtk::GetRequestedSize(&size); + out->set_size(size); } void TabContentsViewGtk::StartDragging(const WebDropData& drop_data, diff --git a/chrome/browser/views/tabs/dragged_tab_view.cc b/chrome/browser/views/tabs/dragged_tab_view.cc index 5ee2626..8f77a87 100644 --- a/chrome/browser/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/views/tabs/dragged_tab_view.cc @@ -163,8 +163,7 @@ void DraggedTabView::PaintDetachedView(gfx::Canvas* canvas) { int image_x = kDragFrameBorderSize; int image_y = tab_size_.height(); int image_w = ps.width() - kTwiceDragFrameBorderSize; - int image_h = - ps.height() - kTwiceDragFrameBorderSize - tab_size_.height(); + int image_h = contents_size_.height(); scale_canvas.FillRectInt(SK_ColorBLACK, image_x, image_y, image_w, image_h); photobooth_->PaintScreenshotIntoCanvas( &scale_canvas, diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 1f60543..6323db8 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1764,6 +1764,7 @@ 'browser/ssl/ssl_browser_tests.cc', 'browser/task_manager_browsertest.cc', 'browser/views/browser_actions_container_browsertest.cc', + 'browser/views/html_dialog_view_browsertest.cc', 'renderer/form_autocomplete_browsertest.cc', 'renderer/safe_browsing/phishing_dom_feature_extractor_browsertest.cc', 'test/automation/dom_automation_browsertest.cc', @@ -1897,6 +1898,7 @@ 'sources!': [ 'browser/extensions/browser_action_test_util_views.cc', 'browser/views/browser_actions_container_browsertest.cc', + 'browser/views/html_dialog_view_browsertest.cc', ], }], ], # conditions |