| OLD | NEW | 
|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "app/table_model_observer.h" | 5 #include "app/table_model_observer.h" | 
|  | 6 #include "base/message_loop.h" | 
| 6 #include "base/string_util.h" | 7 #include "base/string_util.h" | 
| 7 #include "base/time.h" | 8 #include "base/time.h" | 
| 8 #include "chrome/browser/bookmarks/bookmark_table_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_table_model.h" | 
|  | 10 #include "chrome/browser/chrome_thread.h" | 
| 9 #include "chrome/test/testing_profile.h" | 11 #include "chrome/test/testing_profile.h" | 
| 10 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" | 
| 11 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" | 
| 12 | 14 | 
| 13 using base::Time; | 15 using base::Time; | 
| 14 using base::TimeDelta; | 16 using base::TimeDelta; | 
| 15 | 17 | 
| 16 // Base class for bookmark model tests. | 18 // Base class for bookmark model tests. | 
| 17 // Initial state of the bookmark model is as follows: | 19 // Initial state of the bookmark model is as follows: | 
| 18 // bb | 20 // bb | 
| 19 //   url1 (t0) | 21 //   url1 (t0) | 
| 20 //   f1 | 22 //   f1 | 
| 21 // o | 23 // o | 
| 22 //   url2 (t0 + 2) | 24 //   url2 (t0 + 2) | 
| 23 //   f2 | 25 //   f2 | 
| 24 //   url3 (t0 + 1) | 26 //   url3 (t0 + 1) | 
| 25 class BookmarkTableModelTest : public testing::Test, | 27 class BookmarkTableModelTest : public testing::Test, | 
| 26                                public TableModelObserver { | 28                                public TableModelObserver { | 
| 27  public: | 29  public: | 
| 28   BookmarkTableModelTest() | 30   BookmarkTableModelTest() | 
| 29       : url1_("http://1"), | 31       : url1_("http://1"), | 
| 30         url2_("http://2"), | 32         url2_("http://2"), | 
| 31         url3_("http://3"), | 33         url3_("http://3"), | 
| 32         changed_count_(0), | 34         changed_count_(0), | 
| 33         item_changed_count_(0), | 35         item_changed_count_(0), | 
| 34         added_count_(0), | 36         added_count_(0), | 
| 35         removed_count_(0) { | 37         removed_count_(0), | 
|  | 38         ui_thread_(ChromeThread::UI, &loop_), | 
|  | 39         file_thread_(ChromeThread::FILE, &loop_) { | 
| 36   } | 40   } | 
| 37 | 41 | 
| 38   virtual void SetUp() { | 42   virtual void SetUp() { | 
| 39     profile_.reset(new TestingProfile()); | 43     profile_.reset(new TestingProfile()); | 
| 40     profile_->CreateBookmarkModel(true); | 44     profile_->CreateBookmarkModel(true); | 
|  | 45     profile_->BlockUntilBookmarkModelLoaded(); | 
| 41     // Populate with some default data. | 46     // Populate with some default data. | 
| 42     Time t0 = Time::Now(); | 47     Time t0 = Time::Now(); | 
| 43     const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode(); | 48     const BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode(); | 
| 44     bookmark_model()->AddURLWithCreationTime(bb, 0, L"a", url1_, t0); | 49     bookmark_model()->AddURLWithCreationTime(bb, 0, L"a", url1_, t0); | 
| 45     bookmark_model()->AddGroup(bb, 1, L"f1"); | 50     bookmark_model()->AddGroup(bb, 1, L"f1"); | 
| 46 | 51 | 
| 47     const BookmarkNode* other = bookmark_model()->other_node(); | 52     const BookmarkNode* other = bookmark_model()->other_node(); | 
| 48     bookmark_model()->AddURLWithCreationTime(other, 0, L"b", | 53     bookmark_model()->AddURLWithCreationTime(other, 0, L"b", | 
| 49         url2_, t0 + TimeDelta::FromDays(2)); | 54         url2_, t0 + TimeDelta::FromDays(2)); | 
| 50     bookmark_model()->AddGroup(other, 1, L"f2"); | 55     bookmark_model()->AddGroup(other, 1, L"f2"); | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 103   const GURL url1_; | 108   const GURL url1_; | 
| 104   const GURL url2_; | 109   const GURL url2_; | 
| 105   const GURL url3_; | 110   const GURL url3_; | 
| 106 | 111 | 
| 107  private: | 112  private: | 
| 108   int changed_count_; | 113   int changed_count_; | 
| 109   int item_changed_count_; | 114   int item_changed_count_; | 
| 110   int added_count_; | 115   int added_count_; | 
| 111   int removed_count_; | 116   int removed_count_; | 
| 112   scoped_ptr<TestingProfile> profile_; | 117   scoped_ptr<TestingProfile> profile_; | 
|  | 118   MessageLoop loop_; | 
|  | 119   ChromeThread ui_thread_; | 
|  | 120   ChromeThread file_thread_; | 
| 113 }; | 121 }; | 
| 114 | 122 | 
| 115 // Verifies the count when showing various nodes. | 123 // Verifies the count when showing various nodes. | 
| 116 TEST_F(BookmarkTableModelTest, FolderInitialState) { | 124 TEST_F(BookmarkTableModelTest, FolderInitialState) { | 
| 117   SetModel(BookmarkTableModel::CreateBookmarkTableModelForFolder( | 125   SetModel(BookmarkTableModel::CreateBookmarkTableModelForFolder( | 
| 118       bookmark_model(), bookmark_model()->GetBookmarkBarNode())); | 126       bookmark_model(), bookmark_model()->GetBookmarkBarNode())); | 
| 119   ASSERT_EQ(2, model_->RowCount()); | 127   ASSERT_EQ(2, model_->RowCount()); | 
| 120   EXPECT_TRUE(bookmark_model()->GetBookmarkBarNode()->GetChild(0) == | 128   EXPECT_TRUE(bookmark_model()->GetBookmarkBarNode()->GetChild(0) == | 
| 121               model_->GetNodeForRow(0)); | 129               model_->GetNodeForRow(0)); | 
| 122   EXPECT_TRUE(bookmark_model()->GetBookmarkBarNode()->GetChild(1) == | 130   EXPECT_TRUE(bookmark_model()->GetBookmarkBarNode()->GetChild(1) == | 
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 312   // Change a folder, this shouldn't change the model. | 320   // Change a folder, this shouldn't change the model. | 
| 313   bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(1), | 321   bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(1), | 
| 314                              L"new"); | 322                              L"new"); | 
| 315   VerifyAndClearOberserverCounts(0, 0, 0, 0); | 323   VerifyAndClearOberserverCounts(0, 0, 0, 0); | 
| 316 | 324 | 
| 317   // Change a url that isn't in the model, this shouldn't send change. | 325   // Change a url that isn't in the model, this shouldn't send change. | 
| 318   bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(0), | 326   bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(0), | 
| 319                              L"new"); | 327                              L"new"); | 
| 320   VerifyAndClearOberserverCounts(0, 0, 0, 0); | 328   VerifyAndClearOberserverCounts(0, 0, 0, 0); | 
| 321 } | 329 } | 
| OLD | NEW | 
|---|