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/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "components/bookmarks/browser/base_bookmark_model_observer.h" | 15 #include "components/bookmarks/browser/base_bookmark_model_observer.h" |
16 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
17 #include "components/bookmarks/browser/bookmark_node_data.h" | 17 #include "components/bookmarks/browser/bookmark_node_data.h" |
18 #include "components/bookmarks/test/test_bookmark_client.h" | 18 #include "components/bookmarks/test/test_bookmark_client.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "ui/base/clipboard/clipboard.h" | 20 #include "ui/base/clipboard/clipboard.h" |
21 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 21 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
22 | 22 |
23 #if defined(USE_X11) | |
24 #include "ui/events/platform/x11/x11_event_source_glib.h" | |
25 #include "ui/gfx/x/x11_types.h" | |
26 #endif // defined(USE_X11) | |
27 | |
23 using base::ASCIIToUTF16; | 28 using base::ASCIIToUTF16; |
24 using std::string; | 29 using std::string; |
25 | 30 |
26 namespace bookmarks { | 31 namespace bookmarks { |
27 namespace { | 32 namespace { |
28 | 33 |
29 class BookmarkUtilsTest : public testing::Test, | 34 class BookmarkUtilsTest : public testing::Test, |
30 public BaseBookmarkModelObserver { | 35 public BaseBookmarkModelObserver { |
31 public: | 36 public: |
32 BookmarkUtilsTest() | 37 BookmarkUtilsTest() |
33 : grouped_changes_beginning_count_(0), | 38 : grouped_changes_beginning_count_(0), |
34 grouped_changes_ended_count_(0) {} | 39 #if defined(USE_X11) |
40 grouped_changes_ended_count_(0), | |
41 event_source_(gfx::GetXDisplay()) { | |
42 } | |
43 #else | |
44 grouped_changes_ended_count_(0) { | |
45 } | |
46 #endif // defined(USE_x11) | |
35 ~BookmarkUtilsTest() override {} | 47 ~BookmarkUtilsTest() override {} |
36 | 48 |
37 // Copy and paste is not yet supported on iOS. http://crbug.com/228147 | 49 // Copy and paste is not yet supported on iOS. http://crbug.com/228147 |
38 #if !defined(OS_IOS) | 50 #if !defined(OS_IOS) |
39 void TearDown() override { | 51 void TearDown() override { |
40 ui::Clipboard::DestroyClipboardForCurrentThread(); | 52 ui::Clipboard::DestroyClipboardForCurrentThread(); |
41 } | 53 } |
42 #endif // !defined(OS_IOS) | 54 #endif // !defined(OS_IOS) |
43 | 55 |
44 // Certain user actions require multiple changes to the bookmark model, | 56 // Certain user actions require multiple changes to the bookmark model, |
(...skipping 21 matching lines...) Expand all Loading... | |
66 | 78 |
67 void GroupedBookmarkChangesEnded(BookmarkModel* model) override { | 79 void GroupedBookmarkChangesEnded(BookmarkModel* model) override { |
68 ++grouped_changes_ended_count_; | 80 ++grouped_changes_ended_count_; |
69 } | 81 } |
70 | 82 |
71 int grouped_changes_beginning_count_; | 83 int grouped_changes_beginning_count_; |
72 int grouped_changes_ended_count_; | 84 int grouped_changes_ended_count_; |
73 | 85 |
74 // Clipboard requires a message loop. | 86 // Clipboard requires a message loop. |
75 base::MessageLoopForUI loop_; | 87 base::MessageLoopForUI loop_; |
88 #if defined(USE_X11) | |
89 // On Linux, Clipboard also depends on an event source being present, to get | |
90 // the timestamp. | |
91 ui::X11EventSourceGlib event_source_; | |
dcheng
2016/04/20 00:55:26
I'm pretty sure the existing bookmark clipboard te
| |
92 #endif // defined(USE_X11) | |
76 | 93 |
77 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest); | 94 DISALLOW_COPY_AND_ASSIGN(BookmarkUtilsTest); |
78 }; | 95 }; |
79 | 96 |
80 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { | 97 TEST_F(BookmarkUtilsTest, GetBookmarksMatchingPropertiesWordPhraseQuery) { |
81 scoped_ptr<BookmarkModel> model(TestBookmarkClient::CreateModel()); | 98 scoped_ptr<BookmarkModel> model(TestBookmarkClient::CreateModel()); |
82 const BookmarkNode* node1 = model->AddURL(model->other_node(), | 99 const BookmarkNode* node1 = model->AddURL(model->other_node(), |
83 0, | 100 0, |
84 ASCIIToUTF16("foo bar"), | 101 ASCIIToUTF16("foo bar"), |
85 GURL("http://www.google.com")); | 102 GURL("http://www.google.com")); |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 model->GetNodesByURL(url, &nodes); | 614 model->GetNodesByURL(url, &nodes); |
598 ASSERT_EQ(1u, nodes.size()); | 615 ASSERT_EQ(1u, nodes.size()); |
599 EXPECT_TRUE(model->bookmark_bar_node()->empty()); | 616 EXPECT_TRUE(model->bookmark_bar_node()->empty()); |
600 EXPECT_TRUE(model->other_node()->empty()); | 617 EXPECT_TRUE(model->other_node()->empty()); |
601 EXPECT_TRUE(model->mobile_node()->empty()); | 618 EXPECT_TRUE(model->mobile_node()->empty()); |
602 EXPECT_EQ(1, extra_node->child_count()); | 619 EXPECT_EQ(1, extra_node->child_count()); |
603 } | 620 } |
604 | 621 |
605 } // namespace | 622 } // namespace |
606 } // namespace bookmarks | 623 } // namespace bookmarks |
OLD | NEW |