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