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

Side by Side Diff: chrome/browser/bookmarks/bookmark_utils_unittest.cc

Issue 155913004: Eliminate Bookmarks dependence to bookmark_undo_utils.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: All grouped action to notify BookmarkModelObservers Created 6 years, 10 months 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/bookmarks/bookmark_utils.h" 5 #include "chrome/browser/bookmarks/bookmark_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
11 #include "chrome/browser/bookmarks/bookmark_model.h" 12 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/bookmarks/bookmark_node_data.h" 13 #include "chrome/browser/bookmarks/bookmark_node_data.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/base/clipboard/clipboard.h" 15 #include "ui/base/clipboard/clipboard.h"
15 #include "ui/base/clipboard/scoped_clipboard_writer.h" 16 #include "ui/base/clipboard/scoped_clipboard_writer.h"
16 17
17 using base::ASCIIToUTF16; 18 using base::ASCIIToUTF16;
18 using std::string; 19 using std::string;
19 20
20 namespace bookmark_utils { 21 namespace bookmark_utils {
21 namespace { 22 namespace {
22 23
23 class BookmarkUtilsTest : public ::testing::Test { 24 class BookmarkUtilsTest : public ::testing::Test,
24 public: 25 public BaseBookmarkModelObserver {
26 public:
tfarina 2014/02/21 18:46:47 please, sync your checkout. also, please, run cla
Tom Cassiotis 2014/02/22 04:29:35 Done.
27 BookmarkUtilsTest() {
28 ClearCounts();
29 }
30
25 virtual void TearDown() OVERRIDE { 31 virtual void TearDown() OVERRIDE {
26 ui::Clipboard::DestroyClipboardForCurrentThread(); 32 ui::Clipboard::DestroyClipboardForCurrentThread();
27 } 33 }
28 34
35 void ClearCounts() {
36 grouped_changes_beginning_count_ = grouped_changes_ended_count_ = 0;
37 }
38
39 void AssertGroupedChangesObserverCount(int expected_beginning_count,
sky 2014/02/06 17:48:27 ExpectedGroupChanges...
Tom Cassiotis 2014/02/21 17:51:45 Added 'Assert' so it come out as AssertExpectedGro
tfarina 2014/02/21 18:46:47 I'd say Scott suggested Expected* because this met
Tom Cassiotis 2014/02/22 04:29:35 Sorry for the misunderstanding. Done.
40 int expected_ended_count) {
41 EXPECT_EQ(grouped_changes_beginning_count_, expected_beginning_count);
42 EXPECT_EQ(grouped_changes_ended_count_, expected_ended_count);
43 }
44
45 // BookmarkModelObserver:
46 virtual void BookmarkModelChanged() OVERRIDE {}
47
48 virtual void GroupedBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE {
49 ++grouped_changes_beginning_count_;
50 }
51
52 virtual void GroupedBookmarkChangesEnded(BookmarkModel* model) OVERRIDE {
53 ++grouped_changes_ended_count_;
54 }
55
29 private: 56 private:
57 int grouped_changes_beginning_count_;
58 int grouped_changes_ended_count_;
59
30 // Clipboard requires a message loop. 60 // Clipboard requires a message loop.
31 base::MessageLoopForUI loop; 61 base::MessageLoopForUI loop;
32 }; 62 };
33 63
34 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { 64 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) {
35 BookmarkModel model(NULL); 65 BookmarkModel model(NULL);
36 const BookmarkNode* node1 = model.AddURL(model.other_node(), 66 const BookmarkNode* node1 = model.AddURL(model.other_node(),
37 0, 67 0,
38 ASCIIToUTF16("foo bar"), 68 ASCIIToUTF16("foo bar"),
39 GURL("http://www.google.com")); 69 GURL("http://www.google.com"));
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 ui::ScopedClipboardWriter clipboard_writer( 265 ui::ScopedClipboardWriter clipboard_writer(
236 ui::Clipboard::GetForCurrentThread(), 266 ui::Clipboard::GetForCurrentThread(),
237 ui::CLIPBOARD_TYPE_COPY_PASTE); 267 ui::CLIPBOARD_TYPE_COPY_PASTE);
238 clipboard_writer.WriteText(ASCIIToUTF16("foo")); 268 clipboard_writer.WriteText(ASCIIToUTF16("foo"));
239 } 269 }
240 270
241 // Now we shouldn't be able to paste from the clipboard. 271 // Now we shouldn't be able to paste from the clipboard.
242 EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node())); 272 EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node()));
243 } 273 }
244 274
275 TEST_F(BookmarkUtilsTest, CutToClipboard) {
276 BookmarkModel model(NULL);
277 model.AddObserver(this);
278 base::string16 title(ASCIIToUTF16("foo"));
279 GURL url("http://foo.com");
280 const BookmarkNode* n1 = model.AddURL(model.other_node(), 0, title, url);
281 const BookmarkNode* n2 = model.AddURL(model.other_node(), 1, title, url);
282 ClearCounts();
tfarina 2014/02/21 18:46:47 I doubt you need this here. Because the test fixtu
Tom Cassiotis 2014/02/22 04:29:35 You are right. Done.
283
284 // Cut the nodes to the clipboard.
285 std::vector<const BookmarkNode*> nodes;
286 nodes.push_back(n1);
287 nodes.push_back(n2);
288 CopyToClipboard(&model, nodes, true);
289
290 // Make sure the nodes were removed.
291 EXPECT_EQ(0, model.other_node()->child_count());
292
293 // Make sure observers were notified the set of changes should be grouped.
294 AssertGroupedChangesObserverCount(1, 1);
295
296 // And make sure we can paste from the clipboard.
297 EXPECT_TRUE(CanPasteFromClipboard(model.bookmark_bar_node()));
tfarina 2014/02/21 18:46:47 this could be other_node() as well, no?
Tom Cassiotis 2014/02/22 04:29:35 This function simply checks whether we can paste i
298
tfarina 2014/02/21 18:46:47 remove this empty line;
Tom Cassiotis 2014/02/22 04:29:35 Done.
299 }
300
245 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { 301 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) {
246 BookmarkModel model(NULL); 302 BookmarkModel model(NULL);
247 // This tests the case where selection contains one item and that item is a 303 // This tests the case where selection contains one item and that item is a
248 // folder. 304 // folder.
249 std::vector<const BookmarkNode*> nodes; 305 std::vector<const BookmarkNode*> nodes;
250 nodes.push_back(model.bookmark_bar_node()); 306 nodes.push_back(model.bookmark_bar_node());
251 int index = -1; 307 int index = -1;
252 const BookmarkNode* real_parent = GetParentForNewNodes( 308 const BookmarkNode* real_parent = GetParentForNewNodes(
253 model.bookmark_bar_node(), nodes, &index); 309 model.bookmark_bar_node(), nodes, &index);
254 EXPECT_EQ(real_parent, model.bookmark_bar_node()); 310 EXPECT_EQ(real_parent, model.bookmark_bar_node());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size()); 364 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size());
309 std::string value; 365 std::string value;
310 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value)); 366 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value));
311 EXPECT_EQ("somevalue", value); 367 EXPECT_EQ("somevalue", value);
312 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value)); 368 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value));
313 EXPECT_EQ("someothervalue", value); 369 EXPECT_EQ("someothervalue", value);
314 } 370 }
315 371
316 } // namespace 372 } // namespace
317 } // namespace bookmark_utils 373 } // namespace bookmark_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698