| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/scoped_nsobject.h" | 5 #include "base/scoped_nsobject.h" |
| 6 #import "chrome/browser/cocoa/bookmark_item.h" | 6 #import "chrome/browser/cocoa/bookmark_item.h" |
| 7 #import "chrome/browser/cocoa/bookmark_manager_controller.h" | 7 #import "chrome/browser/cocoa/bookmark_manager_controller.h" |
| 8 #import "chrome/browser/cocoa/bookmark_tree_controller.h" | 8 #import "chrome/browser/cocoa/bookmark_tree_controller.h" |
| 9 #include "chrome/browser/cocoa/browser_test_helper.h" | 9 #include "chrome/browser/cocoa/browser_test_helper.h" |
| 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 } | 35 } |
| 36 | 36 |
| 37 NSSet* AddFixtureItems() { | 37 NSSet* AddFixtureItems() { |
| 38 return [NSSet setWithObjects: | 38 return [NSSet setWithObjects: |
| 39 AddToBar(@"Google", @"http://google.com"), | 39 AddToBar(@"Google", @"http://google.com"), |
| 40 AddToBar(@"GMail", @"http://gmail.com"), | 40 AddToBar(@"GMail", @"http://gmail.com"), |
| 41 AddToBar(@"Google Sites", @"http://sites.google.com"), | 41 AddToBar(@"Google Sites", @"http://sites.google.com"), |
| 42 nil]; | 42 nil]; |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool SearchResultsVisible() { |
| 46 NSOutlineView* outline = [[controller_ groupsController] outline]; |
| 47 return [outline rowForItem:[controller_ searchGroup]] >= 0; |
| 48 } |
| 49 |
| 45 BrowserTestHelper browser_test_helper_; | 50 BrowserTestHelper browser_test_helper_; |
| 46 BookmarkManagerController* controller_; | 51 BookmarkManagerController* controller_; |
| 47 }; | 52 }; |
| 48 | 53 |
| 49 TEST_F(BookmarkManagerControllerTest, IsThisThingTurnedOn) { | 54 TEST_F(BookmarkManagerControllerTest, IsThisThingTurnedOn) { |
| 50 NSWindow* w = [controller_ window]; | 55 NSWindow* w = [controller_ window]; |
| 51 ASSERT_TRUE(w); | 56 ASSERT_TRUE(w); |
| 52 EXPECT_TRUE([w isVisible]); | 57 EXPECT_TRUE([w isVisible]); |
| 53 | 58 |
| 54 ASSERT_TRUE([controller_ groupsController]); | 59 ASSERT_TRUE([controller_ groupsController]); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 [controller_ setSearchString:@"google"]; | 118 [controller_ setSearchString:@"google"]; |
| 114 shown = [search children]; | 119 shown = [search children]; |
| 115 EXPECT_EQ(2U, [shown count]); | 120 EXPECT_EQ(2U, [shown count]); |
| 116 | 121 |
| 117 // Search for 'fnord': | 122 // Search for 'fnord': |
| 118 [controller_ setSearchString:@"fnord"]; | 123 [controller_ setSearchString:@"fnord"]; |
| 119 shown = [search children]; | 124 shown = [search children]; |
| 120 EXPECT_EQ(0U, [shown count]); | 125 EXPECT_EQ(0U, [shown count]); |
| 121 } | 126 } |
| 122 | 127 |
| 128 TEST_F(BookmarkManagerControllerTest, SearchSelection) { |
| 129 BookmarkTreeController* groupsController = [controller_ groupsController]; |
| 130 AddFixtureItems(); |
| 131 BookmarkItem* originalSelection = [controller_ bookmarkBarItem]; |
| 132 EXPECT_FALSE(SearchResultsVisible()); |
| 133 EXPECT_EQ(originalSelection, [groupsController selectedItem]); |
| 134 |
| 135 // Start a search and verify the search results group is selected. |
| 136 [controller_ setSearchString:@"g"]; |
| 137 EXPECT_TRUE(SearchResultsVisible()); |
| 138 EXPECT_EQ([controller_ searchGroup], [groupsController selectedItem]); |
| 139 |
| 140 // Type some more, see if updating the search string works. |
| 141 [controller_ setSearchString:@"gmail"]; |
| 142 EXPECT_TRUE(SearchResultsVisible()); |
| 143 EXPECT_EQ([controller_ searchGroup], [groupsController selectedItem]); |
| 144 |
| 145 // Clear search, verify search results are hidden and original sel restored. |
| 146 [controller_ setSearchString:@""]; |
| 147 EXPECT_FALSE(SearchResultsVisible()); |
| 148 EXPECT_EQ(originalSelection, [groupsController selectedItem]); |
| 149 |
| 150 // Now search, then change the selection, then clear search: |
| 151 [controller_ setSearchString:@"gmail"]; |
| 152 EXPECT_TRUE(SearchResultsVisible()); |
| 153 EXPECT_EQ([controller_ searchGroup], [groupsController selectedItem]); |
| 154 BookmarkItem* newerSelection = [controller_ otherBookmarksItem]; |
| 155 [controller_ showGroup:newerSelection]; |
| 156 [controller_ setSearchString:@""]; |
| 157 EXPECT_FALSE(SearchResultsVisible()); |
| 158 EXPECT_EQ(newerSelection, [groupsController selectedItem]); |
| 159 } |
| 160 |
| 123 } // namespace | 161 } // namespace |
| OLD | NEW |