Index: chrome/browser/bookmarks/bookmark_utils_unittest.cc |
diff --git a/chrome/browser/bookmarks/bookmark_utils_unittest.cc b/chrome/browser/bookmarks/bookmark_utils_unittest.cc |
index 0bb86b76b78fbe68e5a0ff91bfa20be51affa630..ab85a43dad36f604b23e87baf6852202368d5d17 100644 |
--- a/chrome/browser/bookmarks/bookmark_utils_unittest.cc |
+++ b/chrome/browser/bookmarks/bookmark_utils_unittest.cc |
@@ -8,6 +8,7 @@ |
#include "base/message_loop/message_loop.h" |
#include "base/strings/utf_string_conversions.h" |
+#include "chrome/browser/bookmarks/base_bookmark_model_observer.h" |
#include "chrome/browser/bookmarks/bookmark_model.h" |
#include "chrome/browser/bookmarks/bookmark_node_data.h" |
#include "testing/gtest/include/gtest/gtest.h" |
@@ -20,16 +21,38 @@ using std::string; |
namespace bookmark_utils { |
namespace { |
-class BookmarkUtilsTest : public ::testing::Test { |
+class BookmarkUtilsTest : public testing::Test, |
+ public BaseBookmarkModelObserver { |
public: |
- BookmarkUtilsTest() {} |
+ BookmarkUtilsTest() |
+ : grouped_changes_beginning_count_(0), grouped_changes_ended_count_(0) {} |
virtual ~BookmarkUtilsTest() {} |
virtual void TearDown() OVERRIDE { |
ui::Clipboard::DestroyClipboardForCurrentThread(); |
} |
+ void ExpectGroupedChangeCount(int expected_beginning_count, |
+ int expected_ended_count) { |
+ EXPECT_EQ(grouped_changes_beginning_count_, expected_beginning_count); |
+ EXPECT_EQ(grouped_changes_ended_count_, expected_ended_count); |
+ } |
+ |
+ // BaseBookmarkModelObserver: |
+ virtual void BookmarkModelChanged() OVERRIDE {} |
+ |
+ virtual void GroupedBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE { |
+ ++grouped_changes_beginning_count_; |
+ } |
+ |
+ virtual void GroupedBookmarkChangesEnded(BookmarkModel* model) OVERRIDE { |
+ ++grouped_changes_ended_count_; |
+ } |
+ |
private: |
+ int grouped_changes_beginning_count_; |
+ int grouped_changes_ended_count_; |
+ |
// Clipboard requires a message loop. |
base::MessageLoopForUI loop_; |
@@ -242,6 +265,33 @@ TEST_F(BookmarkUtilsTest, CopyPaste) { |
EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node())); |
} |
+TEST_F(BookmarkUtilsTest, CutToClipboard) { |
+ BookmarkModel model(NULL); |
+ model.AddObserver(this); |
+ |
+ base::string16 title(ASCIIToUTF16("foo")); |
+ GURL url("http://foo.com"); |
+ const BookmarkNode* n1 = model.AddURL(model.other_node(), 0, title, url); |
+ const BookmarkNode* n2 = model.AddURL(model.other_node(), 1, title, url); |
+ |
+ // Cut the nodes to the clipboard. |
+ std::vector<const BookmarkNode*> nodes; |
+ nodes.push_back(n1); |
+ nodes.push_back(n2); |
+ CopyToClipboard(&model, nodes, true); |
+ |
+ // Make sure the nodes were removed. |
+ EXPECT_EQ(0, model.other_node()->child_count()); |
+ |
+#if !defined(OS_ANDROID) |
+ // Make sure observers were notified the set of changes should be grouped. |
+ ExpectGroupedChangeCount(1, 1); |
+#endif |
+ |
+ // And make sure we can paste from the clipboard. |
+ EXPECT_TRUE(CanPasteFromClipboard(model.other_node())); |
+} |
+ |
TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { |
BookmarkModel model(NULL); |
// This tests the case where selection contains one item and that item is a |