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

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

Issue 176563002: Revert r252832: Eliminate Bookmarks dependence to bookmark_undo_utils.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
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 | Annotate | Revision Log
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"
12 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
13 #include "chrome/browser/bookmarks/bookmark_node_data.h" 12 #include "chrome/browser/bookmarks/bookmark_node_data.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/base/clipboard/clipboard.h" 14 #include "ui/base/clipboard/clipboard.h"
16 #include "ui/base/clipboard/scoped_clipboard_writer.h" 15 #include "ui/base/clipboard/scoped_clipboard_writer.h"
17 16
18 using base::ASCIIToUTF16; 17 using base::ASCIIToUTF16;
19 using std::string; 18 using std::string;
20 19
21 namespace bookmark_utils { 20 namespace bookmark_utils {
22 namespace { 21 namespace {
23 22
24 class BookmarkUtilsTest : public testing::Test, 23 class BookmarkUtilsTest : public ::testing::Test {
25 public BaseBookmarkModelObserver {
26 public: 24 public:
27 BookmarkUtilsTest() 25 BookmarkUtilsTest() {}
28 : grouped_changes_beginning_count_(0), grouped_changes_ended_count_(0) {}
29 virtual ~BookmarkUtilsTest() {} 26 virtual ~BookmarkUtilsTest() {}
30 27
31 virtual void TearDown() OVERRIDE { 28 virtual void TearDown() OVERRIDE {
32 ui::Clipboard::DestroyClipboardForCurrentThread(); 29 ui::Clipboard::DestroyClipboardForCurrentThread();
33 } 30 }
34 31
35 void ExpectGroupedChangeCount(int expected_beginning_count,
36 int expected_ended_count) {
37 EXPECT_EQ(grouped_changes_beginning_count_, expected_beginning_count);
38 EXPECT_EQ(grouped_changes_ended_count_, expected_ended_count);
39 }
40
41 // BaseBookmarkModelObserver:
42 virtual void BookmarkModelChanged() OVERRIDE {}
43
44 virtual void GroupedBookmarkChangesBeginning(BookmarkModel* model) OVERRIDE {
45 ++grouped_changes_beginning_count_;
46 }
47
48 virtual void GroupedBookmarkChangesEnded(BookmarkModel* model) OVERRIDE {
49 ++grouped_changes_ended_count_;
50 }
51
52 private: 32 private:
53 int grouped_changes_beginning_count_;
54 int grouped_changes_ended_count_;
55
56 // Clipboard requires a message loop. 33 // Clipboard requires a message loop.
57 base::MessageLoopForUI loop_; 34 base::MessageLoopForUI loop_;
58 35
59 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest); 36 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest);
60 }; 37 };
61 38
62 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { 39 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) {
63 BookmarkModel model(NULL); 40 BookmarkModel model(NULL);
64 const BookmarkNode* node1 = model.AddURL(model.other_node(), 41 const BookmarkNode* node1 = model.AddURL(model.other_node(),
65 0, 42 0,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 ui::ScopedClipboardWriter clipboard_writer( 235 ui::ScopedClipboardWriter clipboard_writer(
259 ui::Clipboard::GetForCurrentThread(), 236 ui::Clipboard::GetForCurrentThread(),
260 ui::CLIPBOARD_TYPE_COPY_PASTE); 237 ui::CLIPBOARD_TYPE_COPY_PASTE);
261 clipboard_writer.WriteText(ASCIIToUTF16("foo")); 238 clipboard_writer.WriteText(ASCIIToUTF16("foo"));
262 } 239 }
263 240
264 // Now we shouldn't be able to paste from the clipboard. 241 // Now we shouldn't be able to paste from the clipboard.
265 EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node())); 242 EXPECT_FALSE(CanPasteFromClipboard(model.bookmark_bar_node()));
266 } 243 }
267 244
268 TEST_F(BookmarkUtilsTest, CutToClipboard) {
269 BookmarkModel model(NULL);
270 model.AddObserver(this);
271
272 base::string16 title(ASCIIToUTF16("foo"));
273 GURL url("http://foo.com");
274 const BookmarkNode* n1 = model.AddURL(model.other_node(), 0, title, url);
275 const BookmarkNode* n2 = model.AddURL(model.other_node(), 1, title, url);
276
277 // Cut the nodes to the clipboard.
278 std::vector<const BookmarkNode*> nodes;
279 nodes.push_back(n1);
280 nodes.push_back(n2);
281 CopyToClipboard(&model, nodes, true);
282
283 // Make sure the nodes were removed.
284 EXPECT_EQ(0, model.other_node()->child_count());
285
286 // Make sure observers were notified the set of changes should be grouped.
287 ExpectGroupedChangeCount(1, 1);
288
289 // And make sure we can paste from the clipboard.
290 EXPECT_TRUE(CanPasteFromClipboard(model.other_node()));
291 }
292
293 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { 245 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) {
294 BookmarkModel model(NULL); 246 BookmarkModel model(NULL);
295 // This tests the case where selection contains one item and that item is a 247 // This tests the case where selection contains one item and that item is a
296 // folder. 248 // folder.
297 std::vector<const BookmarkNode*> nodes; 249 std::vector<const BookmarkNode*> nodes;
298 nodes.push_back(model.bookmark_bar_node()); 250 nodes.push_back(model.bookmark_bar_node());
299 int index = -1; 251 int index = -1;
300 const BookmarkNode* real_parent = GetParentForNewNodes( 252 const BookmarkNode* real_parent = GetParentForNewNodes(
301 model.bookmark_bar_node(), nodes, &index); 253 model.bookmark_bar_node(), nodes, &index);
302 EXPECT_EQ(real_parent, model.bookmark_bar_node()); 254 EXPECT_EQ(real_parent, model.bookmark_bar_node());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size()); 309 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size());
358 std::string value; 310 std::string value;
359 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value)); 311 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value));
360 EXPECT_EQ("somevalue", value); 312 EXPECT_EQ("somevalue", value);
361 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value)); 313 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value));
362 EXPECT_EQ("someothervalue", value); 314 EXPECT_EQ("someothervalue", value);
363 } 315 }
364 316
365 } // namespace 317 } // namespace
366 } // namespace bookmark_utils 318 } // namespace bookmark_utils
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.cc ('k') | chrome/browser/bookmarks/scoped_group_bookmark_actions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698