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

Side by Side Diff: chrome/browser/bookmarks/bookmark_table_model_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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "base/time.h" 6 #include "base/time.h"
7 #include "chrome/browser/bookmarks/bookmark_table_model.h" 7 #include "chrome/browser/bookmarks/bookmark_table_model.h"
8 #include "chrome/test/testing_profile.h" 8 #include "chrome/test/testing_profile.h"
9 #include "grit/generated_resources.h" 9 #include "grit/generated_resources.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 15 matching lines...) Expand all
26 public views::TableModelObserver { 26 public views::TableModelObserver {
27 public: 27 public:
28 BookmarkTableModelTest() 28 BookmarkTableModelTest()
29 : url1_("http://1"), 29 : url1_("http://1"),
30 url2_("http://2"), 30 url2_("http://2"),
31 url3_("http://3"), 31 url3_("http://3"),
32 changed_count_(0), 32 changed_count_(0),
33 item_changed_count_(0), 33 item_changed_count_(0),
34 added_count_(0), 34 added_count_(0),
35 removed_count_(0) { 35 removed_count_(0) {
36 } 36 }
37 37
38 virtual void SetUp() { 38 virtual void SetUp() {
39 profile_.reset(new TestingProfile()); 39 profile_.reset(new TestingProfile());
40 profile_->CreateBookmarkModel(true); 40 profile_->CreateBookmarkModel(true);
41 // Populate with some default data. 41 // Populate with some default data.
42 Time t0 = Time::Now(); 42 Time t0 = Time::Now();
43 BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode(); 43 BookmarkNode* bb = bookmark_model()->GetBookmarkBarNode();
44 bookmark_model()->AddURLWithCreationTime(bb, 0, L"a", url1_, t0); 44 bookmark_model()->AddURLWithCreationTime(bb, 0, L"a", url1_, t0);
45 bookmark_model()->AddGroup(bb, 1, L"f1"); 45 bookmark_model()->AddGroup(bb, 1, L"f1");
46 46
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 VerifyAndClearOberserverCounts(0, 1, 0, 0); 241 VerifyAndClearOberserverCounts(0, 1, 0, 0);
242 242
243 // Change a folder, this shouldn't change the model. 243 // Change a folder, this shouldn't change the model.
244 bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(1), 244 bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(1),
245 L"new"); 245 L"new");
246 VerifyAndClearOberserverCounts(0, 0, 0, 0); 246 VerifyAndClearOberserverCounts(0, 0, 0, 0);
247 } 247 }
248 248
249 // Verifies search finds the correct bookmarks. 249 // Verifies search finds the correct bookmarks.
250 TEST_F(BookmarkTableModelTest, Search) { 250 TEST_F(BookmarkTableModelTest, Search) {
251 SetModel(BookmarkTableModel::CreateSearchTableModel(bookmark_model(), L"c")); 251 SetModel(BookmarkTableModel::CreateSearchTableModel(
252 bookmark_model(), L"c", std::wstring()));
252 ASSERT_EQ(1, model_->RowCount()); 253 ASSERT_EQ(1, model_->RowCount());
253 EXPECT_TRUE(bookmark_model()->other_node()->GetChild(2) == 254 EXPECT_TRUE(bookmark_model()->other_node()->GetChild(2) ==
254 model_->GetNodeForRow(0)); 255 model_->GetNodeForRow(0));
255 // Make sure IndexOfNode works. 256 // Make sure IndexOfNode works.
256 EXPECT_EQ(0, 257 EXPECT_EQ(0,
257 model_->IndexOfNode(bookmark_model()->other_node()->GetChild(2))); 258 model_->IndexOfNode(bookmark_model()->other_node()->GetChild(2)));
258 } 259 }
259 260
260 // Verifies adding an item to search notifies observers. 261 // Verifies adding an item to search notifies observers.
261 TEST_F(BookmarkTableModelTest, AddToSearch) { 262 TEST_F(BookmarkTableModelTest, AddToSearch) {
262 SetModel(BookmarkTableModel::CreateSearchTableModel(bookmark_model(), L"c")); 263 SetModel(BookmarkTableModel::CreateSearchTableModel(
264 bookmark_model(), L"c", std::wstring()));
263 BookmarkNode* new_node = 265 BookmarkNode* new_node =
264 bookmark_model()->AddURL(bookmark_model()->other_node(), 0, L"c", url1_); 266 bookmark_model()->AddURL(bookmark_model()->other_node(), 0, L"c", url1_);
265 // Should have gotten notification of the add. 267 // Should have gotten notification of the add.
266 VerifyAndClearOberserverCounts(0, 0, 1, 0); 268 VerifyAndClearOberserverCounts(0, 0, 1, 0);
267 ASSERT_EQ(2, model_->RowCount()); 269 ASSERT_EQ(2, model_->RowCount());
268 // New node should have gone to end. 270 // New node should have gone to end.
269 EXPECT_TRUE(model_->GetNodeForRow(1) == new_node); 271 EXPECT_TRUE(model_->GetNodeForRow(1) == new_node);
270 272
271 // Add a folder, this shouldn't change the model. 273 // Add a folder, this shouldn't change the model.
272 bookmark_model()->AddGroup(bookmark_model()->GetBookmarkBarNode(), 0, L"new"); 274 bookmark_model()->AddGroup(bookmark_model()->GetBookmarkBarNode(), 0, L"new");
273 VerifyAndClearOberserverCounts(0, 0, 0, 0); 275 VerifyAndClearOberserverCounts(0, 0, 0, 0);
274 EXPECT_EQ(2, model_->RowCount()); 276 EXPECT_EQ(2, model_->RowCount());
275 277
276 // Add a url that doesn't match search, this shouldn't change the model. 278 // Add a url that doesn't match search, this shouldn't change the model.
277 bookmark_model()->AddGroup(bookmark_model()->GetBookmarkBarNode(), 0, L"new"); 279 bookmark_model()->AddGroup(bookmark_model()->GetBookmarkBarNode(), 0, L"new");
278 VerifyAndClearOberserverCounts(0, 0, 0, 0); 280 VerifyAndClearOberserverCounts(0, 0, 0, 0);
279 EXPECT_EQ(2, model_->RowCount()); 281 EXPECT_EQ(2, model_->RowCount());
280 } 282 }
281 283
282 // Verifies removing an item updates search. 284 // Verifies removing an item updates search.
283 TEST_F(BookmarkTableModelTest, RemoveFromSearch) { 285 TEST_F(BookmarkTableModelTest, RemoveFromSearch) {
284 SetModel(BookmarkTableModel::CreateSearchTableModel(bookmark_model(), L"c")); 286 SetModel(BookmarkTableModel::CreateSearchTableModel(
287 bookmark_model(), L"c", std::wstring()));
285 bookmark_model()->Remove(bookmark_model()->other_node(), 2); 288 bookmark_model()->Remove(bookmark_model()->other_node(), 2);
286 // Should have gotten notification of the remove. 289 // Should have gotten notification of the remove.
287 VerifyAndClearOberserverCounts(0, 0, 0, 1); 290 VerifyAndClearOberserverCounts(0, 0, 0, 1);
288 EXPECT_EQ(0, model_->RowCount()); 291 EXPECT_EQ(0, model_->RowCount());
289 292
290 // Remove a folder, this shouldn't change the model. 293 // Remove a folder, this shouldn't change the model.
291 bookmark_model()->Remove(bookmark_model()->other_node(), 1); 294 bookmark_model()->Remove(bookmark_model()->other_node(), 1);
292 VerifyAndClearOberserverCounts(0, 0, 0, 0); 295 VerifyAndClearOberserverCounts(0, 0, 0, 0);
293 296
294 // Remove another url that isn't in the model, this shouldn't change anything. 297 // Remove another url that isn't in the model, this shouldn't change anything.
295 bookmark_model()->Remove(bookmark_model()->other_node(), 0); 298 bookmark_model()->Remove(bookmark_model()->other_node(), 0);
296 VerifyAndClearOberserverCounts(0, 0, 0, 0); 299 VerifyAndClearOberserverCounts(0, 0, 0, 0);
297 } 300 }
298 301
299 // Verifies changing an item in search notifies observer. 302 // Verifies changing an item in search notifies observer.
300 TEST_F(BookmarkTableModelTest, ChangeSearch) { 303 TEST_F(BookmarkTableModelTest, ChangeSearch) {
301 SetModel(BookmarkTableModel::CreateSearchTableModel(bookmark_model(), L"c")); 304 SetModel(BookmarkTableModel::CreateSearchTableModel(bookmark_model(),
305 L"c", std::wstring()));
302 bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(2), 306 bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(2),
303 L"new"); 307 L"new");
304 // Should have gotten notification of the change. 308 // Should have gotten notification of the change.
305 VerifyAndClearOberserverCounts(0, 1, 0, 0); 309 VerifyAndClearOberserverCounts(0, 1, 0, 0);
306 310
307 // Change a folder, this shouldn't change the model. 311 // Change a folder, this shouldn't change the model.
308 bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(1), 312 bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(1),
309 L"new"); 313 L"new");
310 VerifyAndClearOberserverCounts(0, 0, 0, 0); 314 VerifyAndClearOberserverCounts(0, 0, 0, 0);
311 315
312 // Change a url that isn't in the model, this shouldn't send change. 316 // Change a url that isn't in the model, this shouldn't send change.
313 bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(0), 317 bookmark_model()->SetTitle(bookmark_model()->other_node()->GetChild(0),
314 L"new"); 318 L"new");
315 VerifyAndClearOberserverCounts(0, 0, 0, 0); 319 VerifyAndClearOberserverCounts(0, 0, 0, 0);
316 } 320 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_table_model.cc ('k') | chrome/browser/bookmarks/bookmark_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698