| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_node_data.h" | 5 #include "components/bookmarks/browser/bookmark_node_data.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 ASSERT_TRUE(success); | 34 ASSERT_TRUE(success); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void TearDown() override { | 37 void TearDown() override { |
| 38 model_.reset(); | 38 model_.reset(); |
| 39 bool success = profile_dir_.Delete(); | 39 bool success = profile_dir_.Delete(); |
| 40 ASSERT_TRUE(success); | 40 ASSERT_TRUE(success); |
| 41 ui::Clipboard::DestroyClipboardForCurrentThread(); | 41 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 42 } | 42 } |
| 43 | 43 |
| 44 const base::FilePath& GetProfilePath() const { return profile_dir_.path(); } | 44 const base::FilePath& GetProfilePath() const { |
| 45 return profile_dir_.GetPath(); |
| 46 } |
| 45 | 47 |
| 46 BookmarkModel* model() { return model_.get(); } | 48 BookmarkModel* model() { return model_.get(); } |
| 47 | 49 |
| 48 protected: | 50 protected: |
| 49 ui::Clipboard& clipboard() { return *ui::Clipboard::GetForCurrentThread(); } | 51 ui::Clipboard& clipboard() { return *ui::Clipboard::GetForCurrentThread(); } |
| 50 | 52 |
| 51 private: | 53 private: |
| 52 base::ScopedTempDir profile_dir_; | 54 base::ScopedTempDir profile_dir_; |
| 53 std::unique_ptr<BookmarkModel> model_; | 55 std::unique_ptr<BookmarkModel> model_; |
| 54 base::MessageLoopForUI loop_; | 56 base::MessageLoopForUI loop_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 EXPECT_TRUE(read_data.elements[0].is_url); | 129 EXPECT_TRUE(read_data.elements[0].is_url); |
| 128 EXPECT_EQ(url, read_data.elements[0].url); | 130 EXPECT_EQ(url, read_data.elements[0].url); |
| 129 EXPECT_EQ(title, read_data.elements[0].title); | 131 EXPECT_EQ(title, read_data.elements[0].title); |
| 130 EXPECT_TRUE(read_data.elements[0].date_added.is_null()); | 132 EXPECT_TRUE(read_data.elements[0].date_added.is_null()); |
| 131 EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); | 133 EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); |
| 132 EXPECT_TRUE(read_data.GetFirstNode(model(), GetProfilePath()) == node); | 134 EXPECT_TRUE(read_data.GetFirstNode(model(), GetProfilePath()) == node); |
| 133 | 135 |
| 134 // Make sure asking for the node with a different profile returns NULL. | 136 // Make sure asking for the node with a different profile returns NULL. |
| 135 base::ScopedTempDir other_profile_dir; | 137 base::ScopedTempDir other_profile_dir; |
| 136 EXPECT_TRUE(other_profile_dir.CreateUniqueTempDir()); | 138 EXPECT_TRUE(other_profile_dir.CreateUniqueTempDir()); |
| 137 EXPECT_TRUE(read_data.GetFirstNode(model(), other_profile_dir.path()) == | 139 EXPECT_TRUE(read_data.GetFirstNode(model(), other_profile_dir.GetPath()) == |
| 138 NULL); | 140 NULL); |
| 139 | 141 |
| 140 // Writing should also put the URL and title on the clipboard. | 142 // Writing should also put the URL and title on the clipboard. |
| 141 GURL read_url; | 143 GURL read_url; |
| 142 base::string16 read_title; | 144 base::string16 read_title; |
| 143 EXPECT_TRUE(data2.GetURLAndTitle( | 145 EXPECT_TRUE(data2.GetURLAndTitle( |
| 144 ui::OSExchangeData::CONVERT_FILENAMES, &read_url, &read_title)); | 146 ui::OSExchangeData::CONVERT_FILENAMES, &read_url, &read_title)); |
| 145 EXPECT_EQ(url, read_url); | 147 EXPECT_EQ(url, read_url); |
| 146 EXPECT_EQ(title, read_title); | 148 EXPECT_EQ(title, read_title); |
| 147 } | 149 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 176 EXPECT_TRUE(read_data.elements[0].date_added.is_null()); | 178 EXPECT_TRUE(read_data.elements[0].date_added.is_null()); |
| 177 EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); | 179 EXPECT_TRUE(read_data.elements[0].date_folder_modified.is_null()); |
| 178 | 180 |
| 179 // We should get back the same node when asking for the same profile. | 181 // We should get back the same node when asking for the same profile. |
| 180 const BookmarkNode* r_g12 = read_data.GetFirstNode(model(), GetProfilePath()); | 182 const BookmarkNode* r_g12 = read_data.GetFirstNode(model(), GetProfilePath()); |
| 181 EXPECT_TRUE(g12 == r_g12); | 183 EXPECT_TRUE(g12 == r_g12); |
| 182 | 184 |
| 183 // A different profile should return NULL for the node. | 185 // A different profile should return NULL for the node. |
| 184 base::ScopedTempDir other_profile_dir; | 186 base::ScopedTempDir other_profile_dir; |
| 185 EXPECT_TRUE(other_profile_dir.CreateUniqueTempDir()); | 187 EXPECT_TRUE(other_profile_dir.CreateUniqueTempDir()); |
| 186 EXPECT_TRUE(read_data.GetFirstNode(model(), other_profile_dir.path()) == | 188 EXPECT_TRUE(read_data.GetFirstNode(model(), other_profile_dir.GetPath()) == |
| 187 NULL); | 189 NULL); |
| 188 } | 190 } |
| 189 | 191 |
| 190 // Tests reading/writing a folder with children. | 192 // Tests reading/writing a folder with children. |
| 191 TEST_F(BookmarkNodeDataTest, FolderWithChild) { | 193 TEST_F(BookmarkNodeDataTest, FolderWithChild) { |
| 192 const BookmarkNode* root = model()->bookmark_bar_node(); | 194 const BookmarkNode* root = model()->bookmark_bar_node(); |
| 193 const BookmarkNode* folder = model()->AddFolder(root, 0, ASCIIToUTF16("g1")); | 195 const BookmarkNode* folder = model()->AddFolder(root, 0, ASCIIToUTF16("g1")); |
| 194 | 196 |
| 195 GURL url(GURL("http://foo.com")); | 197 GURL url(GURL("http://foo.com")); |
| 196 const base::string16 title(ASCIIToUTF16("blah2")); | 198 const base::string16 title(ASCIIToUTF16("blah2")); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 ASSERT_EQ(1u, read_data.size()); | 397 ASSERT_EQ(1u, read_data.size()); |
| 396 | 398 |
| 397 // Verify that the read data contains the same meta info. | 399 // Verify that the read data contains the same meta info. |
| 398 BookmarkNode::MetaInfoMap meta_info_map = read_data.elements[0].meta_info_map; | 400 BookmarkNode::MetaInfoMap meta_info_map = read_data.elements[0].meta_info_map; |
| 399 EXPECT_EQ(2u, meta_info_map.size()); | 401 EXPECT_EQ(2u, meta_info_map.size()); |
| 400 EXPECT_EQ("somevalue", meta_info_map["somekey"]); | 402 EXPECT_EQ("somevalue", meta_info_map["somekey"]); |
| 401 EXPECT_EQ("someothervalue", meta_info_map["someotherkey"]); | 403 EXPECT_EQ("someothervalue", meta_info_map["someotherkey"]); |
| 402 } | 404 } |
| 403 | 405 |
| 404 } // namespace bookmarks | 406 } // namespace bookmarks |
| OLD | NEW |