1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "testing/gtest/include/gtest/gtest.h"
#include "base/message_loop.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/test/testing_browser_process_test.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"
#if !defined(OS_MACOSX)
#include "chrome/browser/browser_process.h"
#endif
typedef TestingBrowserProcessTest BookmarkUtilsTest;
TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) {
BookmarkModel model(NULL);
const BookmarkNode* n1 =
model.AddURL(model.other_node(), 0, ASCIIToUTF16("foo bar"),
GURL("http://www.google.com"));
const BookmarkNode* n2 =
model.AddURL(model.other_node(), 0, ASCIIToUTF16("baz buz"),
GURL("http://www.cnn.com"));
model.AddFolder(model.other_node(), 0, ASCIIToUTF16("foo"));
std::vector<const BookmarkNode*> nodes;
bookmark_utils::GetBookmarksContainingText(
&model, ASCIIToUTF16("foo"), 100, std::string(), &nodes);
ASSERT_EQ(1U, nodes.size());
EXPECT_TRUE(nodes[0] == n1);
EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(
n1, ASCIIToUTF16("foo"), std::string()));
nodes.clear();
bookmark_utils::GetBookmarksContainingText(
&model, ASCIIToUTF16("cnn"), 100, std::string(), &nodes);
ASSERT_EQ(1U, nodes.size());
EXPECT_TRUE(nodes[0] == n2);
EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(
n2, ASCIIToUTF16("cnn"), std::string()));
nodes.clear();
bookmark_utils::GetBookmarksContainingText(
&model, ASCIIToUTF16("foo bar"), 100, std::string(), &nodes);
ASSERT_EQ(1U, nodes.size());
EXPECT_TRUE(nodes[0] == n1);
EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(
n1, ASCIIToUTF16("foo bar"), std::string()));
nodes.clear();
}
TEST_F(BookmarkUtilsTest, DoesBookmarkContainText) {
BookmarkModel model(NULL);
const BookmarkNode* node = model.AddURL(model.other_node(), 0,
ASCIIToUTF16("foo bar"),
GURL("http://www.google.com"));
// Matches to the title.
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("ar"), std::string()));
// Matches to the URL
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("www"), std::string()));
// No match.
ASSERT_FALSE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("cnn"), std::string()));
// Tests for a Japanese IDN.
const string16 kDecodedIdn = WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB");
node = model.AddURL(model.other_node(), 0, ASCIIToUTF16("foo bar"),
GURL("http://xn--qcka1pmc.jp"));
// Unicode query doesn't match if languages have no "ja".
ASSERT_FALSE(bookmark_utils::DoesBookmarkContainText(
node, kDecodedIdn, "en"));
// Unicode query matches if languages have "ja".
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, kDecodedIdn, "ja"));
// Punycode query also matches as ever.
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("qcka1pmc"), "ja"));
// Tests with various lower/upper case characters.
node = model.AddURL(model.other_node(), 0, ASCIIToUTF16("FOO bar"),
GURL("http://www.google.com/search?q=ABC"));
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("foo"), std::string()));
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("Foo"), std::string()));
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("FOO"), std::string()));
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("google abc"), std::string()));
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("google ABC"), std::string()));
ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
node, ASCIIToUTF16("http://www.google.com/search?q=A"), std::string()));
}
#if !defined(OS_MACOSX)
TEST_F(BookmarkUtilsTest, CopyPaste) {
// Clipboard requires a message loop.
MessageLoopForUI loop;
BookmarkModel model(NULL);
const BookmarkNode* node = model.AddURL(model.other_node(), 0,
ASCIIToUTF16("foo bar"),
GURL("http://www.google.com"));
// Copy a node to the clipboard.
std::vector<const BookmarkNode*> nodes;
nodes.push_back(node);
bookmark_utils::CopyToClipboard(&model, nodes, false);
// And make sure we can paste a bookmark from the clipboard.
EXPECT_TRUE(
bookmark_utils::CanPasteFromClipboard(model.GetBookmarkBarNode()));
// Write some text to the clipboard.
{
ui::ScopedClipboardWriter clipboard_writer(g_browser_process->clipboard());
clipboard_writer.WriteText(ASCIIToUTF16("foo"));
}
// Now we shouldn't be able to paste from the clipboard.
EXPECT_FALSE(
bookmark_utils::CanPasteFromClipboard(model.GetBookmarkBarNode()));
}
#endif
|