Index: components/bookmarks/core/browser/bookmark_node_data_unittest.cc |
diff --git a/chrome/browser/bookmarks/bookmark_node_data_unittest.cc b/components/bookmarks/core/browser/bookmark_node_data_unittest.cc |
similarity index 85% |
rename from chrome/browser/bookmarks/bookmark_node_data_unittest.cc |
rename to components/bookmarks/core/browser/bookmark_node_data_unittest.cc |
index 5c23cd37b124114fb94ee867ec85e8240002552e..f8b43e6872f90e704dd99798f9698ba5b99abd1d 100644 |
--- a/chrome/browser/bookmarks/bookmark_node_data_unittest.cc |
+++ b/components/bookmarks/core/browser/bookmark_node_data_unittest.cc |
@@ -3,16 +3,14 @@ |
// found in the LICENSE file. |
#include "base/basictypes.h" |
+#include "base/files/scoped_temp_dir.h" |
#include "base/memory/scoped_ptr.h" |
-#include "base/message_loop/message_loop.h" |
#include "base/strings/string16.h" |
#include "base/strings/utf_string_conversions.h" |
-#include "chrome/browser/bookmarks/bookmark_model_factory.h" |
-#include "chrome/test/base/testing_profile.h" |
#include "components/bookmarks/core/browser/bookmark_model.h" |
#include "components/bookmarks/core/browser/bookmark_node_data.h" |
#include "components/bookmarks/core/test/bookmark_test_helpers.h" |
-#include "content/public/test/test_browser_thread_bundle.h" |
+#include "components/bookmarks/core/test/test_bookmark_client.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "ui/base/dragdrop/os_exchange_data.h" |
#include "ui/events/platform/platform_event_source.h" |
@@ -22,30 +20,31 @@ using base::ASCIIToUTF16; |
class BookmarkNodeDataTest : public testing::Test { |
public: |
- BookmarkNodeDataTest() : model_(NULL) {} |
+ BookmarkNodeDataTest() {} |
virtual void SetUp() OVERRIDE { |
event_source_ = ui::PlatformEventSource::CreateDefault(); |
- profile_.reset(new TestingProfile); |
- profile_->SetID(L"id"); |
- profile_->CreateBookmarkModel(false); |
- model_ = BookmarkModelFactory::GetForProfile(profile_.get()); |
- test::WaitForBookmarkModelToLoad(model_); |
+ model_ = client_.CreateModel(false); |
+ test::WaitForBookmarkModelToLoad(model_.get()); |
+ bool success = profile_dir_.CreateUniqueTempDir(); |
+ ASSERT_TRUE(success); |
} |
virtual void TearDown() OVERRIDE { |
- profile_.reset(); |
+ model_.reset(); |
event_source_.reset(); |
+ bool success = profile_dir_.Delete(); |
+ ASSERT_TRUE(success); |
} |
- Profile* profile() { return profile_.get(); } |
+ const base::FilePath& GetProfilePath() const { return profile_dir_.path(); } |
- BookmarkModel* model() { return model_; } |
+ BookmarkModel* model() { return model_.get(); } |
private: |
- content::TestBrowserThreadBundle thread_bundle_; |
- scoped_ptr<TestingProfile> profile_; |
- BookmarkModel* model_; |
+ base::ScopedTempDir profile_dir_; |
+ test::TestBookmarkClient client_; |
+ scoped_ptr<BookmarkModel> model_; |
scoped_ptr<ui::PlatformEventSource> event_source_; |
DISALLOW_COPY_AND_ASSIGN(BookmarkNodeDataTest); |
@@ -110,7 +109,7 @@ TEST_F(BookmarkNodeDataTest, URL) { |
EXPECT_EQ(node->date_folder_modified(), |
drag_data.elements[0].date_folder_modified); |
ui::OSExchangeData data; |
- drag_data.Write(profile()->GetPath(), &data); |
+ drag_data.Write(GetProfilePath(), &data); |
// Now read the data back in. |
ui::OSExchangeData data2(CloneProvider(data)); |
@@ -123,11 +122,13 @@ TEST_F(BookmarkNodeDataTest, URL) { |
EXPECT_EQ(title, read_data.elements[0].title); |
EXPECT_TRUE(read_data.elements[0].date_added.is_null()); |
EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); |
- EXPECT_TRUE(read_data.GetFirstNode(model(), profile()->GetPath()) == node); |
+ EXPECT_TRUE(read_data.GetFirstNode(model(), GetProfilePath()) == node); |
// Make sure asking for the node with a different profile returns NULL. |
- TestingProfile profile2; |
- EXPECT_TRUE(read_data.GetFirstNode(model(), profile2.GetPath()) == NULL); |
+ base::ScopedTempDir other_profile_dir; |
+ EXPECT_TRUE(other_profile_dir.CreateUniqueTempDir()); |
+ EXPECT_TRUE(read_data.GetFirstNode(model(), other_profile_dir.path()) == |
+ NULL); |
// Writing should also put the URL and title on the clipboard. |
GURL read_url; |
@@ -155,7 +156,7 @@ TEST_F(BookmarkNodeDataTest, Folder) { |
drag_data.elements[0].date_folder_modified); |
ui::OSExchangeData data; |
- drag_data.Write(profile()->GetPath(), &data); |
+ drag_data.Write(GetProfilePath(), &data); |
// Now read the data back in. |
ui::OSExchangeData data2(CloneProvider(data)); |
@@ -169,13 +170,14 @@ TEST_F(BookmarkNodeDataTest, Folder) { |
EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); |
// We should get back the same node when asking for the same profile. |
- const BookmarkNode* r_g12 = |
- read_data.GetFirstNode(model(), profile()->GetPath()); |
+ const BookmarkNode* r_g12 = read_data.GetFirstNode(model(), GetProfilePath()); |
EXPECT_TRUE(g12 == r_g12); |
// A different profile should return NULL for the node. |
- TestingProfile profile2; |
- EXPECT_TRUE(read_data.GetFirstNode(model(), profile2.GetPath()) == NULL); |
+ base::ScopedTempDir other_profile_dir; |
+ EXPECT_TRUE(other_profile_dir.CreateUniqueTempDir()); |
+ EXPECT_TRUE(read_data.GetFirstNode(model(), other_profile_dir.path()) == |
+ NULL); |
} |
// Tests reading/writing a folder with children. |
@@ -191,7 +193,7 @@ TEST_F(BookmarkNodeDataTest, FolderWithChild) { |
BookmarkNodeData drag_data(folder); |
ui::OSExchangeData data; |
- drag_data.Write(profile()->GetPath(), &data); |
+ drag_data.Write(GetProfilePath(), &data); |
// Now read the data back in. |
ui::OSExchangeData data2(CloneProvider(data)); |
@@ -211,7 +213,7 @@ TEST_F(BookmarkNodeDataTest, FolderWithChild) { |
// And make sure we get the node back. |
const BookmarkNode* r_folder = |
- read_data.GetFirstNode(model(), profile()->GetPath()); |
+ read_data.GetFirstNode(model(), GetProfilePath()); |
EXPECT_TRUE(folder == r_folder); |
} |
@@ -231,7 +233,7 @@ TEST_F(BookmarkNodeDataTest, MultipleNodes) { |
nodes.push_back(url_node); |
BookmarkNodeData drag_data(nodes); |
ui::OSExchangeData data; |
- drag_data.Write(profile()->GetPath(), &data); |
+ drag_data.Write(GetProfilePath(), &data); |
// Read the data back in. |
ui::OSExchangeData data2(CloneProvider(data)); |
@@ -255,14 +257,14 @@ TEST_F(BookmarkNodeDataTest, MultipleNodes) { |
// And make sure we get the node back. |
std::vector<const BookmarkNode*> read_nodes = |
- read_data.GetNodes(model(), profile()->GetPath()); |
+ read_data.GetNodes(model(), GetProfilePath()); |
ASSERT_EQ(2u, read_nodes.size()); |
EXPECT_TRUE(read_nodes[0] == folder); |
EXPECT_TRUE(read_nodes[1] == url_node); |
// Asking for the first node should return NULL with more than one element |
// present. |
- EXPECT_TRUE(read_data.GetFirstNode(model(), profile()->GetPath()) == NULL); |
+ EXPECT_TRUE(read_data.GetFirstNode(model(), GetProfilePath()) == NULL); |
} |
// Tests reading/writing of meta info. |
@@ -277,7 +279,7 @@ TEST_F(BookmarkNodeDataTest, MetaInfo) { |
BookmarkNodeData node_data(node); |
ui::OSExchangeData data; |
- node_data.Write(profile()->GetPath(), &data); |
+ node_data.Write(GetProfilePath(), &data); |
// Read the data back in. |
ui::OSExchangeData data2(CloneProvider(data)); |