| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> | 5 #include <set> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 9 #include "base/command_line.h" |
| 9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 10 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
| 11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 12 #include "base/string16.h" | 13 #include "base/string16.h" |
| 13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 14 #include "base/string_split.h" | 15 #include "base/string_split.h" |
| 15 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_codec.h" | 18 #include "chrome/browser/bookmarks/bookmark_codec.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_model.h" | 19 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_utils.h" | 20 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 20 #include "chrome/browser/history/history_notifications.h" | 21 #include "chrome/browser/history/history_notifications.h" |
| 21 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/test/model_test_utils.h" | 25 #include "chrome/test/model_test_utils.h" |
| 24 #include "chrome/test/testing_browser_process_test.h" | 26 #include "chrome/test/testing_browser_process_test.h" |
| 25 #include "chrome/test/testing_profile.h" | 27 #include "chrome/test/testing_profile.h" |
| 26 #include "content/browser/browser_thread.h" | 28 #include "content/browser/browser_thread.h" |
| 27 #include "content/common/notification_details.h" | 29 #include "content/common/notification_details.h" |
| 28 #include "content/common/notification_registrar.h" | 30 #include "content/common/notification_registrar.h" |
| 29 #include "content/common/notification_source.h" | 31 #include "content/common/notification_source.h" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "ui/base/models/tree_node_iterator.h" | 33 #include "ui/base/models/tree_node_iterator.h" |
| 32 #include "ui/base/models/tree_node_model.h" | 34 #include "ui/base/models/tree_node_model.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 ASSERT_EQ(index1, this->index1); | 78 ASSERT_EQ(index1, this->index1); |
| 77 ASSERT_EQ(index2, this->index2); | 79 ASSERT_EQ(index2, this->index2); |
| 78 } | 80 } |
| 79 | 81 |
| 80 const BookmarkNode* node1; | 82 const BookmarkNode* node1; |
| 81 const BookmarkNode* node2; | 83 const BookmarkNode* node2; |
| 82 int index1; | 84 int index1; |
| 83 int index2; | 85 int index2; |
| 84 }; | 86 }; |
| 85 | 87 |
| 86 BookmarkModelTest() : model(NULL) { | 88 BookmarkModelTest() { |
| 87 model.AddObserver(this); | 89 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 90 switches::kEnableSyncedBookmarksFolder); |
| 91 model_.reset(new BookmarkModel(NULL)); |
| 92 model_->AddObserver(this); |
| 88 ClearCounts(); | 93 ClearCounts(); |
| 89 } | 94 } |
| 90 | 95 |
| 91 | |
| 92 void Loaded(BookmarkModel* model) { | 96 void Loaded(BookmarkModel* model) { |
| 93 // We never load from the db, so that this should never get invoked. | 97 // We never load from the db, so that this should never get invoked. |
| 94 NOTREACHED(); | 98 NOTREACHED(); |
| 95 } | 99 } |
| 96 | 100 |
| 97 virtual void BookmarkNodeMoved(BookmarkModel* model, | 101 virtual void BookmarkNodeMoved(BookmarkModel* model, |
| 98 const BookmarkNode* old_parent, | 102 const BookmarkNode* old_parent, |
| 99 int old_index, | 103 int old_index, |
| 100 const BookmarkNode* new_parent, | 104 const BookmarkNode* new_parent, |
| 101 int new_index) { | 105 int new_index) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 int removed_count, | 149 int removed_count, |
| 146 int changed_count, | 150 int changed_count, |
| 147 int reordered_count) { | 151 int reordered_count) { |
| 148 ASSERT_EQ(added_count, this->added_count); | 152 ASSERT_EQ(added_count, this->added_count); |
| 149 ASSERT_EQ(moved_count, this->moved_count); | 153 ASSERT_EQ(moved_count, this->moved_count); |
| 150 ASSERT_EQ(removed_count, this->removed_count); | 154 ASSERT_EQ(removed_count, this->removed_count); |
| 151 ASSERT_EQ(changed_count, this->changed_count); | 155 ASSERT_EQ(changed_count, this->changed_count); |
| 152 ASSERT_EQ(reordered_count, reordered_count_); | 156 ASSERT_EQ(reordered_count, reordered_count_); |
| 153 } | 157 } |
| 154 | 158 |
| 155 BookmarkModel model; | 159 scoped_ptr<BookmarkModel> model_; |
| 156 | 160 |
| 157 int moved_count; | 161 int moved_count; |
| 158 | 162 |
| 159 int added_count; | 163 int added_count; |
| 160 | 164 |
| 161 int removed_count; | 165 int removed_count; |
| 162 | 166 |
| 163 int changed_count; | 167 int changed_count; |
| 164 | 168 |
| 165 int reordered_count_; | 169 int reordered_count_; |
| 166 | 170 |
| 167 ObserverDetails observer_details; | 171 ObserverDetails observer_details; |
| 168 }; | 172 }; |
| 169 | 173 |
| 170 TEST_F(BookmarkModelTest, InitialState) { | 174 TEST_F(BookmarkModelTest, InitialState) { |
| 171 const BookmarkNode* bb_node = model.GetBookmarkBarNode(); | 175 const BookmarkNode* bb_node = model_->GetBookmarkBarNode(); |
| 172 ASSERT_TRUE(bb_node != NULL); | 176 ASSERT_TRUE(bb_node != NULL); |
| 173 EXPECT_EQ(0, bb_node->child_count()); | 177 EXPECT_EQ(0, bb_node->child_count()); |
| 174 EXPECT_EQ(BookmarkNode::BOOKMARK_BAR, bb_node->type()); | 178 EXPECT_EQ(BookmarkNode::BOOKMARK_BAR, bb_node->type()); |
| 175 | 179 |
| 176 const BookmarkNode* other_node = model.other_node(); | 180 const BookmarkNode* other_node = model_->other_node(); |
| 177 ASSERT_TRUE(other_node != NULL); | 181 ASSERT_TRUE(other_node != NULL); |
| 178 EXPECT_EQ(0, other_node->child_count()); | 182 EXPECT_EQ(0, other_node->child_count()); |
| 179 EXPECT_EQ(BookmarkNode::OTHER_NODE, other_node->type()); | 183 EXPECT_EQ(BookmarkNode::OTHER_NODE, other_node->type()); |
| 180 | 184 |
| 185 const BookmarkNode* synced_node = model_->synced_node(); |
| 186 ASSERT_TRUE(synced_node != NULL); |
| 187 EXPECT_EQ(0, synced_node->child_count()); |
| 188 EXPECT_EQ(BookmarkNode::SYNCED, synced_node->type()); |
| 189 |
| 181 EXPECT_TRUE(bb_node->id() != other_node->id()); | 190 EXPECT_TRUE(bb_node->id() != other_node->id()); |
| 191 EXPECT_TRUE(bb_node->id() != synced_node->id()); |
| 192 EXPECT_TRUE(other_node->id() != synced_node->id()); |
| 182 } | 193 } |
| 183 | 194 |
| 184 TEST_F(BookmarkModelTest, AddURL) { | 195 TEST_F(BookmarkModelTest, AddURL) { |
| 185 const BookmarkNode* root = model.GetBookmarkBarNode(); | 196 const BookmarkNode* root = model_->GetBookmarkBarNode(); |
| 186 const string16 title(ASCIIToUTF16("foo")); | 197 const string16 title(ASCIIToUTF16("foo")); |
| 187 const GURL url("http://foo.com"); | 198 const GURL url("http://foo.com"); |
| 188 | 199 |
| 189 const BookmarkNode* new_node = model.AddURL(root, 0, title, url); | 200 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
| 190 AssertObserverCount(1, 0, 0, 0, 0); | 201 AssertObserverCount(1, 0, 0, 0, 0); |
| 191 observer_details.AssertEquals(root, NULL, 0, -1); | 202 observer_details.AssertEquals(root, NULL, 0, -1); |
| 192 | 203 |
| 193 ASSERT_EQ(1, root->child_count()); | 204 ASSERT_EQ(1, root->child_count()); |
| 194 ASSERT_EQ(title, new_node->GetTitle()); | 205 ASSERT_EQ(title, new_node->GetTitle()); |
| 195 ASSERT_TRUE(url == new_node->GetURL()); | 206 ASSERT_TRUE(url == new_node->GetURL()); |
| 196 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 207 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 197 ASSERT_TRUE(new_node == model.GetMostRecentlyAddedNodeForURL(url)); | 208 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); |
| 198 | 209 |
| 199 EXPECT_TRUE(new_node->id() != root->id() && | 210 EXPECT_TRUE(new_node->id() != root->id() && |
| 200 new_node->id() != model.other_node()->id()); | 211 new_node->id() != model_->other_node()->id() && |
| 212 new_node->id() != model_->synced_node()->id()); |
| 213 } |
| 214 |
| 215 TEST_F(BookmarkModelTest, AddURLToSyncedBookmarks) { |
| 216 const BookmarkNode* root = model_->synced_node(); |
| 217 const string16 title(ASCIIToUTF16("foo")); |
| 218 const GURL url("http://foo.com"); |
| 219 |
| 220 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
| 221 AssertObserverCount(1, 0, 0, 0, 0); |
| 222 observer_details.AssertEquals(root, NULL, 0, -1); |
| 223 |
| 224 ASSERT_EQ(1, root->child_count()); |
| 225 ASSERT_EQ(title, new_node->GetTitle()); |
| 226 ASSERT_TRUE(url == new_node->GetURL()); |
| 227 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 228 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); |
| 229 |
| 230 EXPECT_TRUE(new_node->id() != root->id() && |
| 231 new_node->id() != model_->other_node()->id() && |
| 232 new_node->id() != model_->synced_node()->id()); |
| 201 } | 233 } |
| 202 | 234 |
| 203 TEST_F(BookmarkModelTest, AddFolder) { | 235 TEST_F(BookmarkModelTest, AddFolder) { |
| 204 const BookmarkNode* root = model.GetBookmarkBarNode(); | 236 const BookmarkNode* root = model_->GetBookmarkBarNode(); |
| 205 const string16 title(ASCIIToUTF16("foo")); | 237 const string16 title(ASCIIToUTF16("foo")); |
| 206 | 238 |
| 207 const BookmarkNode* new_node = model.AddFolder(root, 0, title); | 239 const BookmarkNode* new_node = model_->AddFolder(root, 0, title); |
| 208 AssertObserverCount(1, 0, 0, 0, 0); | 240 AssertObserverCount(1, 0, 0, 0, 0); |
| 209 observer_details.AssertEquals(root, NULL, 0, -1); | 241 observer_details.AssertEquals(root, NULL, 0, -1); |
| 210 | 242 |
| 211 ASSERT_EQ(1, root->child_count()); | 243 ASSERT_EQ(1, root->child_count()); |
| 212 ASSERT_EQ(title, new_node->GetTitle()); | 244 ASSERT_EQ(title, new_node->GetTitle()); |
| 213 ASSERT_EQ(BookmarkNode::FOLDER, new_node->type()); | 245 ASSERT_EQ(BookmarkNode::FOLDER, new_node->type()); |
| 214 | 246 |
| 215 EXPECT_TRUE(new_node->id() != root->id() && | 247 EXPECT_TRUE(new_node->id() != root->id() && |
| 216 new_node->id() != model.other_node()->id()); | 248 new_node->id() != model_->other_node()->id() && |
| 249 new_node->id() != model_->synced_node()->id()); |
| 217 | 250 |
| 218 // Add another folder, just to make sure folder_ids are incremented correctly. | 251 // Add another folder, just to make sure folder_ids are incremented correctly. |
| 219 ClearCounts(); | 252 ClearCounts(); |
| 220 model.AddFolder(root, 0, title); | 253 model_->AddFolder(root, 0, title); |
| 221 AssertObserverCount(1, 0, 0, 0, 0); | 254 AssertObserverCount(1, 0, 0, 0, 0); |
| 222 observer_details.AssertEquals(root, NULL, 0, -1); | 255 observer_details.AssertEquals(root, NULL, 0, -1); |
| 223 } | 256 } |
| 224 | 257 |
| 225 TEST_F(BookmarkModelTest, RemoveURL) { | 258 TEST_F(BookmarkModelTest, RemoveURL) { |
| 226 const BookmarkNode* root = model.GetBookmarkBarNode(); | 259 const BookmarkNode* root = model_->GetBookmarkBarNode(); |
| 227 const string16 title(ASCIIToUTF16("foo")); | 260 const string16 title(ASCIIToUTF16("foo")); |
| 228 const GURL url("http://foo.com"); | 261 const GURL url("http://foo.com"); |
| 229 model.AddURL(root, 0, title, url); | 262 model_->AddURL(root, 0, title, url); |
| 230 ClearCounts(); | 263 ClearCounts(); |
| 231 | 264 |
| 232 model.Remove(root, 0); | 265 model_->Remove(root, 0); |
| 233 ASSERT_EQ(0, root->child_count()); | 266 ASSERT_EQ(0, root->child_count()); |
| 234 AssertObserverCount(0, 0, 1, 0, 0); | 267 AssertObserverCount(0, 0, 1, 0, 0); |
| 235 observer_details.AssertEquals(root, NULL, 0, -1); | 268 observer_details.AssertEquals(root, NULL, 0, -1); |
| 236 | 269 |
| 237 // Make sure there is no mapping for the URL. | 270 // Make sure there is no mapping for the URL. |
| 238 ASSERT_TRUE(model.GetMostRecentlyAddedNodeForURL(url) == NULL); | 271 ASSERT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); |
| 239 } | 272 } |
| 240 | 273 |
| 241 TEST_F(BookmarkModelTest, RemoveFolder) { | 274 TEST_F(BookmarkModelTest, RemoveFolder) { |
| 242 const BookmarkNode* root = model.GetBookmarkBarNode(); | 275 const BookmarkNode* root = model_->GetBookmarkBarNode(); |
| 243 const BookmarkNode* folder = model.AddFolder(root, 0, ASCIIToUTF16("foo")); | 276 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); |
| 244 | 277 |
| 245 ClearCounts(); | 278 ClearCounts(); |
| 246 | 279 |
| 247 // Add a URL as a child. | 280 // Add a URL as a child. |
| 248 const string16 title(ASCIIToUTF16("foo")); | 281 const string16 title(ASCIIToUTF16("foo")); |
| 249 const GURL url("http://foo.com"); | 282 const GURL url("http://foo.com"); |
| 250 model.AddURL(folder, 0, title, url); | 283 model_->AddURL(folder, 0, title, url); |
| 251 | 284 |
| 252 ClearCounts(); | 285 ClearCounts(); |
| 253 | 286 |
| 254 // Now remove the folder. | 287 // Now remove the folder. |
| 255 model.Remove(root, 0); | 288 model_->Remove(root, 0); |
| 256 ASSERT_EQ(0, root->child_count()); | 289 ASSERT_EQ(0, root->child_count()); |
| 257 AssertObserverCount(0, 0, 1, 0, 0); | 290 AssertObserverCount(0, 0, 1, 0, 0); |
| 258 observer_details.AssertEquals(root, NULL, 0, -1); | 291 observer_details.AssertEquals(root, NULL, 0, -1); |
| 259 | 292 |
| 260 // Make sure there is no mapping for the URL. | 293 // Make sure there is no mapping for the URL. |
| 261 ASSERT_TRUE(model.GetMostRecentlyAddedNodeForURL(url) == NULL); | 294 ASSERT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); |
| 262 } | 295 } |
| 263 | 296 |
| 264 TEST_F(BookmarkModelTest, SetTitle) { | 297 TEST_F(BookmarkModelTest, SetTitle) { |
| 265 const BookmarkNode* root = model.GetBookmarkBarNode(); | 298 const BookmarkNode* root = model_->GetBookmarkBarNode(); |
| 266 string16 title(ASCIIToUTF16("foo")); | 299 string16 title(ASCIIToUTF16("foo")); |
| 267 const GURL url("http://foo.com"); | 300 const GURL url("http://foo.com"); |
| 268 const BookmarkNode* node = model.AddURL(root, 0, title, url); | 301 const BookmarkNode* node = model_->AddURL(root, 0, title, url); |
| 269 | 302 |
| 270 ClearCounts(); | 303 ClearCounts(); |
| 271 | 304 |
| 272 title = ASCIIToUTF16("foo2"); | 305 title = ASCIIToUTF16("foo2"); |
| 273 model.SetTitle(node, title); | 306 model_->SetTitle(node, title); |
| 274 AssertObserverCount(0, 0, 0, 1, 0); | 307 AssertObserverCount(0, 0, 0, 1, 0); |
| 275 observer_details.AssertEquals(node, NULL, -1, -1); | 308 observer_details.AssertEquals(node, NULL, -1, -1); |
| 276 EXPECT_EQ(title, node->GetTitle()); | 309 EXPECT_EQ(title, node->GetTitle()); |
| 277 } | 310 } |
| 278 | 311 |
| 279 TEST_F(BookmarkModelTest, SetURL) { | 312 TEST_F(BookmarkModelTest, SetURL) { |
| 280 const BookmarkNode* root = model.GetBookmarkBarNode(); | 313 const BookmarkNode* root = model_->GetBookmarkBarNode(); |
| 281 const string16 title(ASCIIToUTF16("foo")); | 314 const string16 title(ASCIIToUTF16("foo")); |
| 282 GURL url("http://foo.com"); | 315 GURL url("http://foo.com"); |
| 283 const BookmarkNode* node = model.AddURL(root, 0, title, url); | 316 const BookmarkNode* node = model_->AddURL(root, 0, title, url); |
| 284 | 317 |
| 285 ClearCounts(); | 318 ClearCounts(); |
| 286 | 319 |
| 287 url = GURL("http://foo2.com"); | 320 url = GURL("http://foo2.com"); |
| 288 model.SetURL(node, url); | 321 model_->SetURL(node, url); |
| 289 AssertObserverCount(0, 0, 0, 1, 0); | 322 AssertObserverCount(0, 0, 0, 1, 0); |
| 290 observer_details.AssertEquals(node, NULL, -1, -1); | 323 observer_details.AssertEquals(node, NULL, -1, -1); |
| 291 EXPECT_EQ(url, node->GetURL()); | 324 EXPECT_EQ(url, node->GetURL()); |
| 292 } | 325 } |
| 293 | 326 |
| 294 TEST_F(BookmarkModelTest, Move) { | 327 TEST_F(BookmarkModelTest, Move) { |
| 295 const BookmarkNode* root = model.GetBookmarkBarNode(); | 328 const BookmarkNode* root = model_->GetBookmarkBarNode(); |
| 296 const string16 title(ASCIIToUTF16("foo")); | 329 const string16 title(ASCIIToUTF16("foo")); |
| 297 const GURL url("http://foo.com"); | 330 const GURL url("http://foo.com"); |
| 298 const BookmarkNode* node = model.AddURL(root, 0, title, url); | 331 const BookmarkNode* node = model_->AddURL(root, 0, title, url); |
| 299 const BookmarkNode* folder1 = model.AddFolder(root, 0, ASCIIToUTF16("foo")); | 332 const BookmarkNode* folder1 = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); |
| 300 ClearCounts(); | 333 ClearCounts(); |
| 301 | 334 |
| 302 model.Move(node, folder1, 0); | 335 model_->Move(node, folder1, 0); |
| 303 | 336 |
| 304 AssertObserverCount(0, 1, 0, 0, 0); | 337 AssertObserverCount(0, 1, 0, 0, 0); |
| 305 observer_details.AssertEquals(root, folder1, 1, 0); | 338 observer_details.AssertEquals(root, folder1, 1, 0); |
| 306 EXPECT_TRUE(folder1 == node->parent()); | 339 EXPECT_TRUE(folder1 == node->parent()); |
| 307 EXPECT_EQ(1, root->child_count()); | 340 EXPECT_EQ(1, root->child_count()); |
| 308 EXPECT_EQ(folder1, root->GetChild(0)); | 341 EXPECT_EQ(folder1, root->GetChild(0)); |
| 309 EXPECT_EQ(1, folder1->child_count()); | 342 EXPECT_EQ(1, folder1->child_count()); |
| 310 EXPECT_EQ(node, folder1->GetChild(0)); | 343 EXPECT_EQ(node, folder1->GetChild(0)); |
| 311 | 344 |
| 312 // And remove the folder. | 345 // And remove the folder. |
| 313 ClearCounts(); | 346 ClearCounts(); |
| 314 model.Remove(root, 0); | 347 model_->Remove(root, 0); |
| 315 AssertObserverCount(0, 0, 1, 0, 0); | 348 AssertObserverCount(0, 0, 1, 0, 0); |
| 316 observer_details.AssertEquals(root, NULL, 0, -1); | 349 observer_details.AssertEquals(root, NULL, 0, -1); |
| 317 EXPECT_TRUE(model.GetMostRecentlyAddedNodeForURL(url) == NULL); | 350 EXPECT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); |
| 318 EXPECT_EQ(0, root->child_count()); | 351 EXPECT_EQ(0, root->child_count()); |
| 319 } | 352 } |
| 320 | 353 |
| 321 TEST_F(BookmarkModelTest, Copy) { | 354 TEST_F(BookmarkModelTest, Copy) { |
| 322 const BookmarkNode* root = model.GetBookmarkBarNode(); | 355 const BookmarkNode* root = model_->GetBookmarkBarNode(); |
| 323 static const std::string model_string("a 1:[ b c ] d 2:[ e f g ] h "); | 356 static const std::string model_string("a 1:[ b c ] d 2:[ e f g ] h "); |
| 324 model_test_utils::AddNodesFromModelString(model, root, model_string); | 357 model_test_utils::AddNodesFromModelString(*model_, root, model_string); |
| 325 | 358 |
| 326 // Validate initial model. | 359 // Validate initial model. |
| 327 std::string actualModelString = model_test_utils::ModelStringFromNode(root); | 360 std::string actualModelString = model_test_utils::ModelStringFromNode(root); |
| 328 EXPECT_EQ(model_string, actualModelString); | 361 EXPECT_EQ(model_string, actualModelString); |
| 329 | 362 |
| 330 // Copy 'd' to be after '1:b': URL item from bar to folder. | 363 // Copy 'd' to be after '1:b': URL item from bar to folder. |
| 331 const BookmarkNode* nodeToCopy = root->GetChild(2); | 364 const BookmarkNode* nodeToCopy = root->GetChild(2); |
| 332 const BookmarkNode* destination = root->GetChild(1); | 365 const BookmarkNode* destination = root->GetChild(1); |
| 333 model.Copy(nodeToCopy, destination, 1); | 366 model_->Copy(nodeToCopy, destination, 1); |
| 334 actualModelString = model_test_utils::ModelStringFromNode(root); | 367 actualModelString = model_test_utils::ModelStringFromNode(root); |
| 335 EXPECT_EQ("a 1:[ b d c ] d 2:[ e f g ] h ", actualModelString); | 368 EXPECT_EQ("a 1:[ b d c ] d 2:[ e f g ] h ", actualModelString); |
| 336 | 369 |
| 337 // Copy '1:d' to be after 'a': URL item from folder to bar. | 370 // Copy '1:d' to be after 'a': URL item from folder to bar. |
| 338 const BookmarkNode* folder = root->GetChild(1); | 371 const BookmarkNode* folder = root->GetChild(1); |
| 339 nodeToCopy = folder->GetChild(1); | 372 nodeToCopy = folder->GetChild(1); |
| 340 model.Copy(nodeToCopy, root, 1); | 373 model_->Copy(nodeToCopy, root, 1); |
| 341 actualModelString = model_test_utils::ModelStringFromNode(root); | 374 actualModelString = model_test_utils::ModelStringFromNode(root); |
| 342 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e f g ] h ", actualModelString); | 375 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e f g ] h ", actualModelString); |
| 343 | 376 |
| 344 // Copy '1' to be after '2:e': Folder from bar to folder. | 377 // Copy '1' to be after '2:e': Folder from bar to folder. |
| 345 nodeToCopy = root->GetChild(2); | 378 nodeToCopy = root->GetChild(2); |
| 346 destination = root->GetChild(4); | 379 destination = root->GetChild(4); |
| 347 model.Copy(nodeToCopy, destination, 1); | 380 model_->Copy(nodeToCopy, destination, 1); |
| 348 actualModelString = model_test_utils::ModelStringFromNode(root); | 381 actualModelString = model_test_utils::ModelStringFromNode(root); |
| 349 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f g ] h ", actualModelString); | 382 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f g ] h ", actualModelString); |
| 350 | 383 |
| 351 // Copy '2:1' to be after '2:f': Folder within same folder. | 384 // Copy '2:1' to be after '2:f': Folder within same folder. |
| 352 folder = root->GetChild(4); | 385 folder = root->GetChild(4); |
| 353 nodeToCopy = folder->GetChild(1); | 386 nodeToCopy = folder->GetChild(1); |
| 354 model.Copy(nodeToCopy, folder, 3); | 387 model_->Copy(nodeToCopy, folder, 3); |
| 355 actualModelString = model_test_utils::ModelStringFromNode(root); | 388 actualModelString = model_test_utils::ModelStringFromNode(root); |
| 356 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h ", | 389 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h ", |
| 357 actualModelString); | 390 actualModelString); |
| 358 | 391 |
| 359 // Copy first 'd' to be after 'h': URL item within the bar. | 392 // Copy first 'd' to be after 'h': URL item within the bar. |
| 360 nodeToCopy = root->GetChild(1); | 393 nodeToCopy = root->GetChild(1); |
| 361 model.Copy(nodeToCopy, root, 6); | 394 model_->Copy(nodeToCopy, root, 6); |
| 362 actualModelString = model_test_utils::ModelStringFromNode(root); | 395 actualModelString = model_test_utils::ModelStringFromNode(root); |
| 363 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ", | 396 EXPECT_EQ("a d 1:[ b d c ] d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ", |
| 364 actualModelString); | 397 actualModelString); |
| 365 | 398 |
| 366 // Copy '2' to be after 'a': Folder within the bar. | 399 // Copy '2' to be after 'a': Folder within the bar. |
| 367 nodeToCopy = root->GetChild(4); | 400 nodeToCopy = root->GetChild(4); |
| 368 model.Copy(nodeToCopy, root, 1); | 401 model_->Copy(nodeToCopy, root, 1); |
| 369 actualModelString = model_test_utils::ModelStringFromNode(root); | 402 actualModelString = model_test_utils::ModelStringFromNode(root); |
| 370 EXPECT_EQ("a 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] d 1:[ b d c ] " | 403 EXPECT_EQ("a 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] d 1:[ b d c ] " |
| 371 "d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ", | 404 "d 2:[ e 1:[ b d c ] f 1:[ b d c ] g ] h d ", |
| 372 actualModelString); | 405 actualModelString); |
| 373 } | 406 } |
| 374 | 407 |
| 375 // Tests that adding a URL to a folder updates the last modified time. | 408 // Tests that adding a URL to a folder updates the last modified time. |
| 376 TEST_F(BookmarkModelTest, ParentForNewNodes) { | 409 TEST_F(BookmarkModelTest, ParentForNewNodes) { |
| 377 ASSERT_EQ(model.GetBookmarkBarNode(), model.GetParentForNewNodes()); | 410 ASSERT_EQ(model_->GetBookmarkBarNode(), model_->GetParentForNewNodes()); |
| 378 | 411 |
| 379 const string16 title(ASCIIToUTF16("foo")); | 412 const string16 title(ASCIIToUTF16("foo")); |
| 380 const GURL url("http://foo.com"); | 413 const GURL url("http://foo.com"); |
| 381 | 414 |
| 382 model.AddURL(model.other_node(), 0, title, url); | 415 model_->AddURL(model_->other_node(), 0, title, url); |
| 383 ASSERT_EQ(model.other_node(), model.GetParentForNewNodes()); | 416 ASSERT_EQ(model_->other_node(), model_->GetParentForNewNodes()); |
| 417 } |
| 418 |
| 419 // Tests that adding a URL to a folder updates the last modified time. |
| 420 TEST_F(BookmarkModelTest, ParentForNewSyncedNodes) { |
| 421 ASSERT_EQ(model_->GetBookmarkBarNode(), model_->GetParentForNewNodes()); |
| 422 |
| 423 const string16 title(ASCIIToUTF16("foo")); |
| 424 const GURL url("http://foo.com"); |
| 425 |
| 426 model_->AddURL(model_->synced_node(), 0, title, url); |
| 427 ASSERT_EQ(model_->synced_node(), model_->GetParentForNewNodes()); |
| 384 } | 428 } |
| 385 | 429 |
| 386 // Make sure recently modified stays in sync when adding a URL. | 430 // Make sure recently modified stays in sync when adding a URL. |
| 387 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { | 431 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { |
| 388 // Add a folder. | 432 // Add a folder. |
| 389 const BookmarkNode* folder = model.AddFolder(model.other_node(), 0, | 433 const BookmarkNode* folder = model_->AddFolder(model_->other_node(), 0, |
| 390 ASCIIToUTF16("foo")); | 434 ASCIIToUTF16("foo")); |
| 391 // Add a URL to it. | 435 // Add a URL to it. |
| 392 model.AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); | 436 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); |
| 393 | 437 |
| 394 // Make sure folder is in the most recently modified. | 438 // Make sure folder is in the most recently modified. |
| 395 std::vector<const BookmarkNode*> most_recent_folders = | 439 std::vector<const BookmarkNode*> most_recent_folders = |
| 396 bookmark_utils::GetMostRecentlyModifiedFolders(&model, 1); | 440 bookmark_utils::GetMostRecentlyModifiedFolders(model_.get(), 1); |
| 397 ASSERT_EQ(1U, most_recent_folders.size()); | 441 ASSERT_EQ(1U, most_recent_folders.size()); |
| 398 ASSERT_EQ(folder, most_recent_folders[0]); | 442 ASSERT_EQ(folder, most_recent_folders[0]); |
| 399 | 443 |
| 400 // Nuke the folder and do another fetch, making sure folder isn't in the | 444 // Nuke the folder and do another fetch, making sure folder isn't in the |
| 401 // returned list. | 445 // returned list. |
| 402 model.Remove(folder->parent(), 0); | 446 model_->Remove(folder->parent(), 0); |
| 403 most_recent_folders = | 447 most_recent_folders = |
| 404 bookmark_utils::GetMostRecentlyModifiedFolders(&model, 1); | 448 bookmark_utils::GetMostRecentlyModifiedFolders(model_.get(), 1); |
| 405 ASSERT_EQ(1U, most_recent_folders.size()); | 449 ASSERT_EQ(1U, most_recent_folders.size()); |
| 406 ASSERT_TRUE(most_recent_folders[0] != folder); | 450 ASSERT_TRUE(most_recent_folders[0] != folder); |
| 407 } | 451 } |
| 408 | 452 |
| 409 // Make sure MostRecentlyAddedEntries stays in sync. | 453 // Make sure MostRecentlyAddedEntries stays in sync. |
| 410 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { | 454 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { |
| 411 // Add a couple of nodes such that the following holds for the time of the | 455 // Add a couple of nodes such that the following holds for the time of the |
| 412 // nodes: n1 > n2 > n3 > n4. | 456 // nodes: n1 > n2 > n3 > n4. |
| 413 Time base_time = Time::Now(); | 457 Time base_time = Time::Now(); |
| 414 BookmarkNode* n1 = AsMutable(model.AddURL(model.GetBookmarkBarNode(), | 458 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->GetBookmarkBarNode(), |
| 415 0, | 459 0, |
| 416 ASCIIToUTF16("blah"), | 460 ASCIIToUTF16("blah"), |
| 417 GURL("http://foo.com/0"))); | 461 GURL("http://foo.com/0"))); |
| 418 BookmarkNode* n2 = AsMutable(model.AddURL(model.GetBookmarkBarNode(), | 462 BookmarkNode* n2 = AsMutable(model_->AddURL(model_->GetBookmarkBarNode(), |
| 419 1, | 463 1, |
| 420 ASCIIToUTF16("blah"), | 464 ASCIIToUTF16("blah"), |
| 421 GURL("http://foo.com/1"))); | 465 GURL("http://foo.com/1"))); |
| 422 BookmarkNode* n3 = AsMutable(model.AddURL(model.GetBookmarkBarNode(), | 466 BookmarkNode* n3 = AsMutable(model_->AddURL(model_->GetBookmarkBarNode(), |
| 423 2, | 467 2, |
| 424 ASCIIToUTF16("blah"), | 468 ASCIIToUTF16("blah"), |
| 425 GURL("http://foo.com/2"))); | 469 GURL("http://foo.com/2"))); |
| 426 BookmarkNode* n4 = AsMutable(model.AddURL(model.GetBookmarkBarNode(), | 470 BookmarkNode* n4 = AsMutable(model_->AddURL(model_->GetBookmarkBarNode(), |
| 427 3, | 471 3, |
| 428 ASCIIToUTF16("blah"), | 472 ASCIIToUTF16("blah"), |
| 429 GURL("http://foo.com/3"))); | 473 GURL("http://foo.com/3"))); |
| 430 n1->set_date_added(base_time + TimeDelta::FromDays(4)); | 474 n1->set_date_added(base_time + TimeDelta::FromDays(4)); |
| 431 n2->set_date_added(base_time + TimeDelta::FromDays(3)); | 475 n2->set_date_added(base_time + TimeDelta::FromDays(3)); |
| 432 n3->set_date_added(base_time + TimeDelta::FromDays(2)); | 476 n3->set_date_added(base_time + TimeDelta::FromDays(2)); |
| 433 n4->set_date_added(base_time + TimeDelta::FromDays(1)); | 477 n4->set_date_added(base_time + TimeDelta::FromDays(1)); |
| 434 | 478 |
| 435 // Make sure order is honored. | 479 // Make sure order is honored. |
| 436 std::vector<const BookmarkNode*> recently_added; | 480 std::vector<const BookmarkNode*> recently_added; |
| 437 bookmark_utils::GetMostRecentlyAddedEntries(&model, 2, &recently_added); | 481 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 2, &recently_added); |
| 438 ASSERT_EQ(2U, recently_added.size()); | 482 ASSERT_EQ(2U, recently_added.size()); |
| 439 ASSERT_TRUE(n1 == recently_added[0]); | 483 ASSERT_TRUE(n1 == recently_added[0]); |
| 440 ASSERT_TRUE(n2 == recently_added[1]); | 484 ASSERT_TRUE(n2 == recently_added[1]); |
| 441 | 485 |
| 442 // swap 1 and 2, then check again. | 486 // swap 1 and 2, then check again. |
| 443 recently_added.clear(); | 487 recently_added.clear(); |
| 444 SwapDateAdded(n1, n2); | 488 SwapDateAdded(n1, n2); |
| 445 bookmark_utils::GetMostRecentlyAddedEntries(&model, 4, &recently_added); | 489 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); |
| 446 ASSERT_EQ(4U, recently_added.size()); | 490 ASSERT_EQ(4U, recently_added.size()); |
| 447 ASSERT_TRUE(n2 == recently_added[0]); | 491 ASSERT_TRUE(n2 == recently_added[0]); |
| 448 ASSERT_TRUE(n1 == recently_added[1]); | 492 ASSERT_TRUE(n1 == recently_added[1]); |
| 449 ASSERT_TRUE(n3 == recently_added[2]); | 493 ASSERT_TRUE(n3 == recently_added[2]); |
| 450 ASSERT_TRUE(n4 == recently_added[3]); | 494 ASSERT_TRUE(n4 == recently_added[3]); |
| 451 } | 495 } |
| 452 | 496 |
| 453 // Makes sure GetMostRecentlyAddedNodeForURL stays in sync. | 497 // Makes sure GetMostRecentlyAddedNodeForURL stays in sync. |
| 454 TEST_F(BookmarkModelTest, GetMostRecentlyAddedNodeForURL) { | 498 TEST_F(BookmarkModelTest, GetMostRecentlyAddedNodeForURL) { |
| 455 // Add a couple of nodes such that the following holds for the time of the | 499 // Add a couple of nodes such that the following holds for the time of the |
| 456 // nodes: n1 > n2 | 500 // nodes: n1 > n2 |
| 457 Time base_time = Time::Now(); | 501 Time base_time = Time::Now(); |
| 458 const GURL url("http://foo.com/0"); | 502 const GURL url("http://foo.com/0"); |
| 459 BookmarkNode* n1 = AsMutable(model.AddURL( | 503 BookmarkNode* n1 = AsMutable(model_->AddURL( |
| 460 model.GetBookmarkBarNode(), 0, ASCIIToUTF16("blah"), url)); | 504 model_->GetBookmarkBarNode(), 0, ASCIIToUTF16("blah"), url)); |
| 461 BookmarkNode* n2 = AsMutable(model.AddURL( | 505 BookmarkNode* n2 = AsMutable(model_->AddURL( |
| 462 model.GetBookmarkBarNode(), 1, ASCIIToUTF16("blah"), url)); | 506 model_->GetBookmarkBarNode(), 1, ASCIIToUTF16("blah"), url)); |
| 463 n1->set_date_added(base_time + TimeDelta::FromDays(4)); | 507 n1->set_date_added(base_time + TimeDelta::FromDays(4)); |
| 464 n2->set_date_added(base_time + TimeDelta::FromDays(3)); | 508 n2->set_date_added(base_time + TimeDelta::FromDays(3)); |
| 465 | 509 |
| 466 // Make sure order is honored. | 510 // Make sure order is honored. |
| 467 ASSERT_EQ(n1, model.GetMostRecentlyAddedNodeForURL(url)); | 511 ASSERT_EQ(n1, model_->GetMostRecentlyAddedNodeForURL(url)); |
| 468 | 512 |
| 469 // swap 1 and 2, then check again. | 513 // swap 1 and 2, then check again. |
| 470 SwapDateAdded(n1, n2); | 514 SwapDateAdded(n1, n2); |
| 471 ASSERT_EQ(n2, model.GetMostRecentlyAddedNodeForURL(url)); | 515 ASSERT_EQ(n2, model_->GetMostRecentlyAddedNodeForURL(url)); |
| 472 } | 516 } |
| 473 | 517 |
| 474 // Makes sure GetBookmarks removes duplicates. | 518 // Makes sure GetBookmarks removes duplicates. |
| 475 TEST_F(BookmarkModelTest, GetBookmarksWithDups) { | 519 TEST_F(BookmarkModelTest, GetBookmarksWithDups) { |
| 476 const GURL url("http://foo.com/0"); | 520 const GURL url("http://foo.com/0"); |
| 477 model.AddURL(model.GetBookmarkBarNode(), 0, ASCIIToUTF16("blah"), url); | 521 model_->AddURL(model_->GetBookmarkBarNode(), 0, ASCIIToUTF16("blah"), url); |
| 478 model.AddURL(model.GetBookmarkBarNode(), 1, ASCIIToUTF16("blah"), url); | 522 model_->AddURL(model_->GetBookmarkBarNode(), 1, ASCIIToUTF16("blah"), url); |
| 479 | 523 |
| 480 std::vector<GURL> urls; | 524 std::vector<GURL> urls; |
| 481 model.GetBookmarks(&urls); | 525 model_->GetBookmarks(&urls); |
| 482 EXPECT_EQ(1U, urls.size()); | 526 EXPECT_EQ(1U, urls.size()); |
| 483 ASSERT_TRUE(urls[0] == url); | 527 ASSERT_TRUE(urls[0] == url); |
| 484 } | 528 } |
| 485 | 529 |
| 486 TEST_F(BookmarkModelTest, HasBookmarks) { | 530 TEST_F(BookmarkModelTest, HasBookmarks) { |
| 487 const GURL url("http://foo.com/"); | 531 const GURL url("http://foo.com/"); |
| 488 model.AddURL(model.GetBookmarkBarNode(), 0, ASCIIToUTF16("bar"), url); | 532 model_->AddURL(model_->GetBookmarkBarNode(), 0, ASCIIToUTF16("bar"), url); |
| 489 | 533 |
| 490 EXPECT_TRUE(model.HasBookmarks()); | 534 EXPECT_TRUE(model_->HasBookmarks()); |
| 491 } | 535 } |
| 492 | 536 |
| 493 namespace { | 537 namespace { |
| 494 | 538 |
| 495 // NotificationObserver implementation used in verifying we've received the | 539 // NotificationObserver implementation used in verifying we've received the |
| 496 // NOTIFY_URLS_STARRED method correctly. | 540 // NOTIFY_URLS_STARRED method correctly. |
| 497 class StarredListener : public NotificationObserver { | 541 class StarredListener : public NotificationObserver { |
| 498 public: | 542 public: |
| 499 StarredListener() : notification_count_(0), details_(false) { | 543 StarredListener() : notification_count_(0), details_(false) { |
| 500 registrar_.Add(this, NotificationType::URLS_STARRED, Source<Profile>(NULL)); | 544 registrar_.Add(this, NotificationType::URLS_STARRED, Source<Profile>(NULL)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 520 | 564 |
| 521 DISALLOW_COPY_AND_ASSIGN(StarredListener); | 565 DISALLOW_COPY_AND_ASSIGN(StarredListener); |
| 522 }; | 566 }; |
| 523 | 567 |
| 524 } // namespace | 568 } // namespace |
| 525 | 569 |
| 526 // Makes sure NOTIFY_URLS_STARRED is sent correctly. | 570 // Makes sure NOTIFY_URLS_STARRED is sent correctly. |
| 527 TEST_F(BookmarkModelTest, NotifyURLsStarred) { | 571 TEST_F(BookmarkModelTest, NotifyURLsStarred) { |
| 528 StarredListener listener; | 572 StarredListener listener; |
| 529 const GURL url("http://foo.com/0"); | 573 const GURL url("http://foo.com/0"); |
| 530 const BookmarkNode* n1 = model.AddURL( | 574 const BookmarkNode* n1 = model_->AddURL( |
| 531 model.GetBookmarkBarNode(), 0, ASCIIToUTF16("blah"), url); | 575 model_->GetBookmarkBarNode(), 0, ASCIIToUTF16("blah"), url); |
| 532 | 576 |
| 533 // Starred notification should be sent. | 577 // Starred notification should be sent. |
| 534 EXPECT_EQ(1, listener.notification_count_); | 578 EXPECT_EQ(1, listener.notification_count_); |
| 535 ASSERT_TRUE(listener.details_.starred); | 579 ASSERT_TRUE(listener.details_.starred); |
| 536 ASSERT_EQ(1U, listener.details_.changed_urls.size()); | 580 ASSERT_EQ(1U, listener.details_.changed_urls.size()); |
| 537 EXPECT_TRUE(url == *(listener.details_.changed_urls.begin())); | 581 EXPECT_TRUE(url == *(listener.details_.changed_urls.begin())); |
| 538 listener.notification_count_ = 0; | 582 listener.notification_count_ = 0; |
| 539 listener.details_.changed_urls.clear(); | 583 listener.details_.changed_urls.clear(); |
| 540 | 584 |
| 541 // Add another bookmark for the same URL. This should not send any | 585 // Add another bookmark for the same URL. This should not send any |
| 542 // notification. | 586 // notification. |
| 543 const BookmarkNode* n2 = model.AddURL( | 587 const BookmarkNode* n2 = model_->AddURL( |
| 544 model.GetBookmarkBarNode(), 1, ASCIIToUTF16("blah"), url); | 588 model_->GetBookmarkBarNode(), 1, ASCIIToUTF16("blah"), url); |
| 545 | 589 |
| 546 EXPECT_EQ(0, listener.notification_count_); | 590 EXPECT_EQ(0, listener.notification_count_); |
| 547 | 591 |
| 548 // Remove n2. | 592 // Remove n2. |
| 549 model.Remove(n2->parent(), 1); | 593 model_->Remove(n2->parent(), 1); |
| 550 n2 = NULL; | 594 n2 = NULL; |
| 551 | 595 |
| 552 // Shouldn't have received any notification as n1 still exists with the same | 596 // Shouldn't have received any notification as n1 still exists with the same |
| 553 // URL. | 597 // URL. |
| 554 EXPECT_EQ(0, listener.notification_count_); | 598 EXPECT_EQ(0, listener.notification_count_); |
| 555 | 599 |
| 556 EXPECT_TRUE(model.GetMostRecentlyAddedNodeForURL(url) == n1); | 600 EXPECT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == n1); |
| 557 | 601 |
| 558 // Remove n1. | 602 // Remove n1. |
| 559 model.Remove(n1->parent(), 0); | 603 model_->Remove(n1->parent(), 0); |
| 560 | 604 |
| 561 // Now we should get the notification. | 605 // Now we should get the notification. |
| 562 EXPECT_EQ(1, listener.notification_count_); | 606 EXPECT_EQ(1, listener.notification_count_); |
| 563 ASSERT_FALSE(listener.details_.starred); | 607 ASSERT_FALSE(listener.details_.starred); |
| 564 ASSERT_EQ(1U, listener.details_.changed_urls.size()); | 608 ASSERT_EQ(1U, listener.details_.changed_urls.size()); |
| 565 EXPECT_TRUE(url == *(listener.details_.changed_urls.begin())); | 609 EXPECT_TRUE(url == *(listener.details_.changed_urls.begin())); |
| 566 } | 610 } |
| 567 | 611 |
| 568 namespace { | 612 namespace { |
| 569 | 613 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 797 |
| 754 // Creates a set of nodes in the bookmark bar model, then recreates the | 798 // Creates a set of nodes in the bookmark bar model, then recreates the |
| 755 // bookmark bar model which triggers loading from the db and checks the loaded | 799 // bookmark bar model which triggers loading from the db and checks the loaded |
| 756 // structure to make sure it is what we first created. | 800 // structure to make sure it is what we first created. |
| 757 TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) { | 801 TEST_F(BookmarkModelTestWithProfile, CreateAndRestore) { |
| 758 struct TestData { | 802 struct TestData { |
| 759 // Structure of the children of the bookmark bar model node. | 803 // Structure of the children of the bookmark bar model node. |
| 760 const std::string bbn_contents; | 804 const std::string bbn_contents; |
| 761 // Structure of the children of the other node. | 805 // Structure of the children of the other node. |
| 762 const std::string other_contents; | 806 const std::string other_contents; |
| 807 // Structure of the children of the synced node. |
| 808 const std::string synced_contents; |
| 763 } data[] = { | 809 } data[] = { |
| 764 // See PopulateNodeFromString for a description of these strings. | 810 // See PopulateNodeFromString for a description of these strings. |
| 765 { "", "" }, | 811 { "", "" }, |
| 766 { "a", "b" }, | 812 { "a", "b" }, |
| 767 { "a [ b ]", "" }, | 813 { "a [ b ]", "" }, |
| 768 { "", "[ b ] a [ c [ d e [ f ] ] ]" }, | 814 { "", "[ b ] a [ c [ d e [ f ] ] ]" }, |
| 769 { "a [ b ]", "" }, | 815 { "a [ b ]", "" }, |
| 770 { "a b c [ d e [ f ] ]", "g h i [ j k [ l ] ]"}, | 816 { "a b c [ d e [ f ] ]", "g h i [ j k [ l ] ]"}, |
| 771 }; | 817 }; |
| 772 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 818 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { |
| 773 // Recreate the profile. We need to reset with NULL first so that the last | 819 // Recreate the profile. We need to reset with NULL first so that the last |
| 774 // HistoryService releases the locks on the files it creates and we can | 820 // HistoryService releases the locks on the files it creates and we can |
| 775 // delete them. | 821 // delete them. |
| 776 profile_.reset(NULL); | 822 profile_.reset(NULL); |
| 777 profile_.reset(new TestingProfile()); | 823 profile_.reset(new TestingProfile()); |
| 778 profile_->CreateBookmarkModel(true); | 824 profile_->CreateBookmarkModel(true); |
| 779 profile_->CreateHistoryService(true, false); | 825 profile_->CreateHistoryService(true, false); |
| 780 BlockTillBookmarkModelLoaded(); | 826 BlockTillBookmarkModelLoaded(); |
| 781 | 827 |
| 782 TestNode bbn; | 828 TestNode bbn; |
| 783 PopulateNodeFromString(data[i].bbn_contents, &bbn); | 829 PopulateNodeFromString(data[i].bbn_contents, &bbn); |
| 784 PopulateBookmarkNode(&bbn, bb_model_, bb_model_->GetBookmarkBarNode()); | 830 PopulateBookmarkNode(&bbn, bb_model_, bb_model_->GetBookmarkBarNode()); |
| 785 | 831 |
| 786 TestNode other; | 832 TestNode other; |
| 787 PopulateNodeFromString(data[i].other_contents, &other); | 833 PopulateNodeFromString(data[i].other_contents, &other); |
| 788 PopulateBookmarkNode(&other, bb_model_, bb_model_->other_node()); | 834 PopulateBookmarkNode(&other, bb_model_, bb_model_->other_node()); |
| 789 | 835 |
| 836 TestNode synced; |
| 837 PopulateNodeFromString(data[i].synced_contents, &synced); |
| 838 PopulateBookmarkNode(&synced, bb_model_, bb_model_->synced_node()); |
| 839 |
| 790 profile_->CreateBookmarkModel(false); | 840 profile_->CreateBookmarkModel(false); |
| 791 BlockTillBookmarkModelLoaded(); | 841 BlockTillBookmarkModelLoaded(); |
| 792 | 842 |
| 793 VerifyModelMatchesNode(&bbn, bb_model_->GetBookmarkBarNode()); | 843 VerifyModelMatchesNode(&bbn, bb_model_->GetBookmarkBarNode()); |
| 794 VerifyModelMatchesNode(&other, bb_model_->other_node()); | 844 VerifyModelMatchesNode(&other, bb_model_->other_node()); |
| 845 VerifyModelMatchesNode(&synced, bb_model_->synced_node()); |
| 795 VerifyNoDuplicateIDs(bb_model_); | 846 VerifyNoDuplicateIDs(bb_model_); |
| 796 } | 847 } |
| 797 } | 848 } |
| 798 | 849 |
| 799 // Test class that creates a BookmarkModel with a real history backend. | 850 // Test class that creates a BookmarkModel with a real history backend. |
| 800 class BookmarkModelTestWithProfile2 : public BookmarkModelTestWithProfile { | 851 class BookmarkModelTestWithProfile2 : public BookmarkModelTestWithProfile { |
| 801 public: | 852 public: |
| 802 virtual void SetUp() { | 853 virtual void SetUp() { |
| 803 profile_.reset(new TestingProfile()); | 854 profile_.reset(new TestingProfile()); |
| 804 } | 855 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 ASSERT_TRUE(child->is_folder()); | 905 ASSERT_TRUE(child->is_folder()); |
| 855 ASSERT_EQ(ASCIIToUTF16("OF1"), child->GetTitle()); | 906 ASSERT_EQ(ASCIIToUTF16("OF1"), child->GetTitle()); |
| 856 ASSERT_EQ(0, child->child_count()); | 907 ASSERT_EQ(0, child->child_count()); |
| 857 | 908 |
| 858 child = parent->GetChild(1); | 909 child = parent->GetChild(1); |
| 859 ASSERT_EQ(BookmarkNode::URL, child->type()); | 910 ASSERT_EQ(BookmarkNode::URL, child->type()); |
| 860 ASSERT_EQ(ASCIIToUTF16("About Google"), child->GetTitle()); | 911 ASSERT_EQ(ASCIIToUTF16("About Google"), child->GetTitle()); |
| 861 ASSERT_TRUE(child->GetURL() == | 912 ASSERT_TRUE(child->GetURL() == |
| 862 GURL("http://www.google.com/intl/en/about.html")); | 913 GURL("http://www.google.com/intl/en/about.html")); |
| 863 | 914 |
| 915 parent = bb_model_->synced_node(); |
| 916 ASSERT_EQ(0, parent->child_count()); |
| 917 |
| 864 ASSERT_TRUE(bb_model_->IsBookmarked(GURL("http://www.google.com"))); | 918 ASSERT_TRUE(bb_model_->IsBookmarked(GURL("http://www.google.com"))); |
| 865 } | 919 } |
| 866 | 920 |
| 867 void VerifyUniqueIDs() { | 921 void VerifyUniqueIDs() { |
| 868 std::set<int64> ids; | 922 std::set<int64> ids; |
| 869 bool has_unique = true; | 923 bool has_unique = true; |
| 870 VerifyUniqueIDImpl(bb_model_->GetBookmarkBarNode(), &ids, &has_unique); | 924 VerifyUniqueIDImpl(bb_model_->GetBookmarkBarNode(), &ids, &has_unique); |
| 871 VerifyUniqueIDImpl(bb_model_->other_node(), &ids, &has_unique); | 925 VerifyUniqueIDImpl(bb_model_->other_node(), &ids, &has_unique); |
| 872 ASSERT_TRUE(has_unique); | 926 ASSERT_TRUE(has_unique); |
| 873 } | 927 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 // This won't actually delete the URL, rather it'll empty out the visits. | 1017 // This won't actually delete the URL, rather it'll empty out the visits. |
| 964 // This triggers blocking on the BookmarkModel. | 1018 // This triggers blocking on the BookmarkModel. |
| 965 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->DeleteURL(url); | 1019 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->DeleteURL(url); |
| 966 } | 1020 } |
| 967 | 1021 |
| 968 TEST_F(BookmarkModelTest, Sort) { | 1022 TEST_F(BookmarkModelTest, Sort) { |
| 969 // Populate the bookmark bar node with nodes for 'B', 'a', 'd' and 'C'. | 1023 // Populate the bookmark bar node with nodes for 'B', 'a', 'd' and 'C'. |
| 970 // 'C' and 'a' are folders. | 1024 // 'C' and 'a' are folders. |
| 971 TestNode bbn; | 1025 TestNode bbn; |
| 972 PopulateNodeFromString("B [ a ] d [ a ]", &bbn); | 1026 PopulateNodeFromString("B [ a ] d [ a ]", &bbn); |
| 973 const BookmarkNode* parent = model.GetBookmarkBarNode(); | 1027 const BookmarkNode* parent = model_->GetBookmarkBarNode(); |
| 974 PopulateBookmarkNode(&bbn, &model, parent); | 1028 PopulateBookmarkNode(&bbn, model_.get(), parent); |
| 975 | 1029 |
| 976 BookmarkNode* child1 = AsMutable(parent->GetChild(1)); | 1030 BookmarkNode* child1 = AsMutable(parent->GetChild(1)); |
| 977 child1->set_title(ASCIIToUTF16("a")); | 1031 child1->set_title(ASCIIToUTF16("a")); |
| 978 delete child1->Remove(child1->GetChild(0)); | 1032 delete child1->Remove(child1->GetChild(0)); |
| 979 BookmarkNode* child3 = AsMutable(parent->GetChild(3)); | 1033 BookmarkNode* child3 = AsMutable(parent->GetChild(3)); |
| 980 child3->set_title(ASCIIToUTF16("C")); | 1034 child3->set_title(ASCIIToUTF16("C")); |
| 981 delete child3->Remove(child3->GetChild(0)); | 1035 delete child3->Remove(child3->GetChild(0)); |
| 982 | 1036 |
| 983 ClearCounts(); | 1037 ClearCounts(); |
| 984 | 1038 |
| 985 // Sort the children of the bookmark bar node. | 1039 // Sort the children of the bookmark bar node. |
| 986 model.SortChildren(parent); | 1040 model_->SortChildren(parent); |
| 987 | 1041 |
| 988 // Make sure we were notified. | 1042 // Make sure we were notified. |
| 989 AssertObserverCount(0, 0, 0, 0, 1); | 1043 AssertObserverCount(0, 0, 0, 0, 1); |
| 990 | 1044 |
| 991 // Make sure the order matches (remember, 'a' and 'C' are folders and | 1045 // Make sure the order matches (remember, 'a' and 'C' are folders and |
| 992 // come first). | 1046 // come first). |
| 993 EXPECT_EQ(parent->GetChild(0)->GetTitle(), ASCIIToUTF16("a")); | 1047 EXPECT_EQ(parent->GetChild(0)->GetTitle(), ASCIIToUTF16("a")); |
| 994 EXPECT_EQ(parent->GetChild(1)->GetTitle(), ASCIIToUTF16("C")); | 1048 EXPECT_EQ(parent->GetChild(1)->GetTitle(), ASCIIToUTF16("C")); |
| 995 EXPECT_EQ(parent->GetChild(2)->GetTitle(), ASCIIToUTF16("B")); | 1049 EXPECT_EQ(parent->GetChild(2)->GetTitle(), ASCIIToUTF16("B")); |
| 996 EXPECT_EQ(parent->GetChild(3)->GetTitle(), ASCIIToUTF16("d")); | 1050 EXPECT_EQ(parent->GetChild(3)->GetTitle(), ASCIIToUTF16("d")); |
| 997 } | 1051 } |
| OLD | NEW |