OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/bookmarks/browser/bookmark_model.h" | |
6 #import "ios/chrome/browser/browser_state/test_chrome_browser_state.h" | |
7 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_handset_view_controller.h
" | |
8 #include "ios/chrome/browser/ui/bookmarks/bookmark_ios_unittest.h" | |
9 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h" | |
10 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | |
11 | |
12 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
13 #error "This file requires ARC support." | |
14 #endif | |
15 | |
16 using bookmarks::BookmarkNode; | |
17 | |
18 // A partial mock subclass that doesn't load any heavy weight subclasses. | |
19 @interface MockBookmarkHomeHandsetViewController | |
20 : BookmarkHomeHandsetViewController | |
21 @end | |
22 | |
23 @implementation MockBookmarkHomeHandsetViewController | |
24 | |
25 - (void)hideEditingBarAnimated:(BOOL)animated { | |
26 // Do nothing. | |
27 // The animation would delay the release of the | |
28 // BookmarkHomeHandsetViewController and make the test fail by keeping | |
29 // the view controller alive after the test is shutdown leading | |
30 // to DCHECK failure on the sign in manager. | |
31 } | |
32 | |
33 - (void)ensureAllViewExists { | |
34 // Do nothing. | |
35 } | |
36 - (void)loadImageService { | |
37 // Do nothing. | |
38 } | |
39 @end | |
40 | |
41 namespace { | |
42 | |
43 using BookmarkHomeViewControllerTest = BookmarkIOSUnitTest; | |
44 | |
45 TEST_F(BookmarkHomeViewControllerTest, DeleteNodesUpdatesEditNodes) { | |
46 @autoreleasepool { | |
47 const BookmarkNode* mobileNode = _bookmarkModel->mobile_node(); | |
48 const BookmarkNode* f1 = AddFolder(mobileNode, @"f1"); | |
49 const BookmarkNode* a = AddBookmark(mobileNode, @"a"); | |
50 const BookmarkNode* b = AddBookmark(mobileNode, @"b"); | |
51 const BookmarkNode* f2 = AddFolder(mobileNode, @"f2"); | |
52 | |
53 const BookmarkNode* f1a = AddBookmark(f1, @"f1a"); | |
54 AddBookmark(f1, @"f1b"); | |
55 AddBookmark(f1, @"f1c"); | |
56 const BookmarkNode* f2a = AddBookmark(f2, @"f2a"); | |
57 AddBookmark(f2, @"f2b"); | |
58 | |
59 std::set<const BookmarkNode*> toDelete; | |
60 toDelete.insert(b); | |
61 toDelete.insert(f1a); | |
62 toDelete.insert(f1); | |
63 toDelete.insert(f2a); | |
64 | |
65 MockBookmarkHomeHandsetViewController* controller = | |
66 [[MockBookmarkHomeHandsetViewController alloc] | |
67 initWithLoader:nil | |
68 browserState:chrome_browser_state_.get()]; | |
69 | |
70 [controller resetEditNodes]; | |
71 [controller insertEditNode:f1 atIndexPath:nil]; | |
72 [controller insertEditNode:a atIndexPath:nil]; | |
73 [controller insertEditNode:f2 atIndexPath:nil]; | |
74 | |
75 bookmark_utils_ios::DeleteBookmarks(toDelete, _bookmarkModel); | |
76 | |
77 // After the deletion, only 'a' and 'f2' should be left. | |
78 std::set<const BookmarkNode*> editingNodes = [controller editNodes]; | |
79 EXPECT_EQ(editingNodes.size(), 2u); | |
80 EXPECT_TRUE(editingNodes.find(a) != editingNodes.end()); | |
81 EXPECT_TRUE(editingNodes.find(f2) != editingNodes.end()); | |
82 } | |
83 } | |
84 | |
85 } // anonymous namespace | |
OLD | NEW |