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/rand_util.h" | 5 #include "base/rand_util.h" |
6 #include "chrome/browser/profiles/profile.h" | 6 #include "chrome/browser/profiles/profile.h" |
7 #include "chrome/browser/sync/profile_sync_service_harness.h" | 7 #include "chrome/browser/sync/profile_sync_service_harness.h" |
8 #include "chrome/browser/sync/sessions/session_state.h" | 8 #include "chrome/browser/sync/sessions/session_state.h" |
9 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" | 9 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
10 #include "chrome/browser/sync/test/integration/sync_test.h" | 10 #include "chrome/browser/sync/test/integration/sync_test.h" |
(...skipping 1817 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1828 num_conflicting_updates); | 1828 num_conflicting_updates); |
1829 | 1829 |
1830 // Ensure everything is syncing normally by appending a final bookmark. | 1830 // Ensure everything is syncing normally by appending a final bookmark. |
1831 ASSERT_TRUE(AddURL(1, 5, IndexedURLTitle(5), GURL(IndexedURL(5))) != NULL); | 1831 ASSERT_TRUE(AddURL(1, 5, IndexedURLTitle(5), GURL(IndexedURL(5))) != NULL); |
1832 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); | 1832 ASSERT_TRUE(GetClient(1)->AwaitMutualSyncCycleCompletion(GetClient(0))); |
1833 EXPECT_TRUE(AllModelsMatchVerifier()); | 1833 EXPECT_TRUE(AllModelsMatchVerifier()); |
1834 EXPECT_TRUE(AllModelsMatch()); | 1834 EXPECT_TRUE(AllModelsMatch()); |
1835 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> | 1835 ASSERT_EQ(0, GetClient(1)->GetLastSessionSnapshot()-> |
1836 num_conflicting_updates); | 1836 num_conflicting_updates); |
1837 } | 1837 } |
| 1838 |
| 1839 // Deliberately racy rearranging of bookmarks to test that our conflict resolver |
| 1840 // code results in a consistent view across machines (no matter what the final |
| 1841 // order is). |
| 1842 IN_PROC_BROWSER_TEST_F(TwoClientBookmarksSyncTest, RacyPositionChanges) { |
| 1843 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 1844 ASSERT_TRUE(AllModelsMatchVerifier()); |
| 1845 |
| 1846 // Add initial bookmarks. |
| 1847 size_t num_bookmarks = 5; |
| 1848 for (size_t i = 0; i < num_bookmarks; ++i) { |
| 1849 ASSERT_TRUE(AddURL(0, i, IndexedURLTitle(i), GURL(IndexedURL(i))) != NULL); |
| 1850 } |
| 1851 |
| 1852 // Once we make diverging changes the verifer is helpless. |
| 1853 ASSERT_TRUE(AwaitQuiescence()); |
| 1854 ASSERT_TRUE(AllModelsMatchVerifier()); |
| 1855 DisableVerifier(); |
| 1856 |
| 1857 // Make changes on client 0. |
| 1858 for (size_t i = 0; i < num_bookmarks; ++i) { |
| 1859 const BookmarkNode* node = GetUniqueNodeByURL(0, GURL(IndexedURL(i))); |
| 1860 int rand_pos = base::RandInt(0, num_bookmarks-1); |
| 1861 DVLOG(1) << "Moving client 0's bookmark " << i << " to position " |
| 1862 << rand_pos; |
| 1863 Move(0, node, node->parent(), rand_pos); |
| 1864 } |
| 1865 |
| 1866 // Make changes on client 1. |
| 1867 for (size_t i = 0; i < num_bookmarks; ++i) { |
| 1868 const BookmarkNode* node = GetUniqueNodeByURL(1, GURL(IndexedURL(i))); |
| 1869 int rand_pos = base::RandInt(0, num_bookmarks-1); |
| 1870 DVLOG(1) << "Moving client 1's bookmark " << i << " to position " |
| 1871 << rand_pos; |
| 1872 Move(1, node, node->parent(), rand_pos); |
| 1873 } |
| 1874 |
| 1875 ASSERT_TRUE(AwaitQuiescence()); |
| 1876 ASSERT_TRUE(AllModelsMatch()); |
| 1877 |
| 1878 // Now make changes to client 1 first. |
| 1879 for (size_t i = 0; i < num_bookmarks; ++i) { |
| 1880 const BookmarkNode* node = GetUniqueNodeByURL(1, GURL(IndexedURL(i))); |
| 1881 int rand_pos = base::RandInt(0, num_bookmarks-1); |
| 1882 DVLOG(1) << "Moving client 1's bookmark " << i << " to position " |
| 1883 << rand_pos; |
| 1884 Move(1, node, node->parent(), rand_pos); |
| 1885 } |
| 1886 |
| 1887 // Make changes on client 0. |
| 1888 for (size_t i = 0; i < num_bookmarks; ++i) { |
| 1889 const BookmarkNode* node = GetUniqueNodeByURL(0, GURL(IndexedURL(i))); |
| 1890 int rand_pos = base::RandInt(0, num_bookmarks-1); |
| 1891 DVLOG(1) << "Moving client 0's bookmark " << i << " to position " |
| 1892 << rand_pos; |
| 1893 Move(0, node, node->parent(), rand_pos); |
| 1894 } |
| 1895 |
| 1896 ASSERT_TRUE(AwaitQuiescence()); |
| 1897 ASSERT_TRUE(AllModelsMatch()); |
| 1898 } |
OLD | NEW |