- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / sync / test / integration / performance / bookmarks_sync_perf_test.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/sync/profile_sync_service_harness.h"
6 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
7 #include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h"
8 #include "chrome/browser/sync/test/integration/sync_test.h"
9
10 using bookmarks_helper::AddURL;
11 using bookmarks_helper::AllModelsMatch;
12 using bookmarks_helper::GetBookmarkBarNode;
13 using bookmarks_helper::IndexedURL;
14 using bookmarks_helper::IndexedURLTitle;
15 using bookmarks_helper::Remove;
16 using bookmarks_helper::SetURL;
17
18 static const int kNumBookmarks = 150;
19
20 class BookmarksSyncPerfTest : public SyncTest {
21  public:
22   BookmarksSyncPerfTest()
23       : SyncTest(TWO_CLIENT),
24         url_number_(0),
25         url_title_number_(0) {}
26
27   // Adds |num_urls| new unique bookmarks to the bookmark bar for |profile|.
28   void AddURLs(int profile, int num_urls);
29
30   // Updates the URL for all bookmarks in the bookmark bar for |profile|.
31   void UpdateURLs(int profile);
32
33   // Removes all bookmarks in the bookmark bar for |profile|.
34   void RemoveURLs(int profile);
35
36   // Returns the number of bookmarks stored in the bookmark bar for |profile|.
37   int GetURLCount(int profile);
38
39  private:
40   // Returns a new unique bookmark URL.
41   std::string NextIndexedURL();
42
43   // Returns a new unique bookmark title.
44   std::wstring NextIndexedURLTitle();
45
46   int url_number_;
47   int url_title_number_;
48   DISALLOW_COPY_AND_ASSIGN(BookmarksSyncPerfTest);
49 };
50
51 void BookmarksSyncPerfTest::AddURLs(int profile, int num_urls) {
52   for (int i = 0; i < num_urls; ++i) {
53     ASSERT_TRUE(AddURL(
54         profile, 0, NextIndexedURLTitle(), GURL(NextIndexedURL())) != NULL);
55   }
56 }
57
58 void BookmarksSyncPerfTest::UpdateURLs(int profile) {
59   for (int i = 0;
60        i < GetBookmarkBarNode(profile)->child_count();
61        ++i) {
62     ASSERT_TRUE(SetURL(profile,
63                        GetBookmarkBarNode(profile)->GetChild(i),
64                        GURL(NextIndexedURL())));
65   }
66 }
67
68 void BookmarksSyncPerfTest::RemoveURLs(int profile) {
69   while (!GetBookmarkBarNode(profile)->empty()) {
70     Remove(profile, GetBookmarkBarNode(profile), 0);
71   }
72 }
73
74 int BookmarksSyncPerfTest::GetURLCount(int profile) {
75   return GetBookmarkBarNode(profile)->child_count();
76 }
77
78 std::string BookmarksSyncPerfTest::NextIndexedURL() {
79   return IndexedURL(url_number_++);
80 }
81
82 std::wstring BookmarksSyncPerfTest::NextIndexedURLTitle() {
83   return IndexedURLTitle(url_title_number_++);
84 }
85
86 IN_PROC_BROWSER_TEST_F(BookmarksSyncPerfTest, P0) {
87   ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
88
89   // TCM ID - 7556828.
90   AddURLs(0, kNumBookmarks);
91   base::TimeDelta dt =
92       SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
93   ASSERT_EQ(kNumBookmarks, GetURLCount(1));
94   SyncTimingHelper::PrintResult("bookmarks", "add_bookmarks", dt);
95
96   // TCM ID - 7564762.
97   UpdateURLs(0);
98   dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
99   ASSERT_EQ(kNumBookmarks, GetURLCount(1));
100   SyncTimingHelper::PrintResult("bookmarks", "update_bookmarks", dt);
101
102   // TCM ID - 7566626.
103   RemoveURLs(0);
104   dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
105   ASSERT_EQ(0, GetURLCount(1));
106   SyncTimingHelper::PrintResult("bookmarks", "delete_bookmarks", dt);
107 }