Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(575)

Side by Side Diff: chrome/browser/bookmarks/bookmark_utils_unittest.cc

Issue 113815: Support for searching bookmarks for IDN.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "chrome/browser/bookmarks/bookmark_model.h" 7 #include "chrome/browser/bookmarks/bookmark_model.h"
8 #include "chrome/browser/bookmarks/bookmark_utils.h" 8 #include "chrome/browser/bookmarks/bookmark_utils.h"
9 9
10 typedef testing::Test BookmarkUtilsTest; 10 typedef testing::Test BookmarkUtilsTest;
11 11
12 TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) { 12 TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) {
13 BookmarkModel model(NULL); 13 BookmarkModel model(NULL);
14 BookmarkNode* n1 = 14 BookmarkNode* n1 =
15 model.AddURL(model.other_node(), 0, L"foo bar", 15 model.AddURL(model.other_node(), 0, L"foo bar",
16 GURL("http://www.google.com")); 16 GURL("http://www.google.com"));
17 BookmarkNode* n2 = 17 BookmarkNode* n2 =
18 model.AddURL(model.other_node(), 0, L"baz buz", 18 model.AddURL(model.other_node(), 0, L"baz buz",
19 GURL("http://www.cnn.com")); 19 GURL("http://www.cnn.com"));
20 20
21 model.AddGroup(model.other_node(), 0, L"foo"); 21 model.AddGroup(model.other_node(), 0, L"foo");
22 22
23 std::vector<BookmarkNode*> nodes; 23 std::vector<BookmarkNode*> nodes;
24 bookmark_utils::GetBookmarksContainingText(&model, L"foo", 100, &nodes); 24 bookmark_utils::GetBookmarksContainingText(
25 &model, L"foo", 100, std::wstring(), &nodes);
25 ASSERT_EQ(1U, nodes.size()); 26 ASSERT_EQ(1U, nodes.size());
26 EXPECT_TRUE(nodes[0] == n1); 27 EXPECT_TRUE(nodes[0] == n1);
27 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(n1, L"foo")); 28 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(
29 n1, L"foo", std::wstring()));
28 nodes.clear(); 30 nodes.clear();
29 31
30 bookmark_utils::GetBookmarksContainingText(&model, L"cnn", 100, &nodes); 32 bookmark_utils::GetBookmarksContainingText(
33 &model, L"cnn", 100, std::wstring(), &nodes);
31 ASSERT_EQ(1U, nodes.size()); 34 ASSERT_EQ(1U, nodes.size());
32 EXPECT_TRUE(nodes[0] == n2); 35 EXPECT_TRUE(nodes[0] == n2);
33 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(n2, L"cnn")); 36 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(
37 n2, L"cnn", std::wstring()));
34 nodes.clear(); 38 nodes.clear();
35 39
36 bookmark_utils::GetBookmarksContainingText(&model, L"foo bar", 100, &nodes); 40 bookmark_utils::GetBookmarksContainingText(
41 &model, L"foo bar", 100, std::wstring(), &nodes);
37 ASSERT_EQ(1U, nodes.size()); 42 ASSERT_EQ(1U, nodes.size());
38 EXPECT_TRUE(nodes[0] == n1); 43 EXPECT_TRUE(nodes[0] == n1);
39 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(n1, L"foo bar")); 44 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText(
45 n1, L"foo bar", std::wstring()));
40 nodes.clear(); 46 nodes.clear();
41 } 47 }
48
49 TEST_F(BookmarkUtilsTest, DoesBookmarkContainText) {
50 BookmarkModel model(NULL);
51 BookmarkNode* node = model.AddURL(model.other_node(), 0, L"foo bar",
52 GURL("http://www.google.com"));
53 // Matches to the title.
54 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
55 node, L"ar", std::wstring()));
56 // Matches to the URL
57 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
58 node, L"www", std::wstring()));
59 // No match.
60 ASSERT_FALSE(bookmark_utils::DoesBookmarkContainText(
61 node, L"cnn", std::wstring()));
62
63 // Tests for a Japanese IDN.
64 const wchar_t* kDecodedIdn = L"\x30B0\x30FC\x30B0\x30EB";
65 node = model.AddURL(model.other_node(), 0, L"foo bar",
66 GURL("http://xn--qcka1pmc.jp"));
67 // Unicode query doesn't match if languages have no "ja".
68 ASSERT_FALSE(bookmark_utils::DoesBookmarkContainText(
69 node, kDecodedIdn, L"en"));
70 // Unicode query matches if languages have "ja".
71 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
72 node, kDecodedIdn, L"ja"));
73 // Punycode query also matches as ever.
74 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText(
75 node, L"qcka1pmc", L"ja"));
76 }
77
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_utils.cc ('k') | chrome/browser/extensions/extension_bookmarks_module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698