Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Unified Diff: views/view_unittest.cc

Issue 6881107: Rework the way Widget::Init works: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « views/focus/focus_manager_unittest.cc ('k') | views/widget/native_widget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/view_unittest.cc
===================================================================
--- views/view_unittest.cc (revision 83020)
+++ views/view_unittest.cc (working copy)
@@ -52,11 +52,6 @@
virtual ~ViewTest() {
}
-
- Widget* CreateWidget() {
- return Widget::CreateWidget(
- Widget::CreateParams(Widget::CreateParams::TYPE_WINDOW));
- }
};
/*
@@ -366,11 +361,11 @@
TestView* v2 = new TestView();
v2->SetBounds(100, 100, 100, 100);
- scoped_ptr<Widget> widget(CreateWidget());
+ scoped_ptr<Widget> widget(Widget::CreateWidget());
Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
params.delete_on_destroy = false;
- widget->SetCreateParams(params);
- widget->Init(NULL, gfx::Rect(50, 50, 650, 650));
+ params.bounds = gfx::Rect(50, 50, 650, 650);
+ widget->Init(params);
RootView* root = widget->GetRootView();
root->AddChildView(v1);
@@ -475,15 +470,11 @@
TestView* v3 = new TestViewIgnoreTouch();
v3->SetBounds(0, 0, 100, 100);
- scoped_ptr<Widget> window(CreateWidget());
-#if defined(OS_WIN)
- // This code would need to be here when we support
- // touch on windows?
- WidgetWin* window_win = static_cast<WidgetWin*>(window.get());
- window_win->set_delete_on_destroy(false);
- window_win->set_window_style(WS_OVERLAPPEDWINDOW);
- window_win->Init(NULL, gfx::Rect(50, 50, 650, 650));
-#endif
+ scoped_ptr<Widget> widget(Widget::CreateWidget());
+ Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
+ params.delete_on_destroy = false;
+ params.bounds = gfx::Rect(50, 50, 650, 650);
+ widget->Init(params);
RootView* root = window->GetRootView();
root->AddChildView(v1);
@@ -578,7 +569,7 @@
EXPECT_EQ(NULL, gm->last_view_);
EXPECT_EQ(gm->previously_handled_flag_, false);
- window->CloseNow();
+ widget->CloseNow();
}
#endif
@@ -673,8 +664,8 @@
TEST_F(ViewTest, RemoveNotification) {
views::ViewStorage* vs = views::ViewStorage::GetInstance();
- views::Widget* window = CreateWidget();
- views::RootView* root_view = window->GetRootView();
+ views::Widget* widget = Widget::CreateWidget();
+ views::RootView* root_view = widget->GetRootView();
View* v1 = new View;
int s1 = vs->CreateStorageID();
@@ -748,7 +739,7 @@
// Now delete the root view (deleting the window will trigger a delete of the
// RootView) and make sure we are notified that the views were removed.
- delete window;
+ delete widget;
EXPECT_EQ(stored_views - 10, vs->view_count());
EXPECT_EQ(NULL, vs->RetrieveView(s1));
EXPECT_EQ(NULL, vs->RetrieveView(s12));
@@ -800,8 +791,8 @@
}
TEST_F(ViewTest, HitTestMasks) {
- scoped_ptr<views::Widget> window(CreateWidget());
- views::RootView* root_view = window->GetRootView();
+ scoped_ptr<views::Widget> widget(Widget::CreateWidget());
+ views::RootView* root_view = widget->GetRootView();
root_view->SetBounds(0, 0, 500, 500);
gfx::Rect v1_bounds = gfx::Rect(0, 0, 100, 100);
@@ -841,9 +832,11 @@
ui::Clipboard clipboard;
- Widget* window = CreateWidget();
- window->Init(NULL, gfx::Rect(0, 0, 100, 100));
- RootView* root_view = window->GetRootView();
+ Widget* widget = Widget::CreateWidget();
+ Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
+ params.bounds = gfx::Rect(0, 0, 100, 100);
+ widget->Init(params);
+ RootView* root_view = widget->GetRootView();
Textfield* textfield = new Textfield();
root_view->AddChildView(textfield);
@@ -877,11 +870,11 @@
ui::Clipboard clipboard;
- Widget* window = CreateWidget();
-#if defined(OS_WIN)
- static_cast<WidgetWin*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100));
-#endif
- RootView* root_view = window->GetRootView();
+ Widget* widget = Widget::CreateWidget();
+ Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
+ params.bounds = gfx::Rect(0, 0, 100, 100);
+ widget->Init(params);
+ RootView* root_view = widget->GetRootView();
Textfield* normal = new Textfield();
Textfield* read_only = new Textfield();
@@ -1001,17 +994,18 @@
EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
// Create a window and add the view as its child.
- WidgetWin widget;
+ scoped_ptr<Widget> widget(Widget::CreateWidget());
Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
params.delete_on_destroy = false;
- widget.SetCreateParams(params);
- widget.Init(NULL, gfx::Rect(0, 0, 100, 100));
- RootView* root = widget.GetRootView();
+ params.bounds = gfx::Rect(0, 0, 100, 100);
+ widget->Init(params);
+ RootView* root = widget->GetRootView();
root->AddChildView(view);
// Get the focus manager.
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(widget.GetNativeView());
+ views::FocusManager::GetFocusManagerForNativeView(
+ widget->GetNativeView());
ASSERT_TRUE(focus_manager);
// Hit the return key and see if it takes effect.
@@ -1054,7 +1048,7 @@
EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 2);
EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 2);
- widget.CloseNow();
+ widget->CloseNow();
}
#endif
@@ -1066,16 +1060,17 @@
view->AddAccelerator(return_accelerator);
EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
- WidgetWin widget;
+ scoped_ptr<Widget> widget(Widget::CreateWidget());
Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
params.delete_on_destroy = false;
- widget.SetCreateParams(params);
- widget.Init(NULL, gfx::Rect(0, 0, 100, 100));
- RootView* root = widget.GetRootView();
+ params.bounds = gfx::Rect(0, 0, 100, 100);
+ widget->Init(params);
+ RootView* root = widget->GetRootView();
root->AddChildView(view);
views::FocusManager* focus_manager =
- views::FocusManager::GetFocusManagerForNativeView(widget.GetNativeView());
+ views::FocusManager::GetFocusManagerForNativeView(
+ widget->GetNativeView());
ASSERT_TRUE(focus_manager);
view->SetVisible(false);
@@ -1086,7 +1081,7 @@
EXPECT_EQ(view,
focus_manager->GetCurrentTargetForAccelerator(return_accelerator));
- widget.CloseNow();
+ widget->CloseNow();
}
#endif
@@ -1558,12 +1553,17 @@
explicit TestChangeNativeViewHierarchy(ViewTest *view_test) {
view_test_ = view_test;
native_host_ = new views::NativeViewHost();
- host_ = view_test->CreateWidget();
- host_->Init(NULL, gfx::Rect(0, 0, 500, 300));
+ host_ = Widget::CreateWidget();
+ Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
+ params.bounds = gfx::Rect(0, 0, 500, 300);
+ host_->Init(params);
host_->GetRootView()->AddChildView(native_host_);
for (size_t i = 0; i < TestNativeViewHierarchy::kTotalViews; ++i) {
- windows_[i] = view_test->CreateWidget();
- windows_[i]->Init(host_->GetNativeView(), gfx::Rect(0, 0, 500, 300));
+ windows_[i] = Widget::CreateWidget();
+ Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
+ params.parent = host_->GetNativeView();
+ params.bounds = gfx::Rect(0, 0, 500, 300);
+ windows_[i]->Init(params);
root_views_[i] = windows_[i]->GetRootView();
test_views_[i] = new TestNativeViewHierarchy;
root_views_[i]->AddChildView(test_views_[i]);
@@ -1684,12 +1684,10 @@
TestView* v2 = new TestView();
v2->SetBounds(100, 100, 200, 100);
- Widget* widget = CreateWidget();
-#if defined(OS_WIN)
- WidgetWin* window_win = static_cast<WidgetWin*>(widget);
- window_win->set_window_style(WS_OVERLAPPEDWINDOW);
- window_win->Init(NULL, gfx::Rect(50, 50, 650, 650));
-#endif
+ Widget* widget = Widget::CreateWidget();
+ Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
+ params.bounds = gfx::Rect(50, 50, 650, 650);
+ widget->Init(params);
widget->Show();
RootView* root = widget->GetRootView();
@@ -1723,12 +1721,10 @@
TestView* v2 = new TestView();
v2->SetBounds(100, 100, 200, 100);
- Widget* widget = CreateWidget();
-#if defined(OS_WIN)
- WidgetWin* window_win = static_cast<WidgetWin*>(widget);
- window_win->set_window_style(WS_OVERLAPPEDWINDOW);
- window_win->Init(NULL, gfx::Rect(50, 50, 650, 650));
-#endif
+ Widget* widget = Widget::CreateWidget();
+ Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
+ params.bounds = gfx::Rect(50, 50, 650, 650);
+ widget->Init(params);
RootView* root = widget->GetRootView();
root->AddChildView(v1);
@@ -1875,11 +1871,11 @@
TEST_F(ViewTest, OnVisibleBoundsChanged) {
gfx::Rect viewport_bounds(0, 0, 100, 100);
- scoped_ptr<Widget> widget(CreateWidget());
+ scoped_ptr<Widget> widget(Widget::CreateWidget());
Widget::CreateParams params(Widget::CreateParams::TYPE_WINDOW);
params.delete_on_destroy = false;
- widget->SetCreateParams(params);
- widget->Init(NULL, viewport_bounds);
+ params.bounds = viewport_bounds;
+ widget->Init(params);
widget->GetRootView()->SetBoundsRect(viewport_bounds);
View* viewport = new View;
« no previous file with comments | « views/focus/focus_manager_unittest.cc ('k') | views/widget/native_widget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698