| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/test/base/interactive_test_utils.h" | 7 #include "chrome/test/base/interactive_test_utils.h" |
| 8 #include "chrome/test/base/ui_test_utils.h" | 8 #include "chrome/test/base/ui_test_utils.h" |
| 9 #include "chrome/test/base/view_event_test_base.h" | 9 #include "chrome/test/base/view_event_test_base.h" |
| 10 #include "ui/base/models/menu_model.h" | 10 #include "ui/base/models/menu_model.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 virtual ~MenuModelAdapterTest() { | 199 virtual ~MenuModelAdapterTest() { |
| 200 } | 200 } |
| 201 | 201 |
| 202 // ViewEventTestBase implementation. | 202 // ViewEventTestBase implementation. |
| 203 | 203 |
| 204 virtual void SetUp() OVERRIDE { | 204 virtual void SetUp() OVERRIDE { |
| 205 button_ = new views::MenuButton( | 205 button_ = new views::MenuButton( |
| 206 NULL, base::ASCIIToUTF16("Menu Adapter Test"), this, true); | 206 NULL, base::ASCIIToUTF16("Menu Adapter Test"), this, true); |
| 207 | 207 |
| 208 menu_ = menu_model_adapter_.CreateMenu(); | 208 menu_ = menu_model_adapter_.CreateMenu(); |
| 209 menu_runner_.reset(new views::MenuRunner(menu_)); | 209 menu_runner_.reset( |
| 210 new views::MenuRunner(menu_, views::MenuRunner::HAS_MNEMONICS)); |
| 210 | 211 |
| 211 ViewEventTestBase::SetUp(); | 212 ViewEventTestBase::SetUp(); |
| 212 } | 213 } |
| 213 | 214 |
| 214 virtual void TearDown() OVERRIDE { | 215 virtual void TearDown() OVERRIDE { |
| 215 menu_runner_.reset(NULL); | 216 menu_runner_.reset(NULL); |
| 216 menu_ = NULL; | 217 menu_ = NULL; |
| 217 ViewEventTestBase::TearDown(); | 218 ViewEventTestBase::TearDown(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 virtual views::View* CreateContentsView() OVERRIDE { | 221 virtual views::View* CreateContentsView() OVERRIDE { |
| 221 return button_; | 222 return button_; |
| 222 } | 223 } |
| 223 | 224 |
| 224 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 225 virtual gfx::Size GetPreferredSize() const OVERRIDE { |
| 225 return button_->GetPreferredSize(); | 226 return button_->GetPreferredSize(); |
| 226 } | 227 } |
| 227 | 228 |
| 228 // views::MenuButtonListener implementation. | 229 // views::MenuButtonListener implementation. |
| 229 virtual void OnMenuButtonClicked(views::View* source, | 230 virtual void OnMenuButtonClicked(views::View* source, |
| 230 const gfx::Point& point) OVERRIDE { | 231 const gfx::Point& point) OVERRIDE { |
| 231 gfx::Point screen_location; | 232 gfx::Point screen_location; |
| 232 views::View::ConvertPointToScreen(source, &screen_location); | 233 views::View::ConvertPointToScreen(source, &screen_location); |
| 233 gfx::Rect bounds(screen_location, source->size()); | 234 gfx::Rect bounds(screen_location, source->size()); |
| 234 ignore_result(menu_runner_->RunMenuAt(source->GetWidget(), | 235 ignore_result(menu_runner_->RunMenuAt(source->GetWidget(), |
| 235 button_, | 236 button_, |
| 236 bounds, | 237 bounds, |
| 237 views::MENU_ANCHOR_TOPLEFT, | 238 views::MENU_ANCHOR_TOPLEFT, |
| 238 ui::MENU_SOURCE_NONE, | 239 ui::MENU_SOURCE_NONE)); |
| 239 views::MenuRunner::HAS_MNEMONICS)); | |
| 240 } | 240 } |
| 241 | 241 |
| 242 // ViewEventTestBase implementation | 242 // ViewEventTestBase implementation |
| 243 virtual void DoTestOnMessageLoop() OVERRIDE { | 243 virtual void DoTestOnMessageLoop() OVERRIDE { |
| 244 Click(button_, CreateEventTask(this, &MenuModelAdapterTest::Step1)); | 244 Click(button_, CreateEventTask(this, &MenuModelAdapterTest::Step1)); |
| 245 } | 245 } |
| 246 | 246 |
| 247 // Open the submenu. | 247 // Open the submenu. |
| 248 void Step1() { | 248 void Step1() { |
| 249 views::SubmenuView* topmenu = menu_->GetSubmenu(); | 249 views::SubmenuView* topmenu = menu_->GetSubmenu(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 303 } |
| 304 | 304 |
| 305 views::MenuButton* button_; | 305 views::MenuButton* button_; |
| 306 TopMenuModel top_menu_model_; | 306 TopMenuModel top_menu_model_; |
| 307 views::MenuModelAdapter menu_model_adapter_; | 307 views::MenuModelAdapter menu_model_adapter_; |
| 308 views::MenuItemView* menu_; | 308 views::MenuItemView* menu_; |
| 309 scoped_ptr<views::MenuRunner> menu_runner_; | 309 scoped_ptr<views::MenuRunner> menu_runner_; |
| 310 }; | 310 }; |
| 311 | 311 |
| 312 VIEW_TEST(MenuModelAdapterTest, RebuildMenu) | 312 VIEW_TEST(MenuModelAdapterTest, RebuildMenu) |
| OLD | NEW |