extensions_sync_perf_test.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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. 4 5#include "base/strings/stringprintf.h" 6#include "chrome/browser/sync/profile_sync_service_harness.h" 7#include "chrome/browser/sync/test/integration/extensions_helper.h" 8#include "chrome/browser/sync/test/integration/performance/sync_timing_helper.h" 9#include "chrome/browser/sync/test/integration/sync_test.h" 10 11using extensions_helper::AllProfilesHaveSameExtensions; 12using extensions_helper::AllProfilesHaveSameExtensionsAsVerifier; 13using extensions_helper::GetInstalledExtensions; 14using extensions_helper::InstallExtension; 15using extensions_helper::InstallExtensionsPendingForSync; 16using extensions_helper::IsExtensionEnabled; 17using extensions_helper::UninstallExtension; 18 19// TODO(braffert): Replicate these tests for apps. 20 21static const int kNumExtensions = 150; 22 23class ExtensionsSyncPerfTest : public SyncTest { 24 public: 25 ExtensionsSyncPerfTest() 26 : SyncTest(TWO_CLIENT), 27 extension_number_(0) {} 28 29 // Adds |num_extensions| new unique extensions to |profile|. 30 void AddExtensions(int profile, int num_extensions); 31 32 // Uninstalls all currently installed extensions from |profile|. 33 void RemoveExtensions(int profile); 34 35 // Returns the number of currently installed extensions for |profile|. 36 int GetExtensionCount(int profile); 37 38 private: 39 int extension_number_; 40 DISALLOW_COPY_AND_ASSIGN(ExtensionsSyncPerfTest); 41}; 42 43void ExtensionsSyncPerfTest::AddExtensions(int profile, int num_extensions) { 44 for (int i = 0; i < num_extensions; ++i) { 45 InstallExtension(GetProfile(profile), extension_number_++); 46 } 47} 48 49int ExtensionsSyncPerfTest::GetExtensionCount(int profile) { 50 return GetInstalledExtensions(GetProfile(profile)).size(); 51} 52 53void ExtensionsSyncPerfTest::RemoveExtensions(int profile) { 54 std::vector<int> extensions = GetInstalledExtensions(GetProfile(profile)); 55 for (std::vector<int>::iterator it = extensions.begin(); 56 it != extensions.end(); ++it) { 57 UninstallExtension(GetProfile(profile), *it); 58 } 59} 60 61IN_PROC_BROWSER_TEST_F(ExtensionsSyncPerfTest, P0) { 62 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 63 int num_default_extensions = GetExtensionCount(0); 64 int expected_extension_count = num_default_extensions + kNumExtensions; 65 66 // TCM ID - 7563874. 67 AddExtensions(0, kNumExtensions); 68 base::TimeDelta dt = 69 SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); 70 InstallExtensionsPendingForSync(GetProfile(1)); 71 ASSERT_EQ(expected_extension_count, GetExtensionCount(1)); 72 SyncTimingHelper::PrintResult("extensions", "add_extensions", dt); 73 74 // TCM ID - 7567721. 75 RemoveExtensions(0); 76 dt = SyncTimingHelper::TimeMutualSyncCycle(GetClient(0), GetClient(1)); 77 ASSERT_EQ(num_default_extensions, GetExtensionCount(1)); 78 SyncTimingHelper::PrintResult("extensions", "delete_extensions", dt); 79} 80