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

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller_unittest.mm

Issue 2586993002: Upstream Chrome on iOS source code [3/11]. (Closed)
Patch Set: Created 4 years 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
OLDNEW
(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 "base/mac/scoped_nsobject.h"
6 #include "components/bookmarks/browser/bookmark_model.h"
7 #include "components/sync_preferences/testing_pref_service_syncable.h"
8 #import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
9 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_handset_view_controller.h "
10 #include "ios/chrome/browser/ui/bookmarks/bookmark_ios_unittest.h"
11 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h"
12 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
13
14 using bookmarks::BookmarkNode;
15
16 // A partial mock subclass that doesn't load any heavy weight subclasses.
17 @interface MockBookmarkHomeHandsetViewController
18 : BookmarkHomeHandsetViewController
19 @end
20
21 @implementation MockBookmarkHomeHandsetViewController
22
23 - (void)hideEditingBarAnimated:(BOOL)animated {
24 // Do nothing.
25 // The animation would delay the release of the
26 // BookmarkHomeHandsetViewController and make the test fail by keeping
27 // the view controller alive after the test is shutdown leading
28 // to DCHECK failure on the sign in manager.
29 }
30
31 - (void)ensureAllViewExists {
32 // Do nothing.
33 }
34 - (void)loadImageService {
35 // Do nothing.
36 }
37 @end
38
39 namespace {
40
41 class BookmarkHomeViewControllerTest : public BookmarkIOSUnitTest {
42 public:
43 void SetUp() override {
44 BookmarkIOSUnitTest::SetUp();
45 sync_preferences::TestingPrefServiceSyncable* pref =
46 chrome_browser_state_->GetTestingPrefService();
47 [BookmarkPromoController registerBrowserStatePrefs:pref->registry()];
48 }
49 };
50
51 TEST_F(BookmarkHomeViewControllerTest, DeleteNodesUpdatesEditNodes) {
52 const BookmarkNode* mobileNode = _bookmarkModel->mobile_node();
53 const BookmarkNode* f1 = AddFolder(mobileNode, @"f1");
54 const BookmarkNode* a = AddBookmark(mobileNode, @"a");
55 const BookmarkNode* b = AddBookmark(mobileNode, @"b");
56 const BookmarkNode* f2 = AddFolder(mobileNode, @"f2");
57
58 const BookmarkNode* f1a = AddBookmark(f1, @"f1a");
59 AddBookmark(f1, @"f1b");
60 AddBookmark(f1, @"f1c");
61 const BookmarkNode* f2a = AddBookmark(f2, @"f2a");
62 AddBookmark(f2, @"f2b");
63
64 std::set<const BookmarkNode*> toDelete;
65 toDelete.insert(b);
66 toDelete.insert(f1a);
67 toDelete.insert(f1);
68 toDelete.insert(f2a);
69
70 base::scoped_nsobject<MockBookmarkHomeHandsetViewController> controller(
71 [[MockBookmarkHomeHandsetViewController alloc]
72 initWithLoader:nil
73 browserState:chrome_browser_state_.get()]);
74
75 [controller resetEditNodes];
76 [controller insertEditNode:f1 atIndexPath:nil];
77 [controller insertEditNode:a atIndexPath:nil];
78 [controller insertEditNode:f2 atIndexPath:nil];
79
80 bookmark_utils_ios::DeleteBookmarks(toDelete, _bookmarkModel);
81
82 // After the deletion, only 'a' and 'f2' should be left.
83 std::set<const BookmarkNode*> editingNodes = [controller editNodes];
84 EXPECT_EQ(editingNodes.size(), 2u);
85 EXPECT_TRUE(editingNodes.find(a) != editingNodes.end());
86 EXPECT_TRUE(editingNodes.find(f2) != editingNodes.end());
87 }
88
89 } // anonymous namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698