OLD | NEW |
| (Empty) |
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 "base/stringprintf.h" | |
6 #include "chrome/browser/ui/browser.h" | |
7 #include "chrome/browser/sync/profile_sync_service_harness.h" | |
8 #include "chrome/test/live_sync/performance/sync_timing_helper.h" | |
9 #include "chrome/test/live_sync/live_sync_test.h" | |
10 #include "chrome/test/live_sync/sessions_helper.h" | |
11 | |
12 using sessions_helper::GetLocalSession; | |
13 using sessions_helper::GetSessionData; | |
14 using sessions_helper::OpenMultipleTabs; | |
15 using sessions_helper::WaitForTabsToLoad; | |
16 | |
17 static const int kNumTabs = 150; | |
18 | |
19 class SessionsSyncPerfTest: public LiveSyncTest { | |
20 public: | |
21 SessionsSyncPerfTest() : LiveSyncTest(TWO_CLIENT), url_number_(0) {} | |
22 | |
23 // Opens |num_tabs| new tabs on |profile|. | |
24 void AddTabs(int profile, int num_tabs); | |
25 | |
26 // Update all tabs in |profile| by visiting a new URL. | |
27 void UpdateTabs(int profile); | |
28 | |
29 // Close all tabs in |profile|. | |
30 void RemoveTabs(int profile); | |
31 | |
32 // Returns the number of open tabs in all sessions (local + foreign) for | |
33 // |profile|. Returns -1 on failure. | |
34 int GetTabCount(int profile); | |
35 | |
36 private: | |
37 // Returns a new unique URL. | |
38 GURL NextURL(); | |
39 | |
40 // Returns a unique URL according to the integer |n|. | |
41 GURL IntToURL(int n); | |
42 | |
43 int url_number_; | |
44 DISALLOW_COPY_AND_ASSIGN(SessionsSyncPerfTest); | |
45 }; | |
46 | |
47 void SessionsSyncPerfTest::AddTabs(int profile, int num_tabs) { | |
48 std::vector<GURL> urls; | |
49 for (int i = 0; i < num_tabs; ++i) { | |
50 urls.push_back(NextURL()); | |
51 } | |
52 OpenMultipleTabs(profile, urls); | |
53 } | |
54 | |
55 void SessionsSyncPerfTest::UpdateTabs(int profile) { | |
56 Browser* browser = GetBrowser(profile); | |
57 GURL url; | |
58 std::vector<GURL> urls; | |
59 for (int i = 0; i < browser->tab_count(); ++i) { | |
60 browser->SelectNumberedTab(i); | |
61 url = NextURL(); | |
62 browser->OpenURL( | |
63 OpenURLParams(url, GURL("www.google.com"), CURRENT_TAB, 0)); | |
64 urls.push_back(url); | |
65 } | |
66 WaitForTabsToLoad(profile, urls); | |
67 } | |
68 | |
69 void SessionsSyncPerfTest::RemoveTabs(int profile) { | |
70 GetBrowser(profile)->CloseAllTabs(); | |
71 } | |
72 | |
73 int SessionsSyncPerfTest::GetTabCount(int profile) { | |
74 int tab_count = 0; | |
75 const SyncedSession* local_session; | |
76 SyncedSessionVector sessions; | |
77 | |
78 if (!GetLocalSession(profile, &local_session)) { | |
79 VLOG(1) << "GetLocalSession returned false"; | |
80 return -1; | |
81 } | |
82 | |
83 if (!GetSessionData(profile, &sessions)) { | |
84 // Foreign session data may be empty. In this case we only count tabs in | |
85 // the local session. | |
86 VLOG(1) << "GetSessionData returned false"; | |
87 } | |
88 | |
89 sessions.push_back(local_session); | |
90 for (SyncedSessionVector::const_iterator it = sessions.begin(); | |
91 it != sessions.end(); ++it) { | |
92 for (SessionWindowVector::const_iterator win_it = (*it)->windows.begin(); | |
93 win_it != (*it)->windows.end(); | |
94 ++win_it) { | |
95 tab_count += (*win_it)->tabs.size(); | |
96 } | |
97 } | |
98 return tab_count; | |
99 } | |
100 | |
101 GURL SessionsSyncPerfTest::NextURL() { | |
102 return IntToURL(url_number_++); | |
103 } | |
104 | |
105 GURL SessionsSyncPerfTest::IntToURL(int n) { | |
106 return GURL(StringPrintf("http://history%d.google.com/", n)); | |
107 } | |
108 | |
109 IN_PROC_BROWSER_TEST_F(SessionsSyncPerfTest, P0) { | |
110 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | |
111 | |
112 AddTabs(0, kNumTabs); | |
113 base::TimeDelta dt = | |
114 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
115 ASSERT_EQ(kNumTabs, GetTabCount(0)); | |
116 ASSERT_EQ(kNumTabs, GetTabCount(1)); | |
117 SyncTimingHelper::PrintResult("tabs", "add_tabs", dt); | |
118 | |
119 UpdateTabs(0); | |
120 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
121 ASSERT_EQ(kNumTabs, GetTabCount(0)); | |
122 ASSERT_EQ(kNumTabs, GetTabCount(1)); | |
123 SyncTimingHelper::PrintResult("tabs", "update_tabs", dt); | |
124 | |
125 RemoveTabs(0); | |
126 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | |
127 // New tab page remains open on profile 0 after closing all tabs. | |
128 ASSERT_EQ(1, GetTabCount(0)); | |
129 ASSERT_EQ(0, GetTabCount(1)); | |
130 SyncTimingHelper::PrintResult("tabs", "delete_tabs", dt); | |
131 } | |
OLD | NEW |