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