| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/core/browser/bookmark_utils.h" | 5 #include "components/bookmarks/core/browser/bookmark_utils.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 class BookmarkUtilsTest : public testing::Test, | 25 class BookmarkUtilsTest : public testing::Test, |
| 26 public BaseBookmarkModelObserver { | 26 public BaseBookmarkModelObserver { |
| 27 public: | 27 public: |
| 28 BookmarkUtilsTest() | 28 BookmarkUtilsTest() |
| 29 : grouped_changes_beginning_count_(0), | 29 : grouped_changes_beginning_count_(0), |
| 30 grouped_changes_ended_count_(0) {} | 30 grouped_changes_ended_count_(0) {} |
| 31 virtual ~BookmarkUtilsTest() {} | 31 virtual ~BookmarkUtilsTest() {} |
| 32 | 32 |
| 33 // Copy and paste is not yet supported on iOS. http://crbug.com/228147 |
| 34 #if !defined(OS_IOS) |
| 33 virtual void TearDown() OVERRIDE { | 35 virtual void TearDown() OVERRIDE { |
| 34 ui::Clipboard::DestroyClipboardForCurrentThread(); | 36 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 35 } | 37 } |
| 38 #endif // !defined(OS_IOS) |
| 36 | 39 |
| 37 // Certain user actions require multiple changes to the bookmark model, | 40 // Certain user actions require multiple changes to the bookmark model, |
| 38 // however these modifications need to be atomic for the undo framework. The | 41 // however these modifications need to be atomic for the undo framework. The |
| 39 // BaseBookmarkModelObserver is used to inform the boundaries of the user | 42 // BaseBookmarkModelObserver is used to inform the boundaries of the user |
| 40 // action. For example, when multiple bookmarks are cut to the clipboard we | 43 // action. For example, when multiple bookmarks are cut to the clipboard we |
| 41 // expect one call each to GroupedBookmarkChangesBeginning/Ended. | 44 // expect one call each to GroupedBookmarkChangesBeginning/Ended. |
| 42 void ExpectGroupedChangeCount(int expected_beginning_count, | 45 void ExpectGroupedChangeCount(int expected_beginning_count, |
| 43 int expected_ended_count) { | 46 int expected_ended_count) { |
| 44 // The undo framework is not used under Android. Thus the group change | 47 // The undo framework is not used under Android. Thus the group change |
| 45 // events will not be fired and so should not be tested for Android. | 48 // events will not be fired and so should not be tested for Android. |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 for (size_t i = 0; i < arraysize(fields); i++) { | 248 for (size_t i = 0; i < arraysize(fields); i++) { |
| 246 scoped_ptr<base::string16> original_value(fields[i]->release()); | 249 scoped_ptr<base::string16> original_value(fields[i]->release()); |
| 247 fields[i]->reset(new base::string16(ASCIIToUTF16("fjdkslafjkldsa"))); | 250 fields[i]->reset(new base::string16(ASCIIToUTF16("fjdkslafjkldsa"))); |
| 248 GetBookmarksMatchingProperties(model.get(), query, 100, string(), &nodes); | 251 GetBookmarksMatchingProperties(model.get(), query, 100, string(), &nodes); |
| 249 ASSERT_EQ(0U, nodes.size()); | 252 ASSERT_EQ(0U, nodes.size()); |
| 250 nodes.clear(); | 253 nodes.clear(); |
| 251 fields[i]->reset(original_value.release()); | 254 fields[i]->reset(original_value.release()); |
| 252 } | 255 } |
| 253 } | 256 } |
| 254 | 257 |
| 258 // Copy and paste is not yet supported on iOS. http://crbug.com/228147 |
| 259 #if !defined(OS_IOS) |
| 255 TEST_F(BookmarkUtilsTest, CopyPaste) { | 260 TEST_F(BookmarkUtilsTest, CopyPaste) { |
| 256 test::TestBookmarkClient client; | 261 test::TestBookmarkClient client; |
| 257 scoped_ptr<BookmarkModel> model(client.CreateModel(false)); | 262 scoped_ptr<BookmarkModel> model(client.CreateModel(false)); |
| 258 const BookmarkNode* node = model->AddURL(model->other_node(), | 263 const BookmarkNode* node = model->AddURL(model->other_node(), |
| 259 0, | 264 0, |
| 260 ASCIIToUTF16("foo bar"), | 265 ASCIIToUTF16("foo bar"), |
| 261 GURL("http://www.google.com")); | 266 GURL("http://www.google.com")); |
| 262 | 267 |
| 263 // Copy a node to the clipboard. | 268 // Copy a node to the clipboard. |
| 264 std::vector<const BookmarkNode*> nodes; | 269 std::vector<const BookmarkNode*> nodes; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 303 |
| 299 // Make sure the nodes were removed. | 304 // Make sure the nodes were removed. |
| 300 EXPECT_EQ(0, model->other_node()->child_count()); | 305 EXPECT_EQ(0, model->other_node()->child_count()); |
| 301 | 306 |
| 302 // Make sure observers were notified the set of changes should be grouped. | 307 // Make sure observers were notified the set of changes should be grouped. |
| 303 ExpectGroupedChangeCount(1, 1); | 308 ExpectGroupedChangeCount(1, 1); |
| 304 | 309 |
| 305 // And make sure we can paste from the clipboard. | 310 // And make sure we can paste from the clipboard. |
| 306 EXPECT_TRUE(CanPasteFromClipboard(model->other_node())); | 311 EXPECT_TRUE(CanPasteFromClipboard(model->other_node())); |
| 307 } | 312 } |
| 313 #endif // !defined(OS_IOS) |
| 308 | 314 |
| 309 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { | 315 TEST_F(BookmarkUtilsTest, GetParentForNewNodes) { |
| 310 test::TestBookmarkClient client; | 316 test::TestBookmarkClient client; |
| 311 scoped_ptr<BookmarkModel> model(client.CreateModel(false)); | 317 scoped_ptr<BookmarkModel> model(client.CreateModel(false)); |
| 312 // This tests the case where selection contains one item and that item is a | 318 // This tests the case where selection contains one item and that item is a |
| 313 // folder. | 319 // folder. |
| 314 std::vector<const BookmarkNode*> nodes; | 320 std::vector<const BookmarkNode*> nodes; |
| 315 nodes.push_back(model->bookmark_bar_node()); | 321 nodes.push_back(model->bookmark_bar_node()); |
| 316 int index = -1; | 322 int index = -1; |
| 317 const BookmarkNode* real_parent = | 323 const BookmarkNode* real_parent = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size()); | 381 EXPECT_EQ(2u, clone->GetMetaInfoMap()->size()); |
| 376 std::string value; | 382 std::string value; |
| 377 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value)); | 383 EXPECT_TRUE(clone->GetMetaInfo("somekey", &value)); |
| 378 EXPECT_EQ("somevalue", value); | 384 EXPECT_EQ("somevalue", value); |
| 379 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value)); | 385 EXPECT_TRUE(clone->GetMetaInfo("someotherkey", &value)); |
| 380 EXPECT_EQ("someothervalue", value); | 386 EXPECT_EQ("someothervalue", value); |
| 381 } | 387 } |
| 382 | 388 |
| 383 } // namespace | 389 } // namespace |
| 384 } // namespace bookmark_utils | 390 } // namespace bookmark_utils |
| OLD | NEW |