| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
| 6 #include "chrome/browser/sync/profile_sync_service_harness.h" | 6 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 7 #include "chrome/browser/sync/test/integration/extensions_helper.h" | 7 #include "chrome/browser/sync/test/integration/extensions_helper.h" |
| 8 #include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h" | 8 #include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h" |
| 9 #include "chrome/browser/sync/test/integration/sync_test.h" | 9 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 10 | 10 |
| 11 using extensions_helper::AllProfilesHaveSameExtensions; | 11 using extensions_helper::AllProfilesHaveSameExtensions; |
| 12 using extensions_helper::AllProfilesHaveSameExtensionsAsVerifier; | 12 using extensions_helper::AllProfilesHaveSameExtensionsAsVerifier; |
| 13 using extensions_helper::DisableExtension; |
| 14 using extensions_helper::EnableExtension; |
| 13 using extensions_helper::GetInstalledExtensions; | 15 using extensions_helper::GetInstalledExtensions; |
| 14 using extensions_helper::InstallExtension; | 16 using extensions_helper::InstallExtension; |
| 15 using extensions_helper::InstallExtensionsPendingForSync; | 17 using extensions_helper::InstallExtensionsPendingForSync; |
| 16 using extensions_helper::IsExtensionEnabled; | 18 using extensions_helper::IsExtensionEnabled; |
| 17 using extensions_helper::UninstallExtension; | 19 using extensions_helper::UninstallExtension; |
| 18 | 20 |
| 19 // TODO(braffert): Replicate these tests for apps. | 21 // TODO(braffert): Replicate these tests for apps. |
| 20 | 22 |
| 21 static const int kNumExtensions = 150; | 23 static const int kNumExtensions = 150; |
| 22 | 24 |
| 23 class ExtensionsSyncPerfTest : public SyncTest { | 25 class ExtensionsSyncPerfTest : public SyncTest { |
| 24 public: | 26 public: |
| 25 ExtensionsSyncPerfTest() | 27 ExtensionsSyncPerfTest() |
| 26 : SyncTest(TWO_CLIENT), | 28 : SyncTest(TWO_CLIENT), |
| 27 extension_number_(0) {} | 29 extension_number_(0) {} |
| 28 | 30 |
| 29 // Adds |num_extensions| new unique extensions to |profile|. | 31 // Adds |num_extensions| new unique extensions to |profile|. |
| 30 void AddExtensions(int profile, int num_extensions); | 32 void AddExtensions(int profile, int num_extensions); |
| 31 | 33 |
| 34 // Updates the enabled/disabled state for all extensions in |profile|. |
| 35 void UpdateExtensions(int profile); |
| 36 |
| 32 // Uninstalls all currently installed extensions from |profile|. | 37 // Uninstalls all currently installed extensions from |profile|. |
| 33 void RemoveExtensions(int profile); | 38 void RemoveExtensions(int profile); |
| 34 | 39 |
| 35 // Returns the number of currently installed extensions for |profile|. | 40 // Returns the number of currently installed extensions for |profile|. |
| 36 int GetExtensionCount(int profile); | 41 int GetExtensionCount(int profile); |
| 37 | 42 |
| 38 private: | 43 private: |
| 39 int extension_number_; | 44 int extension_number_; |
| 40 DISALLOW_COPY_AND_ASSIGN(ExtensionsSyncPerfTest); | 45 DISALLOW_COPY_AND_ASSIGN(ExtensionsSyncPerfTest); |
| 41 }; | 46 }; |
| 42 | 47 |
| 43 void ExtensionsSyncPerfTest::AddExtensions(int profile, int num_extensions) { | 48 void ExtensionsSyncPerfTest::AddExtensions(int profile, int num_extensions) { |
| 44 for (int i = 0; i < num_extensions; ++i) { | 49 for (int i = 0; i < num_extensions; ++i) { |
| 45 InstallExtension(GetProfile(profile), extension_number_++); | 50 InstallExtension(GetProfile(profile), extension_number_++); |
| 46 } | 51 } |
| 47 } | 52 } |
| 48 | 53 |
| 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); |
| 60 } else { |
| 61 EnableExtension(GetProfile(profile), *it); |
| 62 } |
| 63 } |
| 64 } |
| 65 |
| 49 int ExtensionsSyncPerfTest::GetExtensionCount(int profile) { | 66 int ExtensionsSyncPerfTest::GetExtensionCount(int profile) { |
| 50 return GetInstalledExtensions(GetProfile(profile)).size(); | 67 return GetInstalledExtensions(GetProfile(profile)).size(); |
| 51 } | 68 } |
| 52 | 69 |
| 53 void ExtensionsSyncPerfTest::RemoveExtensions(int profile) { | 70 void ExtensionsSyncPerfTest::RemoveExtensions(int profile) { |
| 54 std::vector<int> extensions = GetInstalledExtensions(GetProfile(profile)); | 71 std::vector<int> extensions = GetInstalledExtensions(GetProfile(profile)); |
| 55 for (std::vector<int>::iterator it = extensions.begin(); | 72 for (std::vector<int>::iterator it = extensions.begin(); |
| 56 it != extensions.end(); ++it) { | 73 it != extensions.end(); ++it) { |
| 57 UninstallExtension(GetProfile(profile), *it); | 74 UninstallExtension(GetProfile(profile), *it); |
| 58 } | 75 } |
| 59 } | 76 } |
| 60 | 77 |
| 61 IN_PROC_BROWSER_TEST_F(ExtensionsSyncPerfTest, P0) { | 78 IN_PROC_BROWSER_TEST_F(ExtensionsSyncPerfTest, P0) { |
| 62 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 79 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 63 int num_default_extensions = GetExtensionCount(0); | 80 int num_default_extensions = GetExtensionCount(0); |
| 64 int expected_extension_count = num_default_extensions + kNumExtensions; | 81 int expected_extension_count = num_default_extensions + kNumExtensions; |
| 65 | 82 |
| 66 // TCM ID - 7563874. | 83 // TCM ID - 7563874. |
| 67 AddExtensions(0, kNumExtensions); | 84 AddExtensions(0, kNumExtensions); |
| 68 base::TimeDelta dt = | 85 base::TimeDelta dt = |
| 69 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 86 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 70 InstallExtensionsPendingForSync(GetProfile(1)); | 87 InstallExtensionsPendingForSync(GetProfile(1)); |
| 71 ASSERT_EQ(expected_extension_count, GetExtensionCount(1)); | 88 ASSERT_EQ(expected_extension_count, GetExtensionCount(1)); |
| 72 SyncTimingHelper::PrintResult("extensions", "add_extensions", dt); | 89 SyncTimingHelper::PrintResult("extensions", "add_extensions", dt); |
| 73 | 90 |
| 91 // TCM ID - 7655397. |
| 92 UpdateExtensions(0); |
| 93 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 94 ASSERT_EQ(expected_extension_count, GetExtensionCount(1)); |
| 95 SyncTimingHelper::PrintResult("extensions", "update_extensions", dt); |
| 96 |
| 74 // TCM ID - 7567721. | 97 // TCM ID - 7567721. |
| 75 RemoveExtensions(0); | 98 RemoveExtensions(0); |
| 76 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); | 99 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); |
| 77 ASSERT_EQ(num_default_extensions, GetExtensionCount(1)); | 100 ASSERT_EQ(num_default_extensions, GetExtensionCount(1)); |
| 78 SyncTimingHelper::PrintResult("extensions", "delete_extensions", dt); | 101 SyncTimingHelper::PrintResult("extensions", "delete_extensions", dt); |
| 79 } | 102 } |
| OLD | NEW |