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

Side by Side Diff: chrome/browser/history/android/bookmark_model_sql_handler_unittest.cc

Issue 10825147: Made BookmarkService::GetBookmarks return both urls and title. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: splited into 2 cls Created 8 years, 4 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/history/android/bookmark_model_sql_handler.h" 5 #include "chrome/browser/history/android/bookmark_model_sql_handler.h"
6 6
7 #include "base/synchronization/waitable_event.h" 7 #include "base/synchronization/waitable_event.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/bookmarks/bookmark_model.h" 9 #include "chrome/browser/bookmarks/bookmark_model.h"
10 #include "chrome/browser/history/history_database.h" 10 #include "chrome/browser/history/history_database.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 TableIDRow id_row; 130 TableIDRow id_row;
131 id_row.url_id = url_id; 131 id_row.url_id = url_id;
132 id_row.url = url_row.url(); 132 id_row.url = url_row.url();
133 TableIDRows id_rows; 133 TableIDRows id_rows;
134 id_rows.push_back(id_row); 134 id_rows.push_back(id_row);
135 135
136 BookmarkModelSQLHandler handler(&history_db_); 136 BookmarkModelSQLHandler handler(&history_db_);
137 ASSERT_TRUE(handler.Update(row, id_rows)); 137 ASSERT_TRUE(handler.Update(row, id_rows));
138 RunMessageLoopForUI(); 138 RunMessageLoopForUI();
139 // Get all bookmarks and verify there is only one. 139 // Get all bookmarks and verify there is only one.
140 std::vector<GURL> urls; 140 std::vector<BookmarkService::Bookmark> bookmarks;
141 bookmark_model_->GetBookmarks(&urls); 141 bookmark_model_->GetBookmarks(&bookmarks);
142 EXPECT_EQ(1u, urls.size()); 142 ASSERT_EQ(1u, bookmarks.size());
143 EXPECT_EQ(url_row.url(), urls[0]); 143 EXPECT_EQ(url_row.url(), bookmarks[0].url);
144 EXPECT_EQ(url_row.title(), bookmarks[0].title);
145
144 // Get the bookmark node. 146 // Get the bookmark node.
145 std::vector<const BookmarkNode*> nodes; 147 std::vector<const BookmarkNode*> nodes;
146 bookmark_model_->GetNodesByURL(row.url(), &nodes); 148 bookmark_model_->GetNodesByURL(row.url(), &nodes);
147 ASSERT_EQ(1u, nodes.size()); 149 ASSERT_EQ(1u, nodes.size());
148 EXPECT_EQ(url_row.title(), nodes[0]->GetTitle()); 150 EXPECT_EQ(url_row.title(), nodes[0]->GetTitle());
149 const BookmarkNode* parent = nodes[0]->parent(); 151 const BookmarkNode* parent = nodes[0]->parent();
150 ASSERT_TRUE(parent); 152 ASSERT_TRUE(parent);
151 EXPECT_EQ(bookmark_model_->mobile_node()->id(), parent->id()); 153 EXPECT_EQ(bookmark_model_->mobile_node()->id(), parent->id());
152 154
153 // Remove the bookmark 155 // Remove the bookmark
154 row.set_is_bookmark(false); 156 row.set_is_bookmark(false);
155 ASSERT_TRUE(handler.Update(row, id_rows)); 157 ASSERT_TRUE(handler.Update(row, id_rows));
156 RunMessageLoopForUI(); 158 RunMessageLoopForUI();
157 urls.clear(); 159 bookmarks.clear();
158 bookmark_model_->GetBookmarks(&urls); 160 bookmark_model_->GetBookmarks(&bookmarks);
159 EXPECT_TRUE(urls.empty()); 161 EXPECT_TRUE(bookmarks.empty());
160 162
161 // Update with the parent id. 163 // Update with the parent id.
162 row.set_parent_id(bookmark_model_->other_node()->id()); 164 row.set_parent_id(bookmark_model_->other_node()->id());
163 row.set_is_bookmark(true); 165 row.set_is_bookmark(true);
164 ASSERT_TRUE(handler.Update(row, id_rows)); 166 ASSERT_TRUE(handler.Update(row, id_rows));
165 RunMessageLoopForUI(); 167 RunMessageLoopForUI();
166 // Get all bookmarks and verify there is only one. 168 // Get all bookmarks and verify there is only one.
167 urls.clear(); 169 bookmarks.clear();
168 bookmark_model_->GetBookmarks(&urls); 170 bookmark_model_->GetBookmarks(&bookmarks);
169 EXPECT_EQ(1u, urls.size()); 171 ASSERT_EQ(1u, bookmarks.size());
170 EXPECT_EQ(url_row.url(), urls[0]); 172 EXPECT_EQ(url_row.url(), bookmarks[0].url);
173 EXPECT_EQ(url_row.title(), bookmarks[0].title);
171 // Get the bookmark node. 174 // Get the bookmark node.
172 nodes.clear(); 175 nodes.clear();
173 bookmark_model_->GetNodesByURL(row.url(), &nodes); 176 bookmark_model_->GetNodesByURL(row.url(), &nodes);
174 ASSERT_EQ(1u, nodes.size()); 177 ASSERT_EQ(1u, nodes.size());
175 EXPECT_EQ(url_row.title(), nodes[0]->GetTitle()); 178 EXPECT_EQ(url_row.title(), nodes[0]->GetTitle());
176 const BookmarkNode* parent1 = nodes[0]->parent(); 179 const BookmarkNode* parent1 = nodes[0]->parent();
177 ASSERT_TRUE(parent1); 180 ASSERT_TRUE(parent1);
178 EXPECT_EQ(row.parent_id(), parent1->id()); 181 EXPECT_EQ(row.parent_id(), parent1->id());
179 182
180 // Only update the title. 183 // Only update the title.
181 url_row.set_title(UTF8ToUTF16("Google Inc.")); 184 url_row.set_title(UTF8ToUTF16("Google Inc."));
182 history_db_.UpdateURLRow(url_id, url_row); 185 history_db_.UpdateURLRow(url_id, url_row);
183 HistoryAndBookmarkRow update_title; 186 HistoryAndBookmarkRow update_title;
184 update_title.set_title(url_row.title()); 187 update_title.set_title(url_row.title());
185 ASSERT_TRUE(handler.Update(update_title, id_rows)); 188 ASSERT_TRUE(handler.Update(update_title, id_rows));
186 RunMessageLoopForUI(); 189 RunMessageLoopForUI();
187 // Get all bookmarks and verify there is only one. 190 // Get all bookmarks and verify there is only one.
188 urls.clear(); 191 bookmarks.clear();
189 bookmark_model_->GetBookmarks(&urls); 192 bookmark_model_->GetBookmarks(&bookmarks);
190 EXPECT_EQ(1u, urls.size()); 193 ASSERT_EQ(1u, bookmarks.size());
191 EXPECT_EQ(url_row.url(), urls[0]); 194 EXPECT_EQ(url_row.url(), bookmarks[0].url);
195 EXPECT_EQ(url_row.title(), bookmarks[0].title);
192 // Get the bookmark node. 196 // Get the bookmark node.
193 nodes.clear(); 197 nodes.clear();
194 bookmark_model_->GetNodesByURL(row.url(), &nodes); 198 bookmark_model_->GetNodesByURL(row.url(), &nodes);
195 ASSERT_EQ(1u, nodes.size()); 199 ASSERT_EQ(1u, nodes.size());
196 EXPECT_EQ(url_row.title(), nodes[0]->GetTitle()); 200 EXPECT_EQ(url_row.title(), nodes[0]->GetTitle());
197 const BookmarkNode* parent2 = nodes[0]->parent(); 201 const BookmarkNode* parent2 = nodes[0]->parent();
198 ASSERT_TRUE(parent2); 202 ASSERT_TRUE(parent2);
199 // The parent id shouldn't changed. 203 // The parent id shouldn't changed.
200 EXPECT_EQ(row.parent_id(), parent2->id()); 204 EXPECT_EQ(row.parent_id(), parent2->id());
201 } 205 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 id_row.url = url1; 243 id_row.url = url1;
240 id_rows.clear(); 244 id_rows.clear();
241 id_rows.push_back(id_row); 245 id_rows.push_back(id_row);
242 ASSERT_TRUE(handler.Delete(id_rows)); 246 ASSERT_TRUE(handler.Delete(id_rows));
243 RunMessageLoopForUI(); 247 RunMessageLoopForUI();
244 // All bookmarks were deleted. 248 // All bookmarks were deleted.
245 EXPECT_FALSE(bookmark_model_->HasBookmarks()); 249 EXPECT_FALSE(bookmark_model_->HasBookmarks());
246 } 250 }
247 251
248 } // namespace history 252 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698