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_utils.h" | 5 #include "components/bookmarks/browser/bookmark_utils.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/message_loop/message_loop.h" | |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/test/scoped_task_environment.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "components/bookmarks/browser/base_bookmark_model_observer.h" | 16 #include "components/bookmarks/browser/base_bookmark_model_observer.h" |
17 #include "components/bookmarks/browser/bookmark_model.h" | 17 #include "components/bookmarks/browser/bookmark_model.h" |
18 #include "components/bookmarks/browser/bookmark_node_data.h" | 18 #include "components/bookmarks/browser/bookmark_node_data.h" |
19 #include "components/bookmarks/test/test_bookmark_client.h" | 19 #include "components/bookmarks/test/test_bookmark_client.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "ui/base/clipboard/clipboard.h" | 21 #include "ui/base/clipboard/clipboard.h" |
22 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 22 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
23 | 23 |
24 using base::ASCIIToUTF16; | 24 using base::ASCIIToUTF16; |
25 using std::string; | 25 using std::string; |
26 | 26 |
27 namespace bookmarks { | 27 namespace bookmarks { |
28 namespace { | 28 namespace { |
29 | 29 |
30 class BookmarkUtilsTest : public testing::Test, | 30 class BookmarkUtilsTest : public testing::Test, |
31 public BaseBookmarkModelObserver { | 31 public BaseBookmarkModelObserver { |
32 public: | 32 public: |
33 BookmarkUtilsTest() | 33 BookmarkUtilsTest() |
34 : grouped_changes_beginning_count_(0), grouped_changes_ended_count_(0) {} | 34 : scoped_task_environment_( |
| 35 base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| 36 grouped_changes_beginning_count_(0), |
| 37 grouped_changes_ended_count_(0) {} |
35 | 38 |
36 ~BookmarkUtilsTest() override {} | 39 ~BookmarkUtilsTest() override {} |
37 | 40 |
38 // Copy and paste is not yet supported on iOS. http://crbug.com/228147 | 41 // Copy and paste is not yet supported on iOS. http://crbug.com/228147 |
39 #if !defined(OS_IOS) | 42 #if !defined(OS_IOS) |
40 void TearDown() override { | 43 void TearDown() override { |
41 ui::Clipboard::DestroyClipboardForCurrentThread(); | 44 ui::Clipboard::DestroyClipboardForCurrentThread(); |
42 } | 45 } |
43 #endif // !defined(OS_IOS) | 46 #endif // !defined(OS_IOS) |
44 | 47 |
(...skipping 17 matching lines...) Expand all Loading... |
62 void BookmarkModelChanged() override {} | 65 void BookmarkModelChanged() override {} |
63 | 66 |
64 void GroupedBookmarkChangesBeginning(BookmarkModel* model) override { | 67 void GroupedBookmarkChangesBeginning(BookmarkModel* model) override { |
65 ++grouped_changes_beginning_count_; | 68 ++grouped_changes_beginning_count_; |
66 } | 69 } |
67 | 70 |
68 void GroupedBookmarkChangesEnded(BookmarkModel* model) override { | 71 void GroupedBookmarkChangesEnded(BookmarkModel* model) override { |
69 ++grouped_changes_ended_count_; | 72 ++grouped_changes_ended_count_; |
70 } | 73 } |
71 | 74 |
| 75 // Clipboard requires a message loop. |
| 76 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 77 |
72 int grouped_changes_beginning_count_; | 78 int grouped_changes_beginning_count_; |
73 int grouped_changes_ended_count_; | 79 int grouped_changes_ended_count_; |
74 | 80 |
75 // Clipboard requires a message loop. | |
76 base::MessageLoopForUI loop_; | |
77 | |
78 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest); | 81 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest); |
79 }; | 82 }; |
80 | 83 |
81 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { | 84 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { |
82 std::unique_ptr<BookmarkModel> model(TestBookmarkClient::CreateModel()); | 85 std::unique_ptr<BookmarkModel> model(TestBookmarkClient::CreateModel()); |
83 const BookmarkNode* node1 = model->AddURL(model->other_node(), | 86 const BookmarkNode* node1 = model->AddURL(model->other_node(), |
84 0, | 87 0, |
85 ASCIIToUTF16("foo bar"), | 88 ASCIIToUTF16("foo bar"), |
86 GURL("http://www.google.com")); | 89 GURL("http://www.google.com")); |
87 const BookmarkNode* node2 = model->AddURL(model->other_node(), | 90 const BookmarkNode* node2 = model->AddURL(model->other_node(), |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 model->GetNodesByURL(url, &nodes); | 601 model->GetNodesByURL(url, &nodes); |
599 ASSERT_EQ(1u, nodes.size()); | 602 ASSERT_EQ(1u, nodes.size()); |
600 EXPECT_TRUE(model->bookmark_bar_node()->empty()); | 603 EXPECT_TRUE(model->bookmark_bar_node()->empty()); |
601 EXPECT_TRUE(model->other_node()->empty()); | 604 EXPECT_TRUE(model->other_node()->empty()); |
602 EXPECT_TRUE(model->mobile_node()->empty()); | 605 EXPECT_TRUE(model->mobile_node()->empty()); |
603 EXPECT_EQ(1, extra_node->child_count()); | 606 EXPECT_EQ(1, extra_node->child_count()); |
604 } | 607 } |
605 | 608 |
606 } // namespace | 609 } // namespace |
607 } // namespace bookmarks | 610 } // namespace bookmarks |
OLD | NEW |