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

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: 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,
25 public BaseBookmarkModelObserver {
24 public: 26 public:
25 BookmarkUtilsTest() {} 27 BookmarkUtilsTest()
26 virtual ~BookmarkUtilsTest() {} 28 : grouped_changes_beginning_count_(0), grouped_changes_ended_count_(0) {}
27 29
tfarina 2014/02/22 15:09:30 where is my virtual destructor? Looks like you rem
Tom Cassiotis 2014/02/22 20:54:02 I made a mistake resolving the conflict. Fixed.
28 virtual void TearDown() OVERRIDE { 30 virtual void TearDown() OVERRIDE {
29 ui::Clipboard::DestroyClipboardForCurrentThread(); 31 ui::Clipboard::DestroyClipboardForCurrentThread();
30 } 32 }
31 33
34 void ExpectGroupedChangeCount(int expected_beginning_count,
35 int expected_ended_count) {
36 EXPECT_EQ(grouped_changes_beginning_count_, expected_beginning_count);
37 EXPECT_EQ(grouped_changes_ended_count_, expected_ended_count);
38 }
39
40 // BookmarkModelObserver:
tfarina 2014/02/22 15:09:30 BaseBookmarkModelObserver
Tom Cassiotis 2014/02/22 20:54:02 Done.
41 virtual void BookmarkModelChanged() OVERRIDE {}
42
43 virtual void GroupedBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE {
44 ++grouped_changes_beginning_count_;
45 }
46
47 virtual void GroupedBookmarkChangesEnded(BookmarkModel* model) OVERRIDE {
48 ++grouped_changes_ended_count_;
49 }
50
32 private: 51 private:
52 int grouped_changes_beginning_count_;
53 int grouped_changes_ended_count_;
54
33 // Clipboard requires a message loop. 55 // Clipboard requires a message loop.
34 base::MessageLoopForUI loop_; 56 base::MessageLoopForUI loop_;
35 57
36 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest); 58 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest);
37 }; 59 };
38 60
39 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { 61 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) {
40 BookmarkModel model(NULL); 62 BookmarkModel model(NULL);
41 const BookmarkNode* node1 = model.AddURL(model.other_node(), 63 const BookmarkNode* node1 = model.AddURL(model.other_node(),
42 0, 64 0,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 ui::ScopedClipboardWriter clipboard_writer( 257 ui::ScopedClipboardWriter clipboard_writer(
236 ui::Clipboard::GetForCurrentThread(), 258 ui::Clipboard::GetForCurrentThread(),
237 ui::CLIPBOARD_TYPE_COPY_PASTE); 259 ui::CLIPBOARD_TYPE_COPY_PASTE);
238 clipboard_writer.WriteText(ASCIIToUTF16("foo")); 260 clipboard_writer.WriteText(ASCIIToUTF16("foo"));
239 } 261 }
240 262
241 // Now we shouldn't be able to paste from the clipboard. 263 // Now we shouldn't be able to paste from the clipboard.
242 EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node())); 264 EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node()));
243 } 265 }
244 266
267 TEST_F(BookmarkUtilsTest, CutToClipboard) {
268 BookmarkModel model(NULL);
269 model.AddObserver(this);
270
271 base::string16 title(ASCIIToUTF16("foo"));
272 GURL url("http://foo.com");
273 const BookmarkNode* n1 = model.AddURL(model.other_node(), 0, title, url);
274 const BookmarkNode* n2 = model.AddURL(model.other_node(), 1, title, url);
275
276 // Cut the nodes to the clipboard.
277 std::vector<const BookmarkNode*> nodes;
278 nodes.push_back(n1);
279 nodes.push_back(n2);
280 CopyToClipboard(&model, nodes, true);
281
282 // Make sure the nodes were removed.
283 EXPECT_EQ(0, model.other_node()->child_count());
284
285 // Make sure observers were notified the set of changes should be grouped.
286 ExpectGroupedChangeCount(1, 1);
287
288 // And make sure we can paste from the clipboard.
289 EXPECT_TRUE(CanPasteFromClipboard(model.other_node()));
290 }
291
245 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { 292 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) {
246 BookmarkModel model(NULL); 293 BookmarkModel model(NULL);
247 // This tests the case where selection contains one item and that item is a 294 // This tests the case where selection contains one item and that item is a
248 // folder. 295 // folder.
249 std::vector<const BookmarkNode*> nodes; 296 std::vector<const BookmarkNode*> nodes;
250 nodes.push_back(model.bookmark_bar_node()); 297 nodes.push_back(model.bookmark_bar_node());
251 int index = -1; 298 int index = -1;
252 const BookmarkNode* real_parent = GetParentForNewNodes( 299 const BookmarkNode* real_parent = GetParentForNewNodes(
253 model.bookmark_bar_node(), nodes, &index); 300 model.bookmark_bar_node(), nodes, &index);
254 EXPECT_EQ(real_parent, model.bookmark_bar_node()); 301 EXPECT_EQ(real_parent, model.bookmark_bar_node());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size()); 356 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size());
310 std::string value; 357 std::string value;
311 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value)); 358 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value));
312 EXPECT_EQ("somevalue", value); 359 EXPECT_EQ("somevalue", value);
313 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value)); 360 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value));
314 EXPECT_EQ("someothervalue", value); 361 EXPECT_EQ("someothervalue", value);
315 } 362 }
316 363
317 } // namespace 364 } // namespace
318 } // namespace bookmark_utils 365 } // namespace bookmark_utils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698