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 "ui/views/focus/focus_manager.h" | 5 #include "ui/views/focus/focus_manager.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/base/models/combobox_model.h" | 10 #include "ui/base/models/combobox_model.h" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 // Link * kAmelieLinkID | 252 // Link * kAmelieLinkID |
253 // Link * kJoyeuxNoelLinkID | 253 // Link * kJoyeuxNoelLinkID |
254 // Link * kCampingLinkID | 254 // Link * kCampingLinkID |
255 // Link * kBriceDeNiceLinkID | 255 // Link * kBriceDeNiceLinkID |
256 // Link * kTaxiLinkID | 256 // Link * kTaxiLinkID |
257 // Link * kAsterixLinkID | 257 // Link * kAsterixLinkID |
258 // NativeButton * kOKButtonID | 258 // NativeButton * kOKButtonID |
259 // NativeButton * kCancelButtonID | 259 // NativeButton * kCancelButtonID |
260 // NativeButton * kHelpButtonID | 260 // NativeButton * kHelpButtonID |
261 // TabbedPane * kStyleContainerID | 261 // TabbedPane * kStyleContainerID |
262 // TabStrip | |
263 // Tab ("Style") | |
264 // Tab ("Other") | |
262 // View | 265 // View |
263 // Checkbox * kBoldCheckBoxID | 266 // View |
264 // Checkbox * kItalicCheckBoxID | 267 // Checkbox * kBoldCheckBoxID |
265 // Checkbox * kUnderlinedCheckBoxID | 268 // Checkbox * kItalicCheckBoxID |
266 // Link * kStyleHelpLinkID | 269 // Checkbox * kUnderlinedCheckBoxID |
267 // Textfield * kStyleTextEditID | 270 // Link * kStyleHelpLinkID |
268 // Other | 271 // Textfield * kStyleTextEditID |
272 // View | |
269 // BorderView kSearchContainerID | 273 // BorderView kSearchContainerID |
270 // View | 274 // View |
271 // Textfield * kSearchTextfieldID | 275 // Textfield * kSearchTextfieldID |
272 // NativeButton * kSearchButtonID | 276 // NativeButton * kSearchButtonID |
273 // Link * kHelpLinkID | 277 // Link * kHelpLinkID |
274 // View * kThumbnailContainerID | 278 // View * kThumbnailContainerID |
275 // NativeButton * kThumbnailStarID | 279 // NativeButton * kThumbnailStarID |
276 // NativeButton * kThumbnailSuperStarID | 280 // NativeButton * kThumbnailSuperStarID |
277 | 281 |
278 GetContentsView()->set_background( | 282 GetContentsView()->set_background( |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 for (int j = arraysize(kRightTraversalIDs) - 1; j >= 0; --j) { | 767 for (int j = arraysize(kRightTraversalIDs) - 1; j >= 0; --j) { |
764 GetFocusManager()->AdvanceFocus(true); | 768 GetFocusManager()->AdvanceFocus(true); |
765 View* focused_view = GetFocusManager()->GetFocusedView(); | 769 View* focused_view = GetFocusManager()->GetFocusedView(); |
766 EXPECT_TRUE(focused_view != NULL); | 770 EXPECT_TRUE(focused_view != NULL); |
767 if (focused_view) | 771 if (focused_view) |
768 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); | 772 EXPECT_EQ(kRightTraversalIDs[j], focused_view->id()); |
769 } | 773 } |
770 } | 774 } |
771 } | 775 } |
772 | 776 |
777 class FocusTraversalNonFocusableTest : public FocusManagerTest { | |
778 public: | |
779 ~FocusTraversalNonFocusableTest() override {} | |
780 | |
781 void InitContentView() override; | |
782 | |
783 protected: | |
784 FocusTraversalNonFocusableTest() {} | |
785 | |
786 private: | |
787 DISALLOW_COPY_AND_ASSIGN(FocusTraversalNonFocusableTest); | |
788 }; | |
789 | |
790 void FocusTraversalNonFocusableTest::InitContentView() { | |
dmazzoni
2015/02/02 22:07:04
Just to clarify, is your intent that this test wou
Matt Giuca
2015/02/02 23:17:31
Yes, that is the behaviour of the test prior to th
| |
791 // Create a complex nested view hierarchy with no focusable views. This is a | |
792 // regression test for http://crbug.com/453699. There was previously a bug | |
793 // where advancing focus backwards through this tree resulted in an | |
794 // exponential number of nodes being searched. (Each time it traverses one of | |
795 // the x1-x3-x2 triangles, it will traverse the left sibling of x1, (x+1)0, | |
796 // twice, which means it will visit O(2^n) nodes.) | |
797 // | |
798 // 0 | |
799 // / \ | |
800 // / \ | |
801 // 10 1 | |
802 // / \ / \ | |
803 // / \ / \ | |
804 // 20 11 2 3 | |
805 // / \ / \ | |
806 // / \ / \ | |
807 // ... 21 12 13 | |
808 // / \ | |
809 // / \ | |
810 // 22 23 | |
811 | |
812 View* v = GetContentsView(); | |
813 // Create 30 groups of 4 nodes. |v| is the top of each group. | |
814 for (int i = 0; i < 300; i += 10) { | |
815 // |v|'s left child is the top of the next group. If |v| is 20, this is 30. | |
816 View* v10 = new View; | |
817 v10->set_id(i + 10); | |
818 v->AddChildView(v10); | |
819 | |
820 // |v|'s right child. If |v| is 20, this is 21. | |
821 View* v1 = new View; | |
822 v1->set_id(i + 1); | |
823 v->AddChildView(v1); | |
824 | |
825 // |v|'s right child has two children. If |v| is 20, these are 22 and 23. | |
826 View* v2 = new View; | |
827 v2->set_id(i + 2); | |
828 View* v3 = new View; | |
829 v3->set_id(i + 3); | |
830 v1->AddChildView(v2); | |
831 v1->AddChildView(v3); | |
832 | |
833 v = v10; | |
834 } | |
835 } | |
836 | |
837 // See explanation in InitContentView. | |
838 TEST_F(FocusTraversalNonFocusableTest, PathologicalSiblingTraversal) { | |
839 // Advance forwards from the root node. | |
840 GetFocusManager()->ClearFocus(); | |
841 GetFocusManager()->AdvanceFocus(false); | |
842 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); | |
843 | |
844 // Advance backwards from the root node. | |
845 GetFocusManager()->ClearFocus(); | |
846 GetFocusManager()->AdvanceFocus(true); | |
847 EXPECT_FALSE(GetFocusManager()->GetFocusedView()); | |
848 } | |
849 | |
773 } // namespace views | 850 } // namespace views |
OLD | NEW |