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

Side by Side Diff: ui/views/view_unittest.cc

Issue 108063004: Give up focus if the focused view becomes unfocusable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Made View::IsFocusable() non-virtual Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 <map> 5 #include <map>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/rand_util.h" 8 #include "base/rand_util.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 2624 matching lines...) Expand 10 before | Expand all | Expand 10 after
2635 // Check that calling |AddChildView()| does not change the order. 2635 // Check that calling |AddChildView()| does not change the order.
2636 v1.AddChildView(&v2); 2636 v1.AddChildView(&v2);
2637 EXPECT_EQ(0, v1.GetIndexOf(&v2)); 2637 EXPECT_EQ(0, v1.GetIndexOf(&v2));
2638 EXPECT_EQ(1, v1.GetIndexOf(&v3)); 2638 EXPECT_EQ(1, v1.GetIndexOf(&v3));
2639 v1.AddChildView(&v3); 2639 v1.AddChildView(&v3);
2640 EXPECT_EQ(0, v1.GetIndexOf(&v2)); 2640 EXPECT_EQ(0, v1.GetIndexOf(&v2));
2641 EXPECT_EQ(1, v1.GetIndexOf(&v3)); 2641 EXPECT_EQ(1, v1.GetIndexOf(&v3));
2642 } 2642 }
2643 2643
2644 //////////////////////////////////////////////////////////////////////////////// 2644 ////////////////////////////////////////////////////////////////////////////////
2645 // FocusManager
2646 ////////////////////////////////////////////////////////////////////////////////
2647
2648 // A widget that always claims to be active, regardless of its real activation
2649 // status.
2650 class ActiveWidget : public Widget {
2651 public:
2652 ActiveWidget() {}
2653 virtual ~ActiveWidget() {}
2654
2655 virtual bool IsActive() const OVERRIDE {
2656 return true;
2657 }
2658
2659 private:
2660 DISALLOW_COPY_AND_ASSIGN(ActiveWidget);
2661 };
2662
2663 TEST_F(ViewTest, AdvanceFocusIfNecessaryForUnfocusableView) {
2664 // Create a widget with two views and give the first one focus.
2665 ActiveWidget widget;
2666 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
2667 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
2668 widget.Init(params);
2669
2670 View* view1 = new View();
2671 view1->SetFocusable(true);
2672 widget.GetRootView()->AddChildView(view1);
2673 View* view2 = new View();
2674 view2->SetFocusable(true);
2675 widget.GetRootView()->AddChildView(view2);
2676
2677 FocusManager* focus_manager = widget.GetFocusManager();
2678 ASSERT_TRUE(focus_manager);
2679
2680 focus_manager->SetFocusedView(view1);
2681 EXPECT_EQ(view1, focus_manager->GetFocusedView());
2682
2683 // Disable the focused view and check if the next view gets focused.
2684 view1->SetEnabled(false);
2685 EXPECT_EQ(view2, focus_manager->GetFocusedView());
2686
2687 // Re-enable and re-focus.
2688 view1->SetEnabled(true);
2689 focus_manager->SetFocusedView(view1);
2690 EXPECT_EQ(view1, focus_manager->GetFocusedView());
2691
2692 // Hide the focused view and check it the next view gets focused.
2693 view1->SetVisible(false);
2694 EXPECT_EQ(view2, focus_manager->GetFocusedView());
2695
2696 // Re-show and re-focus.
2697 view1->SetVisible(true);
2698 focus_manager->SetFocusedView(view1);
2699 EXPECT_EQ(view1, focus_manager->GetFocusedView());
2700
2701 // Set the focused view as not focusable and check if the next view gets
2702 // focused.
2703 view1->SetFocusable(false);
2704 EXPECT_EQ(view2, focus_manager->GetFocusedView());
2705 }
2706
2707 ////////////////////////////////////////////////////////////////////////////////
2645 // Layers 2708 // Layers
2646 //////////////////////////////////////////////////////////////////////////////// 2709 ////////////////////////////////////////////////////////////////////////////////
2647 2710
2648 namespace { 2711 namespace {
2649 2712
2650 // Test implementation of LayerAnimator. 2713 // Test implementation of LayerAnimator.
2651 class TestLayerAnimator : public ui::LayerAnimator { 2714 class TestLayerAnimator : public ui::LayerAnimator {
2652 public: 2715 public:
2653 TestLayerAnimator(); 2716 TestLayerAnimator();
2654 2717
(...skipping 980 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 // notification. 3698 // notification.
3636 TestView* test_view_child_2 = new TestView(); 3699 TestView* test_view_child_2 = new TestView();
3637 test_view->AddChildView(test_view_child_2); 3700 test_view->AddChildView(test_view_child_2);
3638 EXPECT_TRUE(test_view_child_2->native_theme_); 3701 EXPECT_TRUE(test_view_child_2->native_theme_);
3639 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); 3702 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_);
3640 3703
3641 widget->CloseNow(); 3704 widget->CloseNow();
3642 } 3705 }
3643 3706
3644 } // namespace views 3707 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698