diff options
-rw-r--r-- | chrome/chrome_tests.gypi | 3 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.cc | 13 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_views.cc | 34 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_views_unittest.cc | 24 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_win.cc | 7 | ||||
-rw-r--r-- | views/controls/textfield/textfield.cc | 17 | ||||
-rw-r--r-- | views/controls/textfield/textfield_views_model_unittest.cc | 1 | ||||
-rw-r--r-- | views/test/views_test_base.h | 49 | ||||
-rw-r--r-- | views/view_unittest.cc | 25 | ||||
-rw-r--r-- | views/views.gyp | 9 |
10 files changed, 107 insertions, 75 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 19b4580..163162f 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1731,6 +1731,7 @@ '../views/focus/accelerator_handler_gtk_unittest.cc', '../views/focus/focus_manager_unittest.cc', '../views/grid_layout_unittest.cc', + '../views/test/views_test_base.h', '../views/view_unittest.cc', ], 'conditions': [ @@ -1805,8 +1806,6 @@ 'browser/gtk/tabs/tab_renderer_gtk_unittest.cc', 'browser/renderer_host/gtk_key_bindings_handler_unittest.cc', '../views/focus/accelerator_handler_gtk_unittest.cc', - '../views/controls/textfield/textfield_views_model_unittest.cc', - '../views/controls/textfield/native_textfield_views_unittest.cc', ], }], ['OS=="linux" or OS=="freebsd"', { diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index 2271156..d5b1619 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -14,6 +14,7 @@ #include "gfx/skia_utils_gtk.h" #include "views/controls/textfield/gtk_views_entry.h" #include "views/controls/textfield/gtk_views_textview.h" +#include "views/controls/textfield/native_textfield_views.h" #include "views/controls/textfield/textfield.h" #include "views/widget/widget_gtk.h" @@ -462,4 +463,16 @@ bool NativeTextfieldGtk::IsPassword() { return textfield_->IsPassword(); } +/////////////////////////////////////////////////////////////////////////////// +// NativeTextfieldWrapper: + +// static +NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( + Textfield* field) { + if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { + return new NativeTextfieldViews(field); + } + return new NativeTextfieldGtk(field); +} + } // namespace views diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc index ceb5325..06ceb82 100644 --- a/views/controls/textfield/native_textfield_views.cc +++ b/views/controls/textfield/native_textfield_views.cc @@ -15,7 +15,6 @@ #include "gfx/insets.h" #include "views/background.h" #include "views/border.h" -#include "views/controls/textfield/native_textfield_gtk.h" #include "views/controls/textfield/textfield.h" #include "views/controls/textfield/textfield_views_model.h" #include "views/event.h" @@ -41,7 +40,7 @@ const int kCursorVisibleTimeMs = 800; const int kCursorInvisibleTimeMs = 500; // A switch to enable NativeTextfieldViews; -const char kEnableViewsBasedTextfieldSwitch[] = "enable-textfield-view"; +const char kEnableViewsBasedTextfieldSwitch[] = "enable-textfield-views"; } // namespace namespace views { @@ -692,19 +691,6 @@ size_t NativeTextfieldViews::FindCursorPosition(const gfx::Point& point) const { } /////////////////////////////////////////////////////////////////////////////// -// NativeTextfieldWrapper: - -// static -NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( - Textfield* field) { - if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { - return new NativeTextfieldViews(field); - } else { - return new NativeTextfieldGtk(field); - } -} - -/////////////////////////////////////////////////////////////////////////////// // // TextifieldBorder // @@ -722,17 +708,17 @@ void NativeTextfieldViews::TextfieldBorder::Paint( SkIntToScalar(view.width()), SkIntToScalar(view.height())); SkScalar corners[8] = { // top-left - insets_.left(), - insets_.top(), + SkIntToScalar(insets_.left()), + SkIntToScalar(insets_.top()), // top-right - insets_.right(), - insets_.top(), + SkIntToScalar(insets_.right()), + SkIntToScalar(insets_.top()), // bottom-right - insets_.right(), - insets_.bottom(), + SkIntToScalar(insets_.right()), + SkIntToScalar(insets_.bottom()), // bottom-left - insets_.left(), - insets_.bottom(), + SkIntToScalar(insets_.left()), + SkIntToScalar(insets_.bottom()), }; SkPath path; path.addRoundRect(rect, corners); @@ -741,7 +727,7 @@ void NativeTextfieldViews::TextfieldBorder::Paint( paint.setFlags(SkPaint::kAntiAlias_Flag); // TODO(oshima): Copy what WebKit does for focused border. paint.setColor(has_focus_ ? kFocusedBorderColor : kDefaultBorderColor); - paint.setStrokeWidth(has_focus_ ? 2 : 1); + paint.setStrokeWidth(SkIntToScalar(has_focus_ ? 2 : 1)); canvas->AsCanvasSkia()->drawPath(path, paint); } diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc index 9fc883c..f4b321a 100644 --- a/views/controls/textfield/native_textfield_views_unittest.cc +++ b/views/controls/textfield/native_textfield_views_unittest.cc @@ -3,14 +3,13 @@ // found in the LICENSE file. #include "app/keyboard_codes.h" -#include "base/message_loop.h" #include "base/utf_string_conversions.h" -#include "testing/gtest/include/gtest/gtest.h" #include "views/controls/textfield/native_textfield_views.h" #include "views/controls/textfield/textfield.h" #include "views/controls/textfield/textfield_views_model.h" #include "views/event.h" #include "views/focus/focus_manager.h" +#include "views/test/views_test_base.h" #include "views/widget/widget.h" namespace views { @@ -21,15 +20,14 @@ namespace views { // TODO(oshima): Move tests that are independent of TextfieldViews to // textfield_unittests.cc once we move the test utility functions // from chrome/browser/automation/ to app/test/. -class NativeTextfieldViewsTest : public ::testing::Test, +class NativeTextfieldViewsTest : public ViewsTestBase, public Textfield::Controller { public: NativeTextfieldViewsTest() : widget_(NULL), textfield_(NULL), textfield_view_(NULL), - model_(NULL), - message_loop_(MessageLoop::TYPE_UI) { + model_(NULL) { } // ::testing::Test overrides. @@ -41,6 +39,7 @@ class NativeTextfieldViewsTest : public ::testing::Test, NativeTextfieldViews::SetEnableTextfieldViews(false); if (widget_) widget_->Close(); + ViewsTestBase::TearDown(); } // Textfield::Controller implementation: @@ -69,11 +68,11 @@ class NativeTextfieldViewsTest : public ::testing::Test, Widget::AcceptEvents, Widget::DeleteOnDestroy, Widget::DontMirrorOriginInRTL); - widget_->Init(NULL, gfx::Rect()); - + widget_->Init(NULL, gfx::Rect(100, 100, 100, 100)); View* container = new View(); widget_->SetContentsView(container); container->AddChildView(textfield_); + textfield_view_ = static_cast<NativeTextfieldViews*>(textfield_->native_wrapper()); textfield_->SetID(1); @@ -121,9 +120,6 @@ class NativeTextfieldViewsTest : public ::testing::Test, NativeTextfieldViews* textfield_view_; TextfieldViewsModel* model_; - // A fake message loop for view's drawing events. - MessageLoop message_loop_; - // The string from Controller::ContentsChanged callback. string16 last_contents_; @@ -352,6 +348,14 @@ TEST_F(NativeTextfieldViewsTest, CursorMovement) { EXPECT_STR_EQ("one two", last_contents_); } +#if defined(OS_WIN) +// TODO(oshima): Windows' FocusManager::ClearNativeFocus() resets the +// focused view to NULL, which causes crash in this test. Figure out +// why and fix this. +#define MAYBE_FocusTraversalTest DISABLED_FocusTraversalTest +#else +#define MAYBE_FocusTraversalTest FocusTraversalTest +#endif TEST_F(NativeTextfieldViewsTest, FocusTraversalTest) { InitTextfields(Textfield::STYLE_DEFAULT, 3); textfield_->RequestFocus(); diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index 404459d..2010a7c 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -24,6 +24,7 @@ #include "views/controls/menu/menu_win.h" #include "views/controls/menu/menu_2.h" #include "views/controls/native/native_view_host.h" +#include "views/controls/textfield/native_textfield_views.h" #include "views/controls/textfield/textfield.h" #include "views/focus/focus_manager.h" #include "views/focus/focus_util_win.h" @@ -1114,7 +1115,11 @@ void NativeTextfieldWin::BuildContextMenu() { // static NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( Textfield* field) { - return new NativeTextfieldWin(field); + if (NativeTextfieldViews::IsTextfieldViewsEnabled()) { + return new NativeTextfieldViews(field); + } else { + return new NativeTextfieldWin(field); + } } } // namespace views diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index 9da78ec..53d3695 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -26,6 +26,7 @@ // TODO(beng): this should be removed when the OS_WIN hack from // ViewHierarchyChanged is removed. #include "views/controls/textfield/native_textfield_win.h" +#include "views/controls/textfield/native_textfield_views.h" #endif namespace views { @@ -361,13 +362,15 @@ void Textfield::ViewHierarchyChanged(bool is_add, View* parent, View* child) { UpdateAllProperties(); #if defined(OS_WIN) - // TODO(beng): remove this once NativeTextfieldWin subclasses - // NativeControlWin. This is currently called to perform post-AddChildView - // initialization for the wrapper. The GTK version subclasses things - // correctly and doesn't need this. - // - // Remove the include for native_textfield_win.h above when you fix this. - static_cast<NativeTextfieldWin*>(native_wrapper_)->AttachHack(); + if (!NativeTextfieldViews::IsTextfieldViewsEnabled()) { + // TODO(beng): remove this once NativeTextfieldWin subclasses + // NativeControlWin. This is currently called to perform post-AddChildView + // initialization for the wrapper. The GTK version subclasses things + // correctly and doesn't need this. + // + // Remove the include for native_textfield_win.h above when you fix this. + static_cast<NativeTextfieldWin*>(native_wrapper_)->AttachHack(); + } #endif } } diff --git a/views/controls/textfield/textfield_views_model_unittest.cc b/views/controls/textfield/textfield_views_model_unittest.cc index 388c8c3..87cace2 100644 --- a/views/controls/textfield/textfield_views_model_unittest.cc +++ b/views/controls/textfield/textfield_views_model_unittest.cc @@ -215,7 +215,6 @@ TEST(TextfieldViewsModelTest, TextFragment) { // Empty string model.GetFragments(&fragments); EXPECT_EQ(1U, fragments.size()); - fragments.clear(); EXPECT_EQ(0U, fragments[0].begin); EXPECT_EQ(0U, fragments[0].end); EXPECT_FALSE(fragments[0].selected); diff --git a/views/test/views_test_base.h b/views/test/views_test_base.h new file mode 100644 index 0000000..080eca5 --- /dev/null +++ b/views/test/views_test_base.h @@ -0,0 +1,49 @@ +// Copyright (c) 2011 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. + +#ifndef VIEWS_TEST_VIEWS_TEST_BASE_H_ +#define VIEWS_TEST_VIEWS_TEST_BASE_H_ +#pragma once + +#include "testing/gtest/include/gtest/gtest.h" + +#include "base/message_loop.h" + +namespace views { + +// A base class for views unit test. It creates a message loop necessary +// to drive UI events and takes care of OLE initialization for windows. +class ViewsTestBase : public testing::Test { + public: + ViewsTestBase() { +#if defined(OS_WIN) + OleInitialize(NULL); +#endif + } + + virtual ~ViewsTestBase() { +#if defined(OS_WIN) + OleUninitialize(); +#endif + } + + virtual void TearDown() { + // Flush the message loop because we have pending release tasks + // and these tasks if un-executed would upset Valgrind. + RunPendingMessages(); + } + + void RunPendingMessages() { + message_loop_.RunAllPending(); + } + + private: + MessageLoopForUI message_loop_; + + DISALLOW_COPY_AND_ASSIGN(ViewsTestBase); +}; + +} // namespace views + +#endif // VIEWS_TEST_VIEWS_TEST_BASE_H_ diff --git a/views/view_unittest.cc b/views/view_unittest.cc index d29af08..0bd612f 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -5,12 +5,10 @@ #include <map> #include "app/keyboard_codes.h" -#include "base/message_loop.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "gfx/canvas_skia.h" #include "gfx/path.h" -#include "testing/gtest/include/gtest/gtest.h" #include "ui/base/clipboard/clipboard.h" #include "views/background.h" #include "views/controls/button/checkbox.h" @@ -20,6 +18,7 @@ #include "views/event.h" #include "views/focus/accelerator_handler.h" #include "views/focus/view_storage.h" +#include "views/test/views_test_base.h" #include "views/view.h" #include "views/views_delegate.h" #include "views/widget/root_view.h" @@ -42,24 +41,12 @@ using namespace views; namespace { -class ViewTest : public testing::Test { +class ViewTest : public ViewsTestBase { public: ViewTest() { -#if defined(OS_WIN) - OleInitialize(NULL); -#endif } - ~ViewTest() { -#if defined(OS_WIN) - OleUninitialize(); -#endif - } - - virtual void TearDown() { - // Flush the message loop because we have pending release tasks - // and these tasks if un-executed would upset Valgrind. - RunPendingMessages(); + virtual ~ViewTest() { } Widget* CreateWidget() { @@ -69,12 +56,6 @@ class ViewTest : public testing::Test { return new WidgetGtk(WidgetGtk::TYPE_WINDOW); #endif } - - void RunPendingMessages() { - message_loop_.RunAllPending(); - } - private: - MessageLoopForUI message_loop_; }; // Paints the RootView. diff --git a/views/views.gyp b/views/views.gyp index dee51e3..9e67f12 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -399,10 +399,6 @@ 'controls/slider/slider.cc', 'controls/slider/slider.h', 'controls/slider/native_slider_wrapper.h', - 'controls/textfield/native_textfield_views.cc', - 'controls/textfield/native_textfield_views.h', - 'controls/textfield/textfield_views_model.cc', - 'controls/textfield/textfield_views_model.h', ], 'include_dirs': [ '<(DEPTH)/third_party/wtl/include', @@ -440,6 +436,7 @@ 'focus/accelerator_handler_gtk_unittest.cc', 'focus/focus_manager_unittest.cc', 'grid_layout_unittest.cc', + 'test/views_test_base.h', 'run_all_unittests.cc', 'test/test_views_delegate.h', 'view_unittest.cc', @@ -468,10 +465,6 @@ # unrelated things like v8, sqlite nss...). '../chrome/app/locales/locales.gyp:en-US', ], - 'sources!': [ - 'controls/textfield/native_textfield_views_unittest.cc', - 'controls/textfield/textfield_views_model_unittest.cc', - ], 'link_settings': { 'libraries': [ '-limm32.lib', |