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

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

Issue 105193002: Replace string16 with base::string16. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.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 "chrome/browser/bookmarks/bookmark_model_factory.h" 10 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 ui::OSExchangeData data; 43 ui::OSExchangeData data;
44 BookmarkNodeData drag_data; 44 BookmarkNodeData drag_data;
45 EXPECT_FALSE(drag_data.Read(ui::OSExchangeData(CloneProvider(data)))); 45 EXPECT_FALSE(drag_data.Read(ui::OSExchangeData(CloneProvider(data))));
46 EXPECT_FALSE(drag_data.is_valid()); 46 EXPECT_FALSE(drag_data.is_valid());
47 } 47 }
48 48
49 // Writes a URL to the clipboard and make sure BookmarkNodeData can correctly 49 // Writes a URL to the clipboard and make sure BookmarkNodeData can correctly
50 // read it. 50 // read it.
51 TEST_F(BookmarkNodeDataTest, JustURL) { 51 TEST_F(BookmarkNodeDataTest, JustURL) {
52 const GURL url("http://google.com"); 52 const GURL url("http://google.com");
53 const string16 title(ASCIIToUTF16("google.com")); 53 const base::string16 title(ASCIIToUTF16("google.com"));
54 54
55 ui::OSExchangeData data; 55 ui::OSExchangeData data;
56 data.SetURL(url, title); 56 data.SetURL(url, title);
57 57
58 BookmarkNodeData drag_data; 58 BookmarkNodeData drag_data;
59 EXPECT_TRUE(drag_data.Read(ui::OSExchangeData(CloneProvider(data)))); 59 EXPECT_TRUE(drag_data.Read(ui::OSExchangeData(CloneProvider(data))));
60 EXPECT_TRUE(drag_data.is_valid()); 60 EXPECT_TRUE(drag_data.is_valid());
61 ASSERT_EQ(1u, drag_data.elements.size()); 61 ASSERT_EQ(1u, drag_data.elements.size());
62 EXPECT_TRUE(drag_data.elements[0].is_url); 62 EXPECT_TRUE(drag_data.elements[0].is_url);
63 EXPECT_EQ(url, drag_data.elements[0].url); 63 EXPECT_EQ(url, drag_data.elements[0].url);
64 EXPECT_EQ(title, drag_data.elements[0].title); 64 EXPECT_EQ(title, drag_data.elements[0].title);
65 EXPECT_TRUE(drag_data.elements[0].date_added.is_null()); 65 EXPECT_TRUE(drag_data.elements[0].date_added.is_null());
66 EXPECT_TRUE(drag_data.elements[0].date_folder_modified.is_null()); 66 EXPECT_TRUE(drag_data.elements[0].date_folder_modified.is_null());
67 EXPECT_EQ(0u, drag_data.elements[0].children.size()); 67 EXPECT_EQ(0u, drag_data.elements[0].children.size());
68 } 68 }
69 69
70 TEST_F(BookmarkNodeDataTest, URL) { 70 TEST_F(BookmarkNodeDataTest, URL) {
71 // Write a single node representing a URL to the clipboard. 71 // Write a single node representing a URL to the clipboard.
72 TestingProfile profile; 72 TestingProfile profile;
73 profile.SetID(L"id"); 73 profile.SetID(L"id");
74 profile.CreateBookmarkModel(false); 74 profile.CreateBookmarkModel(false);
75 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile); 75 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile);
76 test::WaitForBookmarkModelToLoad(model); 76 test::WaitForBookmarkModelToLoad(model);
77 const BookmarkNode* root = model->bookmark_bar_node(); 77 const BookmarkNode* root = model->bookmark_bar_node();
78 GURL url(GURL("http://foo.com")); 78 GURL url(GURL("http://foo.com"));
79 const string16 title(ASCIIToUTF16("foo.com")); 79 const base::string16 title(ASCIIToUTF16("foo.com"));
80 const BookmarkNode* node = model->AddURL(root, 0, title, url); 80 const BookmarkNode* node = model->AddURL(root, 0, title, url);
81 BookmarkNodeData drag_data(node); 81 BookmarkNodeData drag_data(node);
82 EXPECT_TRUE(drag_data.is_valid()); 82 EXPECT_TRUE(drag_data.is_valid());
83 ASSERT_EQ(1u, drag_data.elements.size()); 83 ASSERT_EQ(1u, drag_data.elements.size());
84 EXPECT_TRUE(drag_data.elements[0].is_url); 84 EXPECT_TRUE(drag_data.elements[0].is_url);
85 EXPECT_EQ(url, drag_data.elements[0].url); 85 EXPECT_EQ(url, drag_data.elements[0].url);
86 EXPECT_EQ(title, drag_data.elements[0].title); 86 EXPECT_EQ(title, drag_data.elements[0].title);
87 EXPECT_EQ(node->date_added(), drag_data.elements[0].date_added); 87 EXPECT_EQ(node->date_added(), drag_data.elements[0].date_added);
88 EXPECT_EQ(node->date_folder_modified(), 88 EXPECT_EQ(node->date_folder_modified(),
89 drag_data.elements[0].date_folder_modified); 89 drag_data.elements[0].date_folder_modified);
(...skipping 12 matching lines...) Expand all
102 EXPECT_TRUE(read_data.elements[0].date_added.is_null()); 102 EXPECT_TRUE(read_data.elements[0].date_added.is_null());
103 EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); 103 EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null());
104 EXPECT_TRUE(read_data.GetFirstNode(&profile) == node); 104 EXPECT_TRUE(read_data.GetFirstNode(&profile) == node);
105 105
106 // Make sure asking for the node with a different profile returns NULL. 106 // Make sure asking for the node with a different profile returns NULL.
107 TestingProfile profile2; 107 TestingProfile profile2;
108 EXPECT_TRUE(read_data.GetFirstNode(&profile2) == NULL); 108 EXPECT_TRUE(read_data.GetFirstNode(&profile2) == NULL);
109 109
110 // Writing should also put the URL and title on the clipboard. 110 // Writing should also put the URL and title on the clipboard.
111 GURL read_url; 111 GURL read_url;
112 string16 read_title; 112 base::string16 read_title;
113 EXPECT_TRUE(data2.GetURLAndTitle(&read_url, &read_title)); 113 EXPECT_TRUE(data2.GetURLAndTitle(&read_url, &read_title));
114 EXPECT_EQ(url, read_url); 114 EXPECT_EQ(url, read_url);
115 EXPECT_EQ(title, read_title); 115 EXPECT_EQ(title, read_title);
116 } 116 }
117 117
118 // Tests writing a folder to the clipboard. 118 // Tests writing a folder to the clipboard.
119 TEST_F(BookmarkNodeDataTest, Folder) { 119 TEST_F(BookmarkNodeDataTest, Folder) {
120 TestingProfile profile; 120 TestingProfile profile;
121 profile.SetID(L"id"); 121 profile.SetID(L"id");
122 profile.CreateBookmarkModel(false); 122 profile.CreateBookmarkModel(false);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 profile.SetID(L"id"); 167 profile.SetID(L"id");
168 profile.CreateBookmarkModel(false); 168 profile.CreateBookmarkModel(false);
169 169
170 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile); 170 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile);
171 test::WaitForBookmarkModelToLoad(model); 171 test::WaitForBookmarkModelToLoad(model);
172 172
173 const BookmarkNode* root = model->bookmark_bar_node(); 173 const BookmarkNode* root = model->bookmark_bar_node();
174 const BookmarkNode* folder = model->AddFolder(root, 0, ASCIIToUTF16("g1")); 174 const BookmarkNode* folder = model->AddFolder(root, 0, ASCIIToUTF16("g1"));
175 175
176 GURL url(GURL("http://foo.com")); 176 GURL url(GURL("http://foo.com"));
177 const string16 title(ASCIIToUTF16("blah2")); 177 const base::string16 title(ASCIIToUTF16("blah2"));
178 178
179 model->AddURL(folder, 0, title, url); 179 model->AddURL(folder, 0, title, url);
180 180
181 BookmarkNodeData drag_data(folder); 181 BookmarkNodeData drag_data(folder);
182 182
183 ui::OSExchangeData data; 183 ui::OSExchangeData data;
184 drag_data.Write(&profile, &data); 184 drag_data.Write(&profile, &data);
185 185
186 // Now read the data back in. 186 // Now read the data back in.
187 ui::OSExchangeData data2(CloneProvider(data)); 187 ui::OSExchangeData data2(CloneProvider(data));
(...skipping 22 matching lines...) Expand all
210 profile.SetID(L"id"); 210 profile.SetID(L"id");
211 profile.CreateBookmarkModel(false); 211 profile.CreateBookmarkModel(false);
212 212
213 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile); 213 BookmarkModel* model = BookmarkModelFactory::GetForProfile(&profile);
214 test::WaitForBookmarkModelToLoad(model); 214 test::WaitForBookmarkModelToLoad(model);
215 215
216 const BookmarkNode* root = model->bookmark_bar_node(); 216 const BookmarkNode* root = model->bookmark_bar_node();
217 const BookmarkNode* folder = model->AddFolder(root, 0, ASCIIToUTF16("g1")); 217 const BookmarkNode* folder = model->AddFolder(root, 0, ASCIIToUTF16("g1"));
218 218
219 GURL url(GURL("http://foo.com")); 219 GURL url(GURL("http://foo.com"));
220 const string16 title(ASCIIToUTF16("blah2")); 220 const base::string16 title(ASCIIToUTF16("blah2"));
221 221
222 const BookmarkNode* url_node = model->AddURL(folder, 0, title, url); 222 const BookmarkNode* url_node = model->AddURL(folder, 0, title, url);
223 223
224 // Write the nodes to the clipboard. 224 // Write the nodes to the clipboard.
225 std::vector<const BookmarkNode*> nodes; 225 std::vector<const BookmarkNode*> nodes;
226 nodes.push_back(folder); 226 nodes.push_back(folder);
227 nodes.push_back(url_node); 227 nodes.push_back(url_node);
228 BookmarkNodeData drag_data(nodes); 228 BookmarkNodeData drag_data(nodes);
229 ui::OSExchangeData data; 229 ui::OSExchangeData data;
230 drag_data.Write(&profile, &data); 230 drag_data.Write(&profile, &data);
(...skipping 21 matching lines...) Expand all
252 // And make sure we get the node back. 252 // And make sure we get the node back.
253 std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile); 253 std::vector<const BookmarkNode*> read_nodes = read_data.GetNodes(&profile);
254 ASSERT_EQ(2u, read_nodes.size()); 254 ASSERT_EQ(2u, read_nodes.size());
255 EXPECT_TRUE(read_nodes[0] == folder); 255 EXPECT_TRUE(read_nodes[0] == folder);
256 EXPECT_TRUE(read_nodes[1] == url_node); 256 EXPECT_TRUE(read_nodes[1] == url_node);
257 257
258 // Asking for the first node should return NULL with more than one element 258 // Asking for the first node should return NULL with more than one element
259 // present. 259 // present.
260 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL); 260 EXPECT_TRUE(read_data.GetFirstNode(&profile) == NULL);
261 } 261 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_node_data.cc ('k') | chrome/browser/bookmarks/bookmark_node_data_views.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698