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