| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string> | 5 #include <string> |
| 6 #include <set> | 6 #include <set> |
| 7 | 7 |
| 8 #include "base/base_paths.h" | 8 #include "base/base_paths.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/hash_tables.h" | 10 #include "base/hash_tables.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_codec.h" | 17 #include "chrome/browser/bookmarks/bookmark_codec.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_model.h" | 18 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_utils.h" | 19 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 20 #include "chrome/browser/browser_thread.h" | 20 #include "chrome/browser/browser_thread.h" |
| 21 #include "chrome/browser/history/history_notifications.h" | 21 #include "chrome/browser/history/history_notifications.h" |
| 22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/notification_details.h" | 24 #include "chrome/common/notification_details.h" |
| 25 #include "chrome/common/notification_registrar.h" | 25 #include "chrome/common/notification_registrar.h" |
| 26 #include "chrome/common/notification_source.h" | 26 #include "chrome/common/notification_source.h" |
| 27 #include "chrome/test/model_test_utils.h" | 27 #include "chrome/test/model_test_utils.h" |
| 28 #include "chrome/test/testing_browser_process_test.h" |
| 28 #include "chrome/test/testing_profile.h" | 29 #include "chrome/test/testing_profile.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 30 #include "ui/base/models/tree_node_model.h" | 31 #include "ui/base/models/tree_node_model.h" |
| 31 #include "ui/base/models/tree_node_iterator.h" | 32 #include "ui/base/models/tree_node_iterator.h" |
| 32 | 33 |
| 33 using base::Time; | 34 using base::Time; |
| 34 using base::TimeDelta; | 35 using base::TimeDelta; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // Helper to get a mutable bookmark node. | 39 // Helper to get a mutable bookmark node. |
| 39 static BookmarkNode* AsMutable(const BookmarkNode* node) { | 40 static BookmarkNode* AsMutable(const BookmarkNode* node) { |
| 40 return const_cast<BookmarkNode*>(node); | 41 return const_cast<BookmarkNode*>(node); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void SwapDateAdded(BookmarkNode* n1, BookmarkNode* n2) { | 44 void SwapDateAdded(BookmarkNode* n1, BookmarkNode* n2) { |
| 44 Time tmp = n1->date_added(); | 45 Time tmp = n1->date_added(); |
| 45 n1->set_date_added(n2->date_added()); | 46 n1->set_date_added(n2->date_added()); |
| 46 n2->set_date_added(tmp); | 47 n2->set_date_added(tmp); |
| 47 } | 48 } |
| 48 | 49 |
| 49 } // anonymous namespace | 50 } // anonymous namespace |
| 50 | 51 |
| 51 class BookmarkModelTest : public testing::Test, public BookmarkModelObserver { | 52 class BookmarkModelTest : public TestingBrowserProcessTest, |
| 53 public BookmarkModelObserver { |
| 52 public: | 54 public: |
| 53 struct ObserverDetails { | 55 struct ObserverDetails { |
| 54 ObserverDetails() { | 56 ObserverDetails() { |
| 55 Set(NULL, NULL, -1, -1); | 57 Set(NULL, NULL, -1, -1); |
| 56 } | 58 } |
| 57 | 59 |
| 58 void Set(const BookmarkNode* node1, | 60 void Set(const BookmarkNode* node1, |
| 59 const BookmarkNode* node2, | 61 const BookmarkNode* node2, |
| 60 int index1, | 62 int index1, |
| 61 int index2) { | 63 int index2) { |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 } else { | 643 } else { |
| 642 model->AddURL(bb_node, i, child->GetTitle(), | 644 model->AddURL(bb_node, i, child->GetTitle(), |
| 643 GURL("http://" + UTF16ToASCII(child->GetTitle()))); | 645 GURL("http://" + UTF16ToASCII(child->GetTitle()))); |
| 644 } | 646 } |
| 645 } | 647 } |
| 646 } | 648 } |
| 647 | 649 |
| 648 } // namespace | 650 } // namespace |
| 649 | 651 |
| 650 // Test class that creates a BookmarkModel with a real history backend. | 652 // Test class that creates a BookmarkModel with a real history backend. |
| 651 class BookmarkModelTestWithProfile : public testing::Test, | 653 class BookmarkModelTestWithProfile : public TestingBrowserProcessTest, |
| 652 public BookmarkModelObserver { | 654 public BookmarkModelObserver { |
| 653 public: | 655 public: |
| 654 BookmarkModelTestWithProfile() | 656 BookmarkModelTestWithProfile() |
| 655 : ui_thread_(BrowserThread::UI, &message_loop_), | 657 : ui_thread_(BrowserThread::UI, &message_loop_), |
| 656 file_thread_(BrowserThread::FILE, &message_loop_) {} | 658 file_thread_(BrowserThread::FILE, &message_loop_) {} |
| 657 | 659 |
| 658 virtual void SetUp() { | 660 virtual void SetUp() { |
| 659 } | 661 } |
| 660 | 662 |
| 661 virtual void TearDown() { | 663 virtual void TearDown() { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 // Make sure we were notified. | 988 // Make sure we were notified. |
| 987 AssertObserverCount(0, 0, 0, 0, 1); | 989 AssertObserverCount(0, 0, 0, 0, 1); |
| 988 | 990 |
| 989 // Make sure the order matches (remember, 'a' and 'C' are folders and | 991 // Make sure the order matches (remember, 'a' and 'C' are folders and |
| 990 // come first). | 992 // come first). |
| 991 EXPECT_EQ(parent->GetChild(0)->GetTitle(), ASCIIToUTF16("a")); | 993 EXPECT_EQ(parent->GetChild(0)->GetTitle(), ASCIIToUTF16("a")); |
| 992 EXPECT_EQ(parent->GetChild(1)->GetTitle(), ASCIIToUTF16("C")); | 994 EXPECT_EQ(parent->GetChild(1)->GetTitle(), ASCIIToUTF16("C")); |
| 993 EXPECT_EQ(parent->GetChild(2)->GetTitle(), ASCIIToUTF16("B")); | 995 EXPECT_EQ(parent->GetChild(2)->GetTitle(), ASCIIToUTF16("B")); |
| 994 EXPECT_EQ(parent->GetChild(3)->GetTitle(), ASCIIToUTF16("d")); | 996 EXPECT_EQ(parent->GetChild(3)->GetTitle(), ASCIIToUTF16("d")); |
| 995 } | 997 } |
| OLD | NEW |