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