1 // Copyright (c) 2012 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/extensions_helper.h"
7 #include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h"
8 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
9 #include "chrome/browser/sync/test/integration/sync_test.h"
11 using extensions_helper::AllProfilesHaveSameExtensions
;
12 using extensions_helper::AllProfilesHaveSameExtensionsAsVerifier
;
13 using extensions_helper::DisableExtension
;
14 using extensions_helper::EnableExtension
;
15 using extensions_helper::GetInstalledExtensions
;
16 using extensions_helper::InstallExtension
;
17 using extensions_helper::InstallExtensionsPendingForSync
;
18 using extensions_helper::IsExtensionEnabled
;
19 using extensions_helper::UninstallExtension
;
21 // TODO(braffert): Replicate these tests for apps.
23 static const int kNumExtensions
= 150;
25 class ExtensionsSyncPerfTest
: public SyncTest
{
27 ExtensionsSyncPerfTest()
28 : SyncTest(TWO_CLIENT
),
29 extension_number_(0) {}
31 // Adds |num_extensions| new unique extensions to |profile|.
32 void AddExtensions(int profile
, int num_extensions
);
34 // Updates the enabled/disabled state for all extensions in |profile|.
35 void UpdateExtensions(int profile
);
37 // Uninstalls all currently installed extensions from |profile|.
38 void RemoveExtensions(int profile
);
40 // Returns the number of currently installed extensions for |profile|.
41 int GetExtensionCount(int profile
);
44 int extension_number_
;
45 DISALLOW_COPY_AND_ASSIGN(ExtensionsSyncPerfTest
);
48 void ExtensionsSyncPerfTest::AddExtensions(int profile
, int num_extensions
) {
49 for (int i
= 0; i
< num_extensions
; ++i
) {
50 InstallExtension(GetProfile(profile
), extension_number_
++);
54 void ExtensionsSyncPerfTest::UpdateExtensions(int profile
) {
55 std::vector
<int> extensions
= GetInstalledExtensions(GetProfile(profile
));
56 for (std::vector
<int>::iterator it
= extensions
.begin();
57 it
!= extensions
.end(); ++it
) {
58 if (IsExtensionEnabled(GetProfile(profile
), *it
)) {
59 DisableExtension(GetProfile(profile
), *it
);
61 EnableExtension(GetProfile(profile
), *it
);
66 int ExtensionsSyncPerfTest::GetExtensionCount(int profile
) {
67 return GetInstalledExtensions(GetProfile(profile
)).size();
70 void ExtensionsSyncPerfTest::RemoveExtensions(int profile
) {
71 std::vector
<int> extensions
= GetInstalledExtensions(GetProfile(profile
));
72 for (std::vector
<int>::iterator it
= extensions
.begin();
73 it
!= extensions
.end(); ++it
) {
74 UninstallExtension(GetProfile(profile
), *it
);
78 IN_PROC_BROWSER_TEST_F(ExtensionsSyncPerfTest
, P0
) {
79 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
80 int num_default_extensions
= GetExtensionCount(0);
81 int expected_extension_count
= num_default_extensions
+ kNumExtensions
;
84 AddExtensions(0, kNumExtensions
);
86 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
87 InstallExtensionsPendingForSync(GetProfile(1));
88 ASSERT_EQ(expected_extension_count
, GetExtensionCount(1));
89 SyncTimingHelper::PrintResult("extensions", "add_extensions", dt
);
93 dt
= SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
94 ASSERT_EQ(expected_extension_count
, GetExtensionCount(1));
95 SyncTimingHelper::PrintResult("extensions", "update_extensions", dt
);
99 dt
= SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1));
100 ASSERT_EQ(num_default_extensions
, GetExtensionCount(1));
101 SyncTimingHelper::PrintResult("extensions", "delete_extensions", dt
);