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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller_unittest.mm
diff --git a/ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller_unittest.mm b/ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..652d18d3ac0752337d614fe99fd100002ee6868a
--- /dev/null
+++ b/ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller_unittest.mm
@@ -0,0 +1,89 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/mac/scoped_nsobject.h"
+#include "components/bookmarks/browser/bookmark_model.h"
+#include "components/sync_preferences/testing_pref_service_syncable.h"
+#import "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
+#import "ios/chrome/browser/ui/bookmarks/bookmark_home_handset_view_controller.h"
+#include "ios/chrome/browser/ui/bookmarks/bookmark_ios_unittest.h"
+#import "ios/chrome/browser/ui/bookmarks/bookmark_promo_controller.h"
+#import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
+
+using bookmarks::BookmarkNode;
+
+// A partial mock subclass that doesn't load any heavy weight subclasses.
+@interface MockBookmarkHomeHandsetViewController
+ : BookmarkHomeHandsetViewController
+@end
+
+@implementation MockBookmarkHomeHandsetViewController
+
+- (void)hideEditingBarAnimated:(BOOL)animated {
+ // Do nothing.
+ // The animation would delay the release of the
+ // BookmarkHomeHandsetViewController and make the test fail by keeping
+ // the view controller alive after the test is shutdown leading
+ // to DCHECK failure on the sign in manager.
+}
+
+- (void)ensureAllViewExists {
+ // Do nothing.
+}
+- (void)loadImageService {
+ // Do nothing.
+}
+@end
+
+namespace {
+
+class BookmarkHomeViewControllerTest : public BookmarkIOSUnitTest {
+ public:
+ void SetUp() override {
+ BookmarkIOSUnitTest::SetUp();
+ sync_preferences::TestingPrefServiceSyncable* pref =
+ chrome_browser_state_->GetTestingPrefService();
+ [BookmarkPromoController registerBrowserStatePrefs:pref->registry()];
+ }
+};
+
+TEST_F(BookmarkHomeViewControllerTest, DeleteNodesUpdatesEditNodes) {
+ const BookmarkNode* mobileNode = _bookmarkModel->mobile_node();
+ const BookmarkNode* f1 = AddFolder(mobileNode, @"f1");
+ const BookmarkNode* a = AddBookmark(mobileNode, @"a");
+ const BookmarkNode* b = AddBookmark(mobileNode, @"b");
+ const BookmarkNode* f2 = AddFolder(mobileNode, @"f2");
+
+ const BookmarkNode* f1a = AddBookmark(f1, @"f1a");
+ AddBookmark(f1, @"f1b");
+ AddBookmark(f1, @"f1c");
+ const BookmarkNode* f2a = AddBookmark(f2, @"f2a");
+ AddBookmark(f2, @"f2b");
+
+ std::set<const BookmarkNode*> toDelete;
+ toDelete.insert(b);
+ toDelete.insert(f1a);
+ toDelete.insert(f1);
+ toDelete.insert(f2a);
+
+ base::scoped_nsobject<MockBookmarkHomeHandsetViewController> controller(
+ [[MockBookmarkHomeHandsetViewController alloc]
+ initWithLoader:nil
+ browserState:chrome_browser_state_.get()]);
+
+ [controller resetEditNodes];
+ [controller insertEditNode:f1 atIndexPath:nil];
+ [controller insertEditNode:a atIndexPath:nil];
+ [controller insertEditNode:f2 atIndexPath:nil];
+
+ bookmark_utils_ios::DeleteBookmarks(toDelete, _bookmarkModel);
+
+ // After the deletion, only 'a' and 'f2' should be left.
+ std::set<const BookmarkNode*> editingNodes = [controller editNodes];
+ EXPECT_EQ(editingNodes.size(), 2u);
+ EXPECT_TRUE(editingNodes.find(a) != editingNodes.end());
+ EXPECT_TRUE(editingNodes.find(f2) != editingNodes.end());
+}
+
+} // anonymous namespace

Powered by Google App Engine
This is Rietveld 408576698