Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / sync / test / integration / performance / sessions_sync_perf_test.cc
blob9aac0b89e3df1f7a148e7a426525826890264286
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.
5 #include "base/strings/stringprintf.h"
6 #include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/sessions_helper.h"
9 #include "chrome/browser/sync/test/integration/sync_test.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 using content::OpenURLParams;
15 using sessions_helper::GetLocalSession;
16 using sessions_helper::GetSessionData;
17 using sessions_helper::OpenMultipleTabs;
18 using sessions_helper::SyncedSessionVector;
19 using sessions_helper::SessionWindowMap;
20 using sessions_helper::WaitForTabsToLoad;
22 static const int kNumTabs = 150;
24 class SessionsSyncPerfTest: public SyncTest {
25 public:
26 SessionsSyncPerfTest() : SyncTest(TWO_CLIENT), url_number_(0) {}
28 // Opens |num_tabs| new tabs on |profile|.
29 void AddTabs(int profile, int num_tabs);
31 // Update all tabs in |profile| by visiting a new URL.
32 void UpdateTabs(int profile);
34 // Close all tabs in |profile|.
35 void RemoveTabs(int profile);
37 // Returns the number of open tabs in all sessions (local + foreign) for
38 // |profile|. Returns -1 on failure.
39 int GetTabCount(int profile);
41 private:
42 // Returns a new unique URL.
43 GURL NextURL();
45 // Returns a unique URL according to the integer |n|.
46 GURL IntToURL(int n);
48 int url_number_;
49 DISALLOW_COPY_AND_ASSIGN(SessionsSyncPerfTest);
52 void SessionsSyncPerfTest::AddTabs(int profile, int num_tabs) {
53 std::vector<GURL> urls;
54 for (int i = 0; i < num_tabs; ++i) {
55 urls.push_back(NextURL());
57 OpenMultipleTabs(profile, urls);
60 void SessionsSyncPerfTest::UpdateTabs(int profile) {
61 Browser* browser = GetBrowser(profile);
62 GURL url;
63 std::vector<GURL> urls;
64 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
65 chrome::SelectNumberedTab(browser, i);
66 url = NextURL();
67 browser->OpenURL(
68 OpenURLParams(url,
69 content::Referrer(GURL("http://localhost"),
70 blink::WebReferrerPolicyDefault),
71 CURRENT_TAB,
72 ui::PAGE_TRANSITION_LINK, false));
73 urls.push_back(url);
75 WaitForTabsToLoad(profile, urls);
78 void SessionsSyncPerfTest::RemoveTabs(int profile) {
79 GetBrowser(profile)->tab_strip_model()->CloseAllTabs();
82 int SessionsSyncPerfTest::GetTabCount(int profile) {
83 int tab_count = 0;
84 const sync_driver::SyncedSession* local_session;
85 SyncedSessionVector sessions;
87 if (!GetLocalSession(profile, &local_session)) {
88 DVLOG(1) << "GetLocalSession returned false";
89 return -1;
92 if (!GetSessionData(profile, &sessions)) {
93 // Foreign session data may be empty. In this case we only count tabs in
94 // the local session.
95 DVLOG(1) << "GetSessionData returned false";
98 sessions.push_back(local_session);
99 for (SyncedSessionVector::const_iterator it = sessions.begin();
100 it != sessions.end(); ++it) {
101 for (SessionWindowMap::const_iterator win_it = (*it)->windows.begin();
102 win_it != (*it)->windows.end();
103 ++win_it) {
104 tab_count += win_it->second->tabs.size();
107 return tab_count;
110 GURL SessionsSyncPerfTest::NextURL() {
111 return IntToURL(url_number_++);
114 GURL SessionsSyncPerfTest::IntToURL(int n) {
115 return GURL(base::StringPrintf("http://localhost/%d", n));
118 // TODO(lipalani): Re-enable after crbug.com/96921 is fixed.
119 IN_PROC_BROWSER_TEST_F(SessionsSyncPerfTest, DISABLED_P0) {
120 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
122 AddTabs(0, kNumTabs);
123 base::TimeDelta dt =
124 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
125 ASSERT_EQ(kNumTabs, GetTabCount(0));
126 ASSERT_EQ(kNumTabs, GetTabCount(1));
127 SyncTimingHelper::PrintResult("tabs", "add_tabs", dt);
129 UpdateTabs(0);
130 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
131 ASSERT_EQ(kNumTabs, GetTabCount(0));
132 ASSERT_EQ(kNumTabs, GetTabCount(1));
133 SyncTimingHelper::PrintResult("tabs", "update_tabs", dt);
135 RemoveTabs(0);
136 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
137 // New tab page remains open on profile 0 after closing all tabs.
138 ASSERT_EQ(1, GetTabCount(0));
139 ASSERT_EQ(0, GetTabCount(1));
140 SyncTimingHelper::PrintResult("tabs", "delete_tabs", dt);