OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/scoped_temp_dir.h" | 8 #include "base/scoped_temp_dir.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/autocomplete/shortcuts_provider_shortcut.h" | |
13 #include "chrome/browser/history/shortcuts_backend.h" | 12 #include "chrome/browser/history/shortcuts_backend.h" |
14 #include "chrome/browser/history/shortcuts_database.h" | 13 #include "chrome/browser/history/shortcuts_database.h" |
15 #include "chrome/common/guid.h" | 14 #include "chrome/common/guid.h" |
16 #include "content/test/test_browser_thread.h" | 15 #include "content/test/test_browser_thread.h" |
17 #include "sql/statement.h" | 16 #include "sql/statement.h" |
18 | 17 |
19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
20 | 19 |
21 using content::BrowserThread; | 20 using content::BrowserThread; |
22 using shortcuts_provider::Shortcut; | |
23 using shortcuts_provider::ShortcutMap; | |
24 | 21 |
25 namespace history { | 22 namespace history { |
26 | 23 |
27 const base::TimeDelta kMaxRequestWaitTimeout = base::TimeDelta::FromSeconds(1); | 24 const base::TimeDelta kMaxRequestWaitTimeout = base::TimeDelta::FromSeconds(1); |
28 | 25 |
29 class ShortcutsBackendTest : public testing::Test, | 26 class ShortcutsBackendTest : public testing::Test, |
30 public ShortcutsBackend::ShortcutsBackendObserver { | 27 public ShortcutsBackend::ShortcutsBackendObserver { |
31 public: | 28 public: |
32 ShortcutsBackendTest() | 29 ShortcutsBackendTest() |
33 : ui_thread_(BrowserThread::UI, &ui_message_loop_), | 30 : ui_thread_(BrowserThread::UI, &ui_message_loop_), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 EXPECT_FALSE(load_notified_); | 72 EXPECT_FALSE(load_notified_); |
76 EXPECT_FALSE(backend_->initialized()); | 73 EXPECT_FALSE(backend_->initialized()); |
77 EXPECT_TRUE(backend_->Init()); | 74 EXPECT_TRUE(backend_->Init()); |
78 MessageLoop::current()->Run(); | 75 MessageLoop::current()->Run(); |
79 EXPECT_TRUE(load_notified_); | 76 EXPECT_TRUE(load_notified_); |
80 EXPECT_TRUE(backend_->initialized()); | 77 EXPECT_TRUE(backend_->initialized()); |
81 } | 78 } |
82 | 79 |
83 TEST_F(ShortcutsBackendTest, AddAndUpdateShortcut) { | 80 TEST_F(ShortcutsBackendTest, AddAndUpdateShortcut) { |
84 InitBackend(); | 81 InitBackend(); |
85 Shortcut shortcut("BD85DBA2-8C29-49F9-84AE-48E1E90880DF", | 82 ShortcutsBackend::Shortcut shortcut("BD85DBA2-8C29-49F9-84AE-48E1E90880DF", |
86 ASCIIToUTF16("goog"), ASCIIToUTF16("http://www.google.com"), | 83 ASCIIToUTF16("goog"), GURL("http://www.google.com"), |
87 ASCIIToUTF16("Google"), ASCIIToUTF16("0,1"), | 84 ASCIIToUTF16("Google"), |
88 ASCIIToUTF16("Google"), ASCIIToUTF16("0,1"), | 85 AutocompleteMatch::ClassificationsFromString("0,1"), |
89 base::Time::Now().ToInternalValue(), | 86 ASCIIToUTF16("Google"), |
90 100); | 87 AutocompleteMatch::ClassificationsFromString("0,1"), base::Time::Now(), |
| 88 100); |
91 EXPECT_TRUE(backend_->AddShortcut(shortcut)); | 89 EXPECT_TRUE(backend_->AddShortcut(shortcut)); |
92 | 90 |
93 const ShortcutMap& shortcuts = backend_->shortcuts_map(); | 91 const ShortcutsBackend::ShortcutMap& shortcuts = backend_->shortcuts_map(); |
94 ASSERT_TRUE(shortcuts.end() != shortcuts.find(shortcut.text)); | 92 ASSERT_TRUE(shortcuts.end() != shortcuts.find(shortcut.text)); |
95 EXPECT_EQ(shortcut.id, shortcuts.find(shortcut.text)->second.id); | 93 EXPECT_EQ(shortcut.id, shortcuts.find(shortcut.text)->second.id); |
96 EXPECT_EQ(shortcut.contents, shortcuts.find(shortcut.text)->second.contents); | 94 EXPECT_EQ(shortcut.contents, shortcuts.find(shortcut.text)->second.contents); |
97 shortcut.contents = ASCIIToUTF16("Google Web Search"); | 95 shortcut.contents = ASCIIToUTF16("Google Web Search"); |
98 EXPECT_TRUE(backend_->UpdateShortcut(shortcut)); | 96 EXPECT_TRUE(backend_->UpdateShortcut(shortcut)); |
99 EXPECT_EQ(shortcut.id, shortcuts.find(shortcut.text)->second.id); | 97 EXPECT_EQ(shortcut.id, shortcuts.find(shortcut.text)->second.id); |
100 EXPECT_EQ(shortcut.contents, shortcuts.find(shortcut.text)->second.contents); | 98 EXPECT_EQ(shortcut.contents, shortcuts.find(shortcut.text)->second.contents); |
101 } | 99 } |
102 | 100 |
103 TEST_F(ShortcutsBackendTest, DeleteShortcuts) { | 101 TEST_F(ShortcutsBackendTest, DeleteShortcuts) { |
104 InitBackend(); | 102 InitBackend(); |
105 Shortcut shortcut1("BD85DBA2-8C29-49F9-84AE-48E1E90880DF", | 103 ShortcutsBackend::Shortcut shortcut1("BD85DBA2-8C29-49F9-84AE-48E1E90880DF", |
106 ASCIIToUTF16("goog"), | 104 ASCIIToUTF16("goog"), GURL("http://www.google.com"), |
107 ASCIIToUTF16("http://www.google.com"), | 105 ASCIIToUTF16("Google"), |
108 ASCIIToUTF16("Google"), ASCIIToUTF16("0,1,4,0"), | 106 AutocompleteMatch::ClassificationsFromString("0,1,4,0"), |
109 ASCIIToUTF16("Google"), ASCIIToUTF16("0,3,4,1"), | 107 ASCIIToUTF16("Google"), |
110 base::Time::Now().ToInternalValue(), | 108 AutocompleteMatch::ClassificationsFromString("0,3,4,1"), |
111 100); | 109 base::Time::Now(), 100); |
112 EXPECT_TRUE(backend_->AddShortcut(shortcut1)); | 110 EXPECT_TRUE(backend_->AddShortcut(shortcut1)); |
113 | 111 |
114 Shortcut shortcut2("BD85DBA2-8C29-49F9-84AE-48E1E90880E0", | 112 ShortcutsBackend::Shortcut shortcut2("BD85DBA2-8C29-49F9-84AE-48E1E90880E0", |
115 ASCIIToUTF16("gle"), ASCIIToUTF16("http://www.google.com"), | 113 ASCIIToUTF16("gle"), GURL("http://www.google.com"), |
116 ASCIIToUTF16("Google"), ASCIIToUTF16("0,1"), | 114 ASCIIToUTF16("Google"), |
117 ASCIIToUTF16("Google"), ASCIIToUTF16("0,1"), | 115 AutocompleteMatch::ClassificationsFromString("0,1"), |
118 base::Time::Now().ToInternalValue(), | 116 ASCIIToUTF16("Google"), |
119 100); | 117 AutocompleteMatch::ClassificationsFromString("0,1"), base::Time::Now(), |
| 118 100); |
120 EXPECT_TRUE(backend_->AddShortcut(shortcut2)); | 119 EXPECT_TRUE(backend_->AddShortcut(shortcut2)); |
121 | 120 |
122 Shortcut shortcut3("BD85DBA2-8C29-49F9-84AE-48E1E90880E1", | 121 ShortcutsBackend::Shortcut shortcut3("BD85DBA2-8C29-49F9-84AE-48E1E90880E1", |
123 ASCIIToUTF16("sp"), ASCIIToUTF16("http://www.sport.com"), | 122 ASCIIToUTF16("sp"), GURL("http://www.sport.com"), ASCIIToUTF16("Sports"), |
124 ASCIIToUTF16("Sports"), ASCIIToUTF16("0,1"), | 123 AutocompleteMatch::ClassificationsFromString("0,1"), |
125 ASCIIToUTF16("Sport news"), ASCIIToUTF16("0,1"), | 124 ASCIIToUTF16("Sport news"), |
126 base::Time::Now().ToInternalValue(), | 125 AutocompleteMatch::ClassificationsFromString("0,1"), base::Time::Now(), |
127 10); | 126 10); |
128 EXPECT_TRUE(backend_->AddShortcut(shortcut3)); | 127 EXPECT_TRUE(backend_->AddShortcut(shortcut3)); |
129 | 128 |
130 Shortcut shortcut4("BD85DBA2-8C29-49F9-84AE-48E1E90880E2", | 129 ShortcutsBackend::Shortcut shortcut4("BD85DBA2-8C29-49F9-84AE-48E1E90880E2", |
131 ASCIIToUTF16("mov"), ASCIIToUTF16("http://www.film.com"), | 130 ASCIIToUTF16("mov"), GURL("http://www.film.com"), ASCIIToUTF16("Movies"), |
132 ASCIIToUTF16("Movies"), ASCIIToUTF16("0,1"), | 131 AutocompleteMatch::ClassificationsFromString("0,1"), |
133 ASCIIToUTF16("Movie news"), ASCIIToUTF16("0,1"), | 132 ASCIIToUTF16("Movie news"), |
134 base::Time::Now().ToInternalValue(), | 133 AutocompleteMatch::ClassificationsFromString("0,1"), base::Time::Now(), |
135 10); | 134 10); |
136 EXPECT_TRUE(backend_->AddShortcut(shortcut4)); | 135 EXPECT_TRUE(backend_->AddShortcut(shortcut4)); |
137 | 136 |
138 const ShortcutMap& shortcuts = backend_->shortcuts_map(); | 137 const ShortcutsBackend::ShortcutMap& shortcuts = backend_->shortcuts_map(); |
139 | 138 |
140 ASSERT_EQ(4U, shortcuts.size()); | 139 ASSERT_EQ(4U, shortcuts.size()); |
141 EXPECT_EQ(shortcut1.id, shortcuts.find(shortcut1.text)->second.id); | 140 EXPECT_EQ(shortcut1.id, shortcuts.find(shortcut1.text)->second.id); |
142 EXPECT_EQ(shortcut2.id, shortcuts.find(shortcut2.text)->second.id); | 141 EXPECT_EQ(shortcut2.id, shortcuts.find(shortcut2.text)->second.id); |
143 EXPECT_EQ(shortcut3.id, shortcuts.find(shortcut3.text)->second.id); | 142 EXPECT_EQ(shortcut3.id, shortcuts.find(shortcut3.text)->second.id); |
144 EXPECT_EQ(shortcut4.id, shortcuts.find(shortcut4.text)->second.id); | 143 EXPECT_EQ(shortcut4.id, shortcuts.find(shortcut4.text)->second.id); |
145 | 144 |
146 EXPECT_TRUE(backend_->DeleteShortcutsWithUrl(shortcut1.url)); | 145 EXPECT_TRUE(backend_->DeleteShortcutsWithUrl(shortcut1.url)); |
147 | 146 |
148 ASSERT_EQ(2U, shortcuts.size()); | 147 ASSERT_EQ(2U, shortcuts.size()); |
149 EXPECT_TRUE(shortcuts.end() == shortcuts.find(shortcut1.text)); | 148 EXPECT_TRUE(shortcuts.end() == shortcuts.find(shortcut1.text)); |
150 EXPECT_TRUE(shortcuts.end() == shortcuts.find(shortcut2.text)); | 149 EXPECT_TRUE(shortcuts.end() == shortcuts.find(shortcut2.text)); |
151 ASSERT_TRUE(shortcuts.end() != shortcuts.find(shortcut3.text)); | 150 ASSERT_TRUE(shortcuts.end() != shortcuts.find(shortcut3.text)); |
152 ASSERT_TRUE(shortcuts.end() != shortcuts.find(shortcut4.text)); | 151 ASSERT_TRUE(shortcuts.end() != shortcuts.find(shortcut4.text)); |
153 EXPECT_EQ(shortcut3.id, shortcuts.find(shortcut3.text)->second.id); | 152 EXPECT_EQ(shortcut3.id, shortcuts.find(shortcut3.text)->second.id); |
154 EXPECT_EQ(shortcut4.id, shortcuts.find(shortcut4.text)->second.id); | 153 EXPECT_EQ(shortcut4.id, shortcuts.find(shortcut4.text)->second.id); |
155 | 154 |
156 std::vector<std::string> deleted_ids; | 155 std::vector<std::string> deleted_ids; |
157 deleted_ids.push_back(shortcut3.id); | 156 deleted_ids.push_back(shortcut3.id); |
158 deleted_ids.push_back(shortcut4.id); | 157 deleted_ids.push_back(shortcut4.id); |
159 | 158 |
160 EXPECT_TRUE(backend_->DeleteShortcutsWithIds(deleted_ids)); | 159 EXPECT_TRUE(backend_->DeleteShortcutsWithIds(deleted_ids)); |
161 | 160 |
162 ASSERT_EQ(0U, shortcuts.size()); | 161 ASSERT_EQ(0U, shortcuts.size()); |
163 } | 162 } |
164 | 163 |
165 } // namespace history | 164 } // namespace history |
OLD | NEW |