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

Side by Side Diff: views/view_unittest.cc

Issue 3354005: Re-lands 58186: (Closed)
Patch Set: Created 10 years, 3 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 unified diff | Download patch
« no previous file with comments | « views/focus/focus_manager_unittest.cc ('k') | views/widget/root_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <map> 5 #include <map>
6 6
7 #include "app/clipboard/clipboard.h" 7 #include "app/clipboard/clipboard.h"
8 #include "base/keyboard_codes.h" 8 #include "app/keyboard_codes.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "gfx/canvas_skia.h" 12 #include "gfx/canvas_skia.h"
13 #include "gfx/path.h" 13 #include "gfx/path.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "views/background.h" 15 #include "views/background.h"
16 #include "views/controls/button/checkbox.h" 16 #include "views/controls/button/checkbox.h"
17 #if defined(OS_WIN) 17 #if defined(OS_WIN)
18 #include "views/controls/button/native_button_win.h" 18 #include "views/controls/button/native_button_win.h"
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 // Accelerators 821 // Accelerators
822 //////////////////////////////////////////////////////////////////////////////// 822 ////////////////////////////////////////////////////////////////////////////////
823 bool TestView::AcceleratorPressed(const Accelerator& accelerator) { 823 bool TestView::AcceleratorPressed(const Accelerator& accelerator) {
824 accelerator_count_map_[accelerator]++; 824 accelerator_count_map_[accelerator]++;
825 return true; 825 return true;
826 } 826 }
827 827
828 #if defined(OS_WIN) 828 #if defined(OS_WIN)
829 TEST_F(ViewTest, ActivateAccelerator) { 829 TEST_F(ViewTest, ActivateAccelerator) {
830 // Register a keyboard accelerator before the view is added to a window. 830 // Register a keyboard accelerator before the view is added to a window.
831 views::Accelerator return_accelerator(base::VKEY_RETURN, false, false, false); 831 views::Accelerator return_accelerator(app::VKEY_RETURN, false, false, false);
832 TestView* view = new TestView(); 832 TestView* view = new TestView();
833 view->Reset(); 833 view->Reset();
834 view->AddAccelerator(return_accelerator); 834 view->AddAccelerator(return_accelerator);
835 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0); 835 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 0);
836 836
837 // Create a window and add the view as its child. 837 // Create a window and add the view as its child.
838 WidgetWin window; 838 WidgetWin window;
839 window.Init(NULL, gfx::Rect(0, 0, 100, 100)); 839 window.Init(NULL, gfx::Rect(0, 0, 100, 100));
840 window.set_delete_on_destroy(false); 840 window.set_delete_on_destroy(false);
841 window.set_window_style(WS_OVERLAPPEDWINDOW); 841 window.set_window_style(WS_OVERLAPPEDWINDOW);
842 RootView* root = window.GetRootView(); 842 RootView* root = window.GetRootView();
843 root->AddChildView(view); 843 root->AddChildView(view);
844 844
845 // Get the focus manager. 845 // Get the focus manager.
846 views::FocusManager* focus_manager = 846 views::FocusManager* focus_manager =
847 views::FocusManager::GetFocusManagerForNativeView(window.GetNativeView()); 847 views::FocusManager::GetFocusManagerForNativeView(window.GetNativeView());
848 ASSERT_TRUE(focus_manager); 848 ASSERT_TRUE(focus_manager);
849 849
850 // Hit the return key and see if it takes effect. 850 // Hit the return key and see if it takes effect.
851 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator)); 851 EXPECT_TRUE(focus_manager->ProcessAccelerator(return_accelerator));
852 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); 852 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1);
853 853
854 // Hit the escape key. Nothing should happen. 854 // Hit the escape key. Nothing should happen.
855 views::Accelerator escape_accelerator(base::VKEY_ESCAPE, false, false, false); 855 views::Accelerator escape_accelerator(app::VKEY_ESCAPE, false, false, false);
856 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator)); 856 EXPECT_FALSE(focus_manager->ProcessAccelerator(escape_accelerator));
857 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); 857 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1);
858 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0); 858 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 0);
859 859
860 // Now register the escape key and hit it again. 860 // Now register the escape key and hit it again.
861 view->AddAccelerator(escape_accelerator); 861 view->AddAccelerator(escape_accelerator);
862 EXPECT_TRUE(focus_manager->ProcessAccelerator(escape_accelerator)); 862 EXPECT_TRUE(focus_manager->ProcessAccelerator(escape_accelerator));
863 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1); 863 EXPECT_EQ(view->accelerator_count_map_[return_accelerator], 1);
864 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 1); 864 EXPECT_EQ(view->accelerator_count_map_[escape_accelerator], 1);
865 865
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
1101 window->Show(); 1101 window->Show();
1102 focus_manager_ = test_dialog_->contents_->GetFocusManager(); 1102 focus_manager_ = test_dialog_->contents_->GetFocusManager();
1103 ASSERT_TRUE(focus_manager_ != NULL); 1103 ASSERT_TRUE(focus_manager_ != NULL);
1104 client_view_ = 1104 client_view_ =
1105 static_cast<views::DialogClientView*>(window->GetClientView()); 1105 static_cast<views::DialogClientView*>(window->GetClientView());
1106 ok_button_ = client_view_->ok_button(); 1106 ok_button_ = client_view_->ok_button();
1107 cancel_button_ = client_view_->cancel_button(); 1107 cancel_button_ = client_view_->cancel_button();
1108 } 1108 }
1109 1109
1110 void SimularePressingEnterAndCheckDefaultButton(ButtonID button_id) { 1110 void SimularePressingEnterAndCheckDefaultButton(ButtonID button_id) {
1111 KeyEvent event(Event::ET_KEY_PRESSED, base::VKEY_RETURN, 0, 0, 0); 1111 KeyEvent event(Event::ET_KEY_PRESSED, app::VKEY_RETURN, 0, 0, 0);
1112 focus_manager_->OnKeyEvent(event); 1112 focus_manager_->OnKeyEvent(event);
1113 switch (button_id) { 1113 switch (button_id) {
1114 case OK: 1114 case OK:
1115 EXPECT_TRUE(test_dialog_->oked_); 1115 EXPECT_TRUE(test_dialog_->oked_);
1116 EXPECT_FALSE(test_dialog_->canceled_); 1116 EXPECT_FALSE(test_dialog_->canceled_);
1117 EXPECT_FALSE(test_dialog_->last_pressed_button_); 1117 EXPECT_FALSE(test_dialog_->last_pressed_button_);
1118 break; 1118 break;
1119 case CANCEL: 1119 case CANCEL:
1120 EXPECT_FALSE(test_dialog_->oked_); 1120 EXPECT_FALSE(test_dialog_->oked_);
1121 EXPECT_TRUE(test_dialog_->canceled_); 1121 EXPECT_TRUE(test_dialog_->canceled_);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1345 #endif 1345 #endif
1346 } 1346 }
1347 1347
1348 TEST_F(ViewTest, ChangeNativeViewHierarchyChangeHierarchy) { 1348 TEST_F(ViewTest, ChangeNativeViewHierarchyChangeHierarchy) {
1349 // TODO(georgey): Fix the test for Linux 1349 // TODO(georgey): Fix the test for Linux
1350 #if defined(OS_WIN) 1350 #if defined(OS_WIN)
1351 TestChangeNativeViewHierarchy test(this); 1351 TestChangeNativeViewHierarchy test(this);
1352 test.CheckChangingHierarhy(); 1352 test.CheckChangingHierarhy();
1353 #endif 1353 #endif
1354 } 1354 }
OLDNEW
« no previous file with comments | « views/focus/focus_manager_unittest.cc ('k') | views/widget/root_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698