OLD | NEW |
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 "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 ui::Clipboard::DestroyClipboardForCurrentThread(); | 22 ui::Clipboard::DestroyClipboardForCurrentThread(); |
23 } | 23 } |
24 | 24 |
25 private: | 25 private: |
26 // Clipboard requires a message loop. | 26 // Clipboard requires a message loop. |
27 base::MessageLoopForUI loop; | 27 base::MessageLoopForUI loop; |
28 }; | 28 }; |
29 | 29 |
30 TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) { | 30 TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) { |
31 BookmarkModel model(NULL); | 31 BookmarkModel model(NULL); |
32 const BookmarkNode* n1 = model.AddURL(model.other_node(), | 32 const BookmarkNode* node1 = model.AddURL(model.other_node(), |
33 0, | 33 0, |
34 ASCIIToUTF16("foo bar"), | 34 ASCIIToUTF16("foo bar"), |
35 GURL("http://www.google.com")); | 35 GURL("http://www.google.com")); |
36 const BookmarkNode* n2 = model.AddURL(model.other_node(), | 36 const BookmarkNode* node2 = model.AddURL(model.other_node(), |
37 0, | 37 0, |
38 ASCIIToUTF16("baz buz"), | 38 ASCIIToUTF16("baz buz"), |
39 GURL("http://www.cnn.com")); | 39 GURL("http://www.cnn.com")); |
40 | 40 |
41 model.AddFolder(model.other_node(), 0, ASCIIToUTF16("foo")); | 41 const BookmarkNode* folder1 = model.AddFolder(model.other_node(), |
| 42 0, |
| 43 ASCIIToUTF16("foo")); |
42 | 44 |
43 std::vector<const BookmarkNode*> nodes; | 45 std::vector<const BookmarkNode*> nodes; |
44 GetBookmarksContainingText( | 46 GetBookmarksContainingText( |
45 &model, ASCIIToUTF16("foo"), 100, string(), &nodes); | 47 &model, ASCIIToUTF16("foo"), 100, string(), &nodes); |
46 ASSERT_EQ(1U, nodes.size()); | 48 ASSERT_EQ(2U, nodes.size()); |
47 EXPECT_TRUE(nodes[0] == n1); | 49 EXPECT_TRUE(nodes[0] == folder1); |
| 50 EXPECT_TRUE(nodes[1] == node1); |
48 nodes.clear(); | 51 nodes.clear(); |
49 | 52 |
50 GetBookmarksContainingText( | 53 GetBookmarksContainingText( |
51 &model, ASCIIToUTF16("cnn"), 100, string(), &nodes); | 54 &model, ASCIIToUTF16("cnn"), 100, string(), &nodes); |
52 ASSERT_EQ(1U, nodes.size()); | 55 ASSERT_EQ(1U, nodes.size()); |
53 EXPECT_TRUE(nodes[0] == n2); | 56 EXPECT_TRUE(nodes[0] == node2); |
54 nodes.clear(); | 57 nodes.clear(); |
55 | 58 |
56 GetBookmarksContainingText( | 59 GetBookmarksContainingText( |
57 &model, ASCIIToUTF16("foo bar"), 100, string(), &nodes); | 60 &model, ASCIIToUTF16("foo bar"), 100, string(), &nodes); |
58 ASSERT_EQ(1U, nodes.size()); | 61 ASSERT_EQ(1U, nodes.size()); |
59 EXPECT_TRUE(nodes[0] == n1); | 62 EXPECT_TRUE(nodes[0] == node1); |
60 nodes.clear(); | 63 nodes.clear(); |
61 } | 64 } |
62 | 65 |
63 TEST_F(BookmarkUtilsTest, CopyPaste) { | 66 TEST_F(BookmarkUtilsTest, CopyPaste) { |
64 BookmarkModel model(NULL); | 67 BookmarkModel model(NULL); |
65 const BookmarkNode* node = model.AddURL(model.other_node(), | 68 const BookmarkNode* node = model.AddURL(model.other_node(), |
66 0, | 69 0, |
67 ASCIIToUTF16("foo bar"), | 70 ASCIIToUTF16("foo bar"), |
68 GURL("http://www.google.com")); | 71 GURL("http://www.google.com")); |
69 | 72 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 124 |
122 // This tests the case where selection doesn't contain any items. | 125 // This tests the case where selection doesn't contain any items. |
123 nodes.clear(); | 126 nodes.clear(); |
124 real_parent = GetParentForNewNodes(model.bookmark_bar_node(), nodes, &index); | 127 real_parent = GetParentForNewNodes(model.bookmark_bar_node(), nodes, &index); |
125 EXPECT_EQ(real_parent, model.bookmark_bar_node()); | 128 EXPECT_EQ(real_parent, model.bookmark_bar_node()); |
126 EXPECT_EQ(2, index); | 129 EXPECT_EQ(2, index); |
127 } | 130 } |
128 | 131 |
129 } // namespace | 132 } // namespace |
130 } // namespace bookmark_utils | 133 } // namespace bookmark_utils |
OLD | NEW |