diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-26 20:09:22 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-26 20:09:22 +0000 |
commit | 366a35ada815caefc10ae3d56f811ac0f051d0ff (patch) | |
tree | 032439c4001d6dd10aeb320c9813e028325ad393 /ash/keyboard_overlay | |
parent | 2f6ce942a3f1bb2be4e0e20c58dd7a6baca6e929 (diff) | |
download | chromium_src-366a35ada815caefc10ae3d56f811ac0f051d0ff.zip chromium_src-366a35ada815caefc10ae3d56f811ac0f051d0ff.tar.gz chromium_src-366a35ada815caefc10ae3d56f811ac0f051d0ff.tar.bz2 |
Add unit test for showing the keyboard overlay widget
Also refactored KeyboardOverlayDelegate so I can pass a NULL WebDialogView
to the Show() method, as Ash unit tests do not have the content and chrome
components available to allow a WebDialog to instantiate a WebContents.
BUG=172176
TEST=added ash_unittests KeyboardOverlayDelegateTest
Review URL: https://chromiumcodereview.appspot.com/12089004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179071 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/keyboard_overlay')
-rw-r--r-- | ash/keyboard_overlay/keyboard_overlay_delegate.cc | 21 | ||||
-rw-r--r-- | ash/keyboard_overlay/keyboard_overlay_delegate.h | 16 | ||||
-rw-r--r-- | ash/keyboard_overlay/keyboard_overlay_delegate_unittest.cc | 42 |
3 files changed, 63 insertions, 16 deletions
diff --git a/ash/keyboard_overlay/keyboard_overlay_delegate.cc b/ash/keyboard_overlay/keyboard_overlay_delegate.cc index 8381432..d6f7890 100644 --- a/ash/keyboard_overlay/keyboard_overlay_delegate.cc +++ b/ash/keyboard_overlay/keyboard_overlay_delegate.cc @@ -66,34 +66,33 @@ KeyboardOverlayDelegate::KeyboardOverlayDelegate(const string16& title, const GURL& url) : title_(title), url_(url), - view_(NULL) { + widget_(NULL) { } KeyboardOverlayDelegate::~KeyboardOverlayDelegate() { } -void KeyboardOverlayDelegate::Show(views::WebDialogView* view) { - view_ = view; - - views::Widget* widget = new views::Widget; +views::Widget* KeyboardOverlayDelegate::Show(views::WebDialogView* view) { + widget_ = new views::Widget; views::Widget::InitParams params( views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); params.context = Shell::GetPrimaryRootWindow(); params.delegate = view; - widget->Init(params); + widget_->Init(params); // Show the widget at the bottom of the work area. gfx::Size size; GetDialogSize(&size); const gfx::Rect& rect = Shell::GetScreen()->GetDisplayNearestWindow( - widget->GetNativeView()).work_area(); + widget_->GetNativeView()).work_area(); gfx::Rect bounds((rect.width() - size.width()) / 2, rect.height() - size.height(), size.width(), size.height()); - widget->SetBounds(bounds); + widget_->SetBounds(bounds); // The widget will be shown when the web contents gets ready to display. + return widget_; } ui::ModalType KeyboardOverlayDelegate::GetDialogModalType() const { @@ -110,15 +109,15 @@ GURL KeyboardOverlayDelegate::GetDialogContentURL() const { void KeyboardOverlayDelegate::GetWebUIMessageHandlers( std::vector<WebUIMessageHandler*>* handlers) const { - handlers->push_back(new PaintMessageHandler(view_->GetWidget())); + handlers->push_back(new PaintMessageHandler(widget_)); } void KeyboardOverlayDelegate::GetDialogSize( gfx::Size* size) const { using std::min; - DCHECK(view_); + DCHECK(widget_); gfx::Rect rect = ash::Shell::GetScreen()->GetDisplayNearestWindow( - view_->GetWidget()->GetNativeView()).bounds(); + widget_->GetNativeView()).bounds(); const int width = min(kBaseWidth, rect.width() - kHorizontalMargin); const int height = width * kBaseHeight / kBaseWidth; size->SetSize(width, height); diff --git a/ash/keyboard_overlay/keyboard_overlay_delegate.h b/ash/keyboard_overlay/keyboard_overlay_delegate.h index 48101e0..57dc0d4 100644 --- a/ash/keyboard_overlay/keyboard_overlay_delegate.h +++ b/ash/keyboard_overlay/keyboard_overlay_delegate.h @@ -5,27 +5,34 @@ #ifndef ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_DELEGATE_H_ #define ASH_KEYBOARD_OVERLAY_KEYBOARD_OVERLAY_DELEGATE_H_ +#include "ash/ash_export.h" #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/gtest_prod_util.h" #include "googleurl/src/gurl.h" #include "ui/web_dialogs/web_dialog_delegate.h" namespace views { class WebDialogView; +class Widget; } namespace ash { -class KeyboardOverlayDelegate : public ui::WebDialogDelegate { +// Delegate to handle showing the keyboard overlay drawing. Exported for test. +class ASH_EXPORT KeyboardOverlayDelegate : public ui::WebDialogDelegate { public: KeyboardOverlayDelegate(const string16& title, const GURL& url); - void Show(views::WebDialogView* view); + // Shows the keyboard overlay widget. Returns the widget for testing. + views::Widget* Show(views::WebDialogView* view); // Overridden from ui::WebDialogDelegate: virtual void GetDialogSize(gfx::Size* size) const OVERRIDE; private: + FRIEND_TEST_ALL_PREFIXES(KeyboardOverlayDelegateTest, ShowAndClose); + virtual ~KeyboardOverlayDelegate(); // Overridden from ui::WebDialogDelegate: @@ -48,9 +55,8 @@ class KeyboardOverlayDelegate : public ui::WebDialogDelegate { // The URL of the keyboard overlay. GURL url_; - // The view associated with this delegate. - // This class does not own the pointer. - views::WebDialogView* view_; + // The widget associated with this delegate. Not owned. + views::Widget* widget_; DISALLOW_COPY_AND_ASSIGN(KeyboardOverlayDelegate); }; diff --git a/ash/keyboard_overlay/keyboard_overlay_delegate_unittest.cc b/ash/keyboard_overlay/keyboard_overlay_delegate_unittest.cc new file mode 100644 index 0000000..c0c3825 --- /dev/null +++ b/ash/keyboard_overlay/keyboard_overlay_delegate_unittest.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2013 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 "ash/keyboard_overlay/keyboard_overlay_delegate.h" + +#include "ash/shell.h" +#include "ash/test/ash_test_base.h" +#include "base/utf_string_conversions.h" +#include "ui/aura/window.h" +#include "ui/gfx/display.h" +#include "ui/gfx/screen.h" +#include "ui/views/widget/widget.h" + +namespace ash { + +typedef test::AshTestBase KeyboardOverlayDelegateTest; + +// Verifies we can show and close the widget for the overlay dialog. +TEST_F(KeyboardOverlayDelegateTest, ShowAndClose) { + UpdateDisplay("500x400,300x200"); + KeyboardOverlayDelegate delegate(ASCIIToUTF16("Title"), + GURL("chrome://keyboardoverlay/")); + // Showing the dialog creates a widget. + views::Widget* widget = delegate.Show(NULL); + EXPECT_TRUE(widget); + + // The widget is on the primary root window. + EXPECT_EQ(Shell::GetPrimaryRootWindow(), + widget->GetNativeWindow()->GetRootWindow()); + + // The widget is horizontally centered at the bottom of the work area. + gfx::Rect work_area = Shell::GetScreen()->GetPrimaryDisplay().work_area(); + gfx::Rect bounds = widget->GetRestoredBounds(); + EXPECT_EQ(work_area.CenterPoint().x(), bounds.CenterPoint().x()); + EXPECT_EQ(work_area.bottom(), bounds.bottom()); + + // Clean up. + widget->CloseNow(); +} + +} // namespace ash |