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

Side by Side Diff: chrome/browser/sync/profile_sync_service_bookmark_unittest.cc

Issue 1105413002: Avoid conversion of index to BookmarkNode pointer unnacessarily. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes as per review comments. Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // TODO(akalin): This file is basically just a unit test for 5 // TODO(akalin): This file is basically just a unit test for
6 // BookmarkChangeProcessor. Write unit tests for 6 // BookmarkChangeProcessor. Write unit tests for
7 // BookmarkModelAssociator separately. 7 // BookmarkModelAssociator separately.
8 8
9 #include <map> 9 #include <map>
10 #include <queue> 10 #include <queue>
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 ExpectModelMatch(); 1039 ExpectModelMatch();
1040 model_->SetTitle(folder, base::ASCIIToUTF16("who's nested now?")); 1040 model_->SetTitle(folder, base::ASCIIToUTF16("who's nested now?"));
1041 ExpectModelMatch(); 1041 ExpectModelMatch();
1042 model_->Copy(url2, model_->bookmark_bar_node(), 0); 1042 model_->Copy(url2, model_->bookmark_bar_node(), 0);
1043 ExpectModelMatch(); 1043 ExpectModelMatch();
1044 model_->SetTitle(mobile_folder, base::ASCIIToUTF16("strawberry")); 1044 model_->SetTitle(mobile_folder, base::ASCIIToUTF16("strawberry"));
1045 ExpectModelMatch(); 1045 ExpectModelMatch();
1046 1046
1047 // Test deletion. 1047 // Test deletion.
1048 // Delete a single item. 1048 // Delete a single item.
1049 model_->Remove(url2->parent(), url2->parent()->GetIndexOf(url2)); 1049 model_->Remove(url2);
1050 ExpectModelMatch(); 1050 ExpectModelMatch();
1051 // Delete an item with several children. 1051 // Delete an item with several children.
1052 model_->Remove(folder2->parent(), 1052 model_->Remove(folder2);
1053 folder2->parent()->GetIndexOf(folder2));
1054 ExpectModelMatch(); 1053 ExpectModelMatch();
1055 model_->Remove(model_->mobile_node(), 0); 1054 model_->Remove(model_->mobile_node()->GetChild(0));
1056 ExpectModelMatch(); 1055 ExpectModelMatch();
1057 } 1056 }
1058 1057
1059 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) { 1058 TEST_F(ProfileSyncServiceBookmarkTest, ServerChangeProcessing) {
1060 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1059 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1061 StartSync(); 1060 StartSync();
1062 1061
1063 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share()); 1062 syncer::WriteTransaction trans(FROM_HERE, test_user_share_.user_share());
1064 1063
1065 FakeServerChange adds(&trans); 1064 FakeServerChange adds(&trans);
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 WriteTestDataToBookmarkModel(); 1915 WriteTestDataToBookmarkModel();
1917 ExpectBookmarkModelMatchesTestData(); 1916 ExpectBookmarkModelMatchesTestData();
1918 1917
1919 // Remove some nodes and reorder some nodes. 1918 // Remove some nodes and reorder some nodes.
1920 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); 1919 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node();
1921 int remove_index = 2; 1920 int remove_index = 2;
1922 ASSERT_GT(bookmark_bar_node->child_count(), remove_index); 1921 ASSERT_GT(bookmark_bar_node->child_count(), remove_index);
1923 const BookmarkNode* child_node = bookmark_bar_node->GetChild(remove_index); 1922 const BookmarkNode* child_node = bookmark_bar_node->GetChild(remove_index);
1924 ASSERT_TRUE(child_node); 1923 ASSERT_TRUE(child_node);
1925 ASSERT_TRUE(child_node->is_url()); 1924 ASSERT_TRUE(child_node->is_url());
1926 model_->Remove(bookmark_bar_node, remove_index); 1925 model_->Remove(bookmark_bar_node->GetChild(remove_index));
1927 ASSERT_GT(bookmark_bar_node->child_count(), remove_index); 1926 ASSERT_GT(bookmark_bar_node->child_count(), remove_index);
1928 child_node = bookmark_bar_node->GetChild(remove_index); 1927 child_node = bookmark_bar_node->GetChild(remove_index);
1929 ASSERT_TRUE(child_node); 1928 ASSERT_TRUE(child_node);
1930 ASSERT_TRUE(child_node->is_folder()); 1929 ASSERT_TRUE(child_node->is_folder());
1931 model_->Remove(bookmark_bar_node, remove_index); 1930 model_->Remove(bookmark_bar_node->GetChild(remove_index));
1932 1931
1933 const BookmarkNode* other_node = model_->other_node(); 1932 const BookmarkNode* other_node = model_->other_node();
1934 ASSERT_GE(other_node->child_count(), 1); 1933 ASSERT_GE(other_node->child_count(), 1);
1935 const BookmarkNode* f3_node = other_node->GetChild(0); 1934 const BookmarkNode* f3_node = other_node->GetChild(0);
1936 ASSERT_TRUE(f3_node); 1935 ASSERT_TRUE(f3_node);
1937 ASSERT_TRUE(f3_node->is_folder()); 1936 ASSERT_TRUE(f3_node->is_folder());
1938 remove_index = 2; 1937 remove_index = 2;
1939 ASSERT_GT(f3_node->child_count(), remove_index); 1938 ASSERT_GT(f3_node->child_count(), remove_index);
1940 model_->Remove(f3_node, remove_index); 1939 model_->Remove(f3_node->GetChild(remove_index));
1941 ASSERT_GT(f3_node->child_count(), remove_index); 1940 ASSERT_GT(f3_node->child_count(), remove_index);
1942 model_->Remove(f3_node, remove_index); 1941 model_->Remove(f3_node->GetChild(remove_index));
1943 1942
1944 StartSync(); 1943 StartSync();
1945 ExpectModelMatch(); 1944 ExpectModelMatch();
1946 StopSync(); 1945 StopSync();
1947 1946
1948 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE); 1947 LoadBookmarkModel(DELETE_EXISTING_STORAGE, DONT_SAVE_TO_STORAGE);
1949 WriteTestDataToBookmarkModel(); 1948 WriteTestDataToBookmarkModel();
1950 ExpectBookmarkModelMatchesTestData(); 1949 ExpectBookmarkModelMatchesTestData();
1951 1950
1952 // Remove some nodes and reorder some nodes. 1951 // Remove some nodes and reorder some nodes.
1953 bookmark_bar_node = model_->bookmark_bar_node(); 1952 bookmark_bar_node = model_->bookmark_bar_node();
1954 remove_index = 0; 1953 remove_index = 0;
1955 ASSERT_GT(bookmark_bar_node->child_count(), remove_index); 1954 ASSERT_GT(bookmark_bar_node->child_count(), remove_index);
1956 child_node = bookmark_bar_node->GetChild(remove_index); 1955 child_node = bookmark_bar_node->GetChild(remove_index);
1957 ASSERT_TRUE(child_node); 1956 ASSERT_TRUE(child_node);
1958 ASSERT_TRUE(child_node->is_url()); 1957 ASSERT_TRUE(child_node->is_url());
1959 model_->Remove(bookmark_bar_node, remove_index); 1958 model_->Remove(bookmark_bar_node->GetChild(remove_index));
1960 ASSERT_GT(bookmark_bar_node->child_count(), remove_index); 1959 ASSERT_GT(bookmark_bar_node->child_count(), remove_index);
1961 child_node = bookmark_bar_node->GetChild(remove_index); 1960 child_node = bookmark_bar_node->GetChild(remove_index);
1962 ASSERT_TRUE(child_node); 1961 ASSERT_TRUE(child_node);
1963 ASSERT_TRUE(child_node->is_folder()); 1962 ASSERT_TRUE(child_node->is_folder());
1964 model_->Remove(bookmark_bar_node, remove_index); 1963 model_->Remove(bookmark_bar_node->GetChild(remove_index));
1965 1964
1966 ASSERT_GE(bookmark_bar_node->child_count(), 2); 1965 ASSERT_GE(bookmark_bar_node->child_count(), 2);
1967 model_->Move(bookmark_bar_node->GetChild(0), bookmark_bar_node, 1); 1966 model_->Move(bookmark_bar_node->GetChild(0), bookmark_bar_node, 1);
1968 1967
1969 other_node = model_->other_node(); 1968 other_node = model_->other_node();
1970 ASSERT_GE(other_node->child_count(), 1); 1969 ASSERT_GE(other_node->child_count(), 1);
1971 f3_node = other_node->GetChild(0); 1970 f3_node = other_node->GetChild(0);
1972 ASSERT_TRUE(f3_node); 1971 ASSERT_TRUE(f3_node);
1973 ASSERT_TRUE(f3_node->is_folder()); 1972 ASSERT_TRUE(f3_node->is_folder());
1974 remove_index = 0; 1973 remove_index = 0;
1975 ASSERT_GT(f3_node->child_count(), remove_index); 1974 ASSERT_GT(f3_node->child_count(), remove_index);
1976 model_->Remove(f3_node, remove_index); 1975 model_->Remove(f3_node->GetChild(remove_index));
1977 ASSERT_GT(f3_node->child_count(), remove_index); 1976 ASSERT_GT(f3_node->child_count(), remove_index);
1978 model_->Remove(f3_node, remove_index); 1977 model_->Remove(f3_node->GetChild(remove_index));
1979 1978
1980 ASSERT_GE(other_node->child_count(), 4); 1979 ASSERT_GE(other_node->child_count(), 4);
1981 model_->Move(other_node->GetChild(0), other_node, 1); 1980 model_->Move(other_node->GetChild(0), other_node, 1);
1982 model_->Move(other_node->GetChild(2), other_node, 3); 1981 model_->Move(other_node->GetChild(2), other_node, 3);
1983 1982
1984 StartSync(); 1983 StartSync();
1985 ExpectModelMatch(); 1984 ExpectModelMatch();
1986 1985
1987 // After the merge, the model should match the test data. 1986 // After the merge, the model should match the test data.
1988 ExpectBookmarkModelMatchesTestData(); 1987 ExpectBookmarkModelMatchesTestData();
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
2332 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), 2331 ExpectTransactionVersionMatch(model_->bookmark_bar_node(),
2333 BookmarkNodeVersionMap()); 2332 BookmarkNodeVersionMap());
2334 ExpectTransactionVersionMatch(model_->other_node(), 2333 ExpectTransactionVersionMatch(model_->other_node(),
2335 BookmarkNodeVersionMap()); 2334 BookmarkNodeVersionMap());
2336 ExpectTransactionVersionMatch(model_->mobile_node(), 2335 ExpectTransactionVersionMatch(model_->mobile_node(),
2337 BookmarkNodeVersionMap()); 2336 BookmarkNodeVersionMap());
2338 2337
2339 // Verify model version is incremented and bookmark node versions remain 2338 // Verify model version is incremented and bookmark node versions remain
2340 // the same. 2339 // the same.
2341 const BookmarkNode* bookmark_bar = model_->bookmark_bar_node(); 2340 const BookmarkNode* bookmark_bar = model_->bookmark_bar_node();
2342 model_->Remove(bookmark_bar, 0); 2341 model_->Remove(bookmark_bar->GetChild(0));
2343 base::MessageLoop::current()->RunUntilIdle(); 2342 base::MessageLoop::current()->RunUntilIdle();
2344 BookmarkNodeVersionMap new_versions; 2343 BookmarkNodeVersionMap new_versions;
2345 GetTransactionVersions(model_->root_node(), &new_versions); 2344 GetTransactionVersions(model_->root_node(), &new_versions);
2346 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 1, 2345 EXPECT_EQ(initial_versions[model_->root_node()->id()] + 1,
2347 new_versions[model_->root_node()->id()]); 2346 new_versions[model_->root_node()->id()]);
2348 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions); 2347 ExpectTransactionVersionMatch(model_->bookmark_bar_node(), initial_versions);
2349 ExpectTransactionVersionMatch(model_->other_node(), initial_versions); 2348 ExpectTransactionVersionMatch(model_->other_node(), initial_versions);
2350 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions); 2349 ExpectTransactionVersionMatch(model_->mobile_node(), initial_versions);
2351 2350
2352 // Verify model version and version of changed bookmark are incremented and 2351 // Verify model version and version of changed bookmark are incremented and
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2431 ExpectModelMatch(); 2430 ExpectModelMatch();
2432 2431
2433 // Then simulate the add call arriving late. 2432 // Then simulate the add call arriving late.
2434 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0); 2433 change_processor_->BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0);
2435 ExpectModelMatch(); 2434 ExpectModelMatch();
2436 } 2435 }
2437 2436
2438 } // namespace 2437 } // namespace
2439 2438
2440 } // namespace browser_sync 2439 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698