| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/clipboard/scoped_clipboard_writer.h" | 7 #include "app/clipboard/scoped_clipboard_writer.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_utils.h" | 13 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 14 | 14 |
| 15 typedef testing::Test BookmarkUtilsTest; | 15 typedef testing::Test BookmarkUtilsTest; |
| 16 | 16 |
| 17 TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) { | 17 TEST_F(BookmarkUtilsTest, GetBookmarksContainingText) { |
| 18 BookmarkModel model(NULL); | 18 BookmarkModel model(NULL); |
| 19 const BookmarkNode* n1 = | 19 const BookmarkNode* n1 = |
| 20 model.AddURL(model.other_node(), 0, ASCIIToUTF16("foo bar"), | 20 model.AddURL(model.other_node(), 0, ASCIIToUTF16("foo bar"), |
| 21 GURL("http://www.google.com")); | 21 GURL("http://www.google.com")); |
| 22 const BookmarkNode* n2 = | 22 const BookmarkNode* n2 = |
| 23 model.AddURL(model.other_node(), 0, ASCIIToUTF16("baz buz"), | 23 model.AddURL(model.other_node(), 0, ASCIIToUTF16("baz buz"), |
| 24 GURL("http://www.cnn.com")); | 24 GURL("http://www.cnn.com")); |
| 25 | 25 |
| 26 model.AddGroup(model.other_node(), 0, ASCIIToUTF16("foo")); | 26 model.AddGroup(model.other_node(), 0, ASCIIToUTF16("foo")); |
| 27 | 27 |
| 28 std::vector<const BookmarkNode*> nodes; | 28 std::vector<const BookmarkNode*> nodes; |
| 29 bookmark_utils::GetBookmarksContainingText( | 29 bookmark_utils::GetBookmarksContainingText( |
| 30 &model, L"foo", 100, std::wstring(), &nodes); | 30 &model, ASCIIToUTF16("foo"), 100, std::wstring(), &nodes); |
| 31 ASSERT_EQ(1U, nodes.size()); | 31 ASSERT_EQ(1U, nodes.size()); |
| 32 EXPECT_TRUE(nodes[0] == n1); | 32 EXPECT_TRUE(nodes[0] == n1); |
| 33 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText( | 33 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 34 n1, L"foo", std::wstring())); | 34 n1, ASCIIToUTF16("foo"), std::wstring())); |
| 35 nodes.clear(); | 35 nodes.clear(); |
| 36 | 36 |
| 37 bookmark_utils::GetBookmarksContainingText( | 37 bookmark_utils::GetBookmarksContainingText( |
| 38 &model, L"cnn", 100, std::wstring(), &nodes); | 38 &model, ASCIIToUTF16("cnn"), 100, std::wstring(), &nodes); |
| 39 ASSERT_EQ(1U, nodes.size()); | 39 ASSERT_EQ(1U, nodes.size()); |
| 40 EXPECT_TRUE(nodes[0] == n2); | 40 EXPECT_TRUE(nodes[0] == n2); |
| 41 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText( | 41 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 42 n2, L"cnn", std::wstring())); | 42 n2, ASCIIToUTF16("cnn"), std::wstring())); |
| 43 nodes.clear(); | 43 nodes.clear(); |
| 44 | 44 |
| 45 bookmark_utils::GetBookmarksContainingText( | 45 bookmark_utils::GetBookmarksContainingText( |
| 46 &model, L"foo bar", 100, std::wstring(), &nodes); | 46 &model, ASCIIToUTF16("foo bar"), 100, std::wstring(), &nodes); |
| 47 ASSERT_EQ(1U, nodes.size()); | 47 ASSERT_EQ(1U, nodes.size()); |
| 48 EXPECT_TRUE(nodes[0] == n1); | 48 EXPECT_TRUE(nodes[0] == n1); |
| 49 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText( | 49 EXPECT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 50 n1, L"foo bar", std::wstring())); | 50 n1, ASCIIToUTF16("foo bar"), std::wstring())); |
| 51 nodes.clear(); | 51 nodes.clear(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 TEST_F(BookmarkUtilsTest, DoesBookmarkContainText) { | 54 TEST_F(BookmarkUtilsTest, DoesBookmarkContainText) { |
| 55 BookmarkModel model(NULL); | 55 BookmarkModel model(NULL); |
| 56 const BookmarkNode* node = model.AddURL(model.other_node(), 0, | 56 const BookmarkNode* node = model.AddURL(model.other_node(), 0, |
| 57 ASCIIToUTF16("foo bar"), | 57 ASCIIToUTF16("foo bar"), |
| 58 GURL("http://www.google.com")); | 58 GURL("http://www.google.com")); |
| 59 // Matches to the title. | 59 // Matches to the title. |
| 60 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 60 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 61 node, L"ar", std::wstring())); | 61 node, ASCIIToUTF16("ar"), std::wstring())); |
| 62 // Matches to the URL | 62 // Matches to the URL |
| 63 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 63 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 64 node, L"www", std::wstring())); | 64 node, ASCIIToUTF16("www"), std::wstring())); |
| 65 // No match. | 65 // No match. |
| 66 ASSERT_FALSE(bookmark_utils::DoesBookmarkContainText( | 66 ASSERT_FALSE(bookmark_utils::DoesBookmarkContainText( |
| 67 node, L"cnn", std::wstring())); | 67 node, ASCIIToUTF16("cnn"), std::wstring())); |
| 68 | 68 |
| 69 // Tests for a Japanese IDN. | 69 // Tests for a Japanese IDN. |
| 70 const wchar_t* kDecodedIdn = L"\x30B0\x30FC\x30B0\x30EB"; | 70 const string16 kDecodedIdn = WideToUTF16(L"\x30B0\x30FC\x30B0\x30EB"); |
| 71 node = model.AddURL(model.other_node(), 0, ASCIIToUTF16("foo bar"), | 71 node = model.AddURL(model.other_node(), 0, ASCIIToUTF16("foo bar"), |
| 72 GURL("http://xn--qcka1pmc.jp")); | 72 GURL("http://xn--qcka1pmc.jp")); |
| 73 // Unicode query doesn't match if languages have no "ja". | 73 // Unicode query doesn't match if languages have no "ja". |
| 74 ASSERT_FALSE(bookmark_utils::DoesBookmarkContainText( | 74 ASSERT_FALSE(bookmark_utils::DoesBookmarkContainText( |
| 75 node, kDecodedIdn, L"en")); | 75 node, kDecodedIdn, L"en")); |
| 76 // Unicode query matches if languages have "ja". | 76 // Unicode query matches if languages have "ja". |
| 77 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 77 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 78 node, kDecodedIdn, L"ja")); | 78 node, kDecodedIdn, L"ja")); |
| 79 // Punycode query also matches as ever. | 79 // Punycode query also matches as ever. |
| 80 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 80 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 81 node, L"qcka1pmc", L"ja")); | 81 node, ASCIIToUTF16("qcka1pmc"), L"ja")); |
| 82 | 82 |
| 83 // Tests with various lower/upper case characters. | 83 // Tests with various lower/upper case characters. |
| 84 node = model.AddURL(model.other_node(), 0, ASCIIToUTF16("FOO bar"), | 84 node = model.AddURL(model.other_node(), 0, ASCIIToUTF16("FOO bar"), |
| 85 GURL("http://www.google.com/search?q=ABC")); | 85 GURL("http://www.google.com/search?q=ABC")); |
| 86 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 86 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 87 node, L"foo", std::wstring())); | 87 node, ASCIIToUTF16("foo"), std::wstring())); |
| 88 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 88 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 89 node, L"Foo", std::wstring())); | 89 node, ASCIIToUTF16("Foo"), std::wstring())); |
| 90 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 90 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 91 node, L"FOO", std::wstring())); | 91 node, ASCIIToUTF16("FOO"), std::wstring())); |
| 92 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 92 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 93 node, L"google abc", std::wstring())); | 93 node, ASCIIToUTF16("google abc"), std::wstring())); |
| 94 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 94 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 95 node, L"google ABC", std::wstring())); | 95 node, ASCIIToUTF16("google ABC"), std::wstring())); |
| 96 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( | 96 ASSERT_TRUE(bookmark_utils::DoesBookmarkContainText( |
| 97 node, L"http://www.google.com/search?q=A", std::wstring())); | 97 node, ASCIIToUTF16("http://www.google.com/search?q=A"), std::wstring())); |
| 98 } | 98 } |
| 99 | 99 |
| 100 #if !defined(OS_MACOSX) | 100 #if !defined(OS_MACOSX) |
| 101 TEST_F(BookmarkUtilsTest, CopyPaste) { | 101 TEST_F(BookmarkUtilsTest, CopyPaste) { |
| 102 // Clipboard requires a message loop. | 102 // Clipboard requires a message loop. |
| 103 MessageLoopForUI loop; | 103 MessageLoopForUI loop; |
| 104 | 104 |
| 105 BookmarkModel model(NULL); | 105 BookmarkModel model(NULL); |
| 106 const BookmarkNode* node = model.AddURL(model.other_node(), 0, | 106 const BookmarkNode* node = model.AddURL(model.other_node(), 0, |
| 107 ASCIIToUTF16("foo bar"), | 107 ASCIIToUTF16("foo bar"), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 121 ScopedClipboardWriter clipboard_writer(g_browser_process->clipboard()); | 121 ScopedClipboardWriter clipboard_writer(g_browser_process->clipboard()); |
| 122 clipboard_writer.WriteText(ASCIIToUTF16("foo")); | 122 clipboard_writer.WriteText(ASCIIToUTF16("foo")); |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Now we shouldn't be able to paste from the clipboard. | 125 // Now we shouldn't be able to paste from the clipboard. |
| 126 EXPECT_FALSE( | 126 EXPECT_FALSE( |
| 127 bookmark_utils::CanPasteFromClipboard(model.GetBookmarkBarNode())); | 127 bookmark_utils::CanPasteFromClipboard(model.GetBookmarkBarNode())); |
| 128 } | 128 } |
| 129 #endif | 129 #endif |
| 130 | 130 |
| OLD | NEW |