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 "chrome/test/live_sync/extensions_helper.h" |
| 6 |
| 7 #include <cstring> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_util.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/test/live_sync/sync_datatype_helper.h" |
| 15 #include "chrome/test/live_sync/sync_extension_helper.h" |
| 16 |
| 17 using sync_datatype_helper::test; |
| 18 |
| 19 namespace extensions_helper { |
| 20 |
| 21 const char extension_name_prefix[] = "fakeextension"; |
| 22 |
| 23 bool HasSameExtensionsAsVerifier(int index) { |
| 24 return SyncExtensionHelper::GetInstance()->ExtensionStatesMatch( |
| 25 test()->GetProfile(index), test()->verifier()); |
| 26 } |
| 27 |
| 28 bool AllProfilesHaveSameExtensionsAsVerifier() { |
| 29 for (int i = 0; i < test()->num_clients(); ++i) { |
| 30 if (!HasSameExtensionsAsVerifier(i)) { |
| 31 LOG(ERROR) << "Profile " << i << " doesn't have the same extensions as" |
| 32 " the verifier profile."; |
| 33 return false; |
| 34 } |
| 35 } |
| 36 return true; |
| 37 } |
| 38 |
| 39 bool AllProfilesHaveSameExtensions() { |
| 40 for (int i = 1; i < test()->num_clients(); ++i) { |
| 41 if (!SyncExtensionHelper::GetInstance()->ExtensionStatesMatch( |
| 42 test()->GetProfile(0), test()->GetProfile(i))) { |
| 43 LOG(ERROR) << "Profile " << i << " doesnt have the same extensions as" |
| 44 " profile 0."; |
| 45 return false; |
| 46 } |
| 47 } |
| 48 return true; |
| 49 } |
| 50 |
| 51 |
| 52 void InstallExtension(Profile* profile, int index) { |
| 53 return SyncExtensionHelper::GetInstance()->InstallExtension( |
| 54 profile, CreateFakeExtensionName(index), Extension::TYPE_EXTENSION); |
| 55 } |
| 56 |
| 57 void UninstallExtension(Profile* profile, int index) { |
| 58 return SyncExtensionHelper::GetInstance()->UninstallExtension( |
| 59 profile, CreateFakeExtensionName(index)); |
| 60 } |
| 61 |
| 62 std::vector<int> GetInstalledExtensions(Profile* profile) { |
| 63 std::vector<int> indices; |
| 64 std::vector<std::string> names = |
| 65 SyncExtensionHelper::GetInstance()->GetInstalledExtensionNames(profile); |
| 66 for (std::vector<std::string>::const_iterator it = names.begin(); |
| 67 it != names.end(); ++it) { |
| 68 int index; |
| 69 if (ExtensionNameToIndex(*it, &index)) { |
| 70 indices.push_back(index); |
| 71 } |
| 72 } |
| 73 return indices; |
| 74 } |
| 75 |
| 76 void EnableExtension(Profile* profile, int index) { |
| 77 return SyncExtensionHelper::GetInstance()->EnableExtension( |
| 78 profile, CreateFakeExtensionName(index)); |
| 79 } |
| 80 |
| 81 void DisableExtension(Profile* profile, int index) { |
| 82 return SyncExtensionHelper::GetInstance()->DisableExtension( |
| 83 profile, CreateFakeExtensionName(index)); |
| 84 } |
| 85 |
| 86 bool IsExtensionEnabled(Profile* profile, int index) { |
| 87 return SyncExtensionHelper::GetInstance()->IsExtensionEnabled( |
| 88 profile, CreateFakeExtensionName(index)); |
| 89 } |
| 90 |
| 91 void IncognitoEnableExtension(Profile* profile, int index) { |
| 92 return SyncExtensionHelper::GetInstance()->IncognitoEnableExtension( |
| 93 profile, CreateFakeExtensionName(index)); |
| 94 } |
| 95 |
| 96 void IncognitoDisableExtension(Profile* profile, int index) { |
| 97 return SyncExtensionHelper::GetInstance()->IncognitoDisableExtension( |
| 98 profile, CreateFakeExtensionName(index)); |
| 99 } |
| 100 |
| 101 bool IsIncognitoEnabled(Profile* profile, int index) { |
| 102 return SyncExtensionHelper::GetInstance()->IsIncognitoEnabled( |
| 103 profile, CreateFakeExtensionName(index)); |
| 104 } |
| 105 |
| 106 void InstallExtensionsPendingForSync(Profile* profile) { |
| 107 SyncExtensionHelper::GetInstance()->InstallExtensionsPendingForSync( |
| 108 profile, Extension::TYPE_EXTENSION); |
| 109 } |
| 110 |
| 111 std::string CreateFakeExtensionName(int index) { |
| 112 return extension_name_prefix + base::IntToString(index); |
| 113 } |
| 114 |
| 115 bool ExtensionNameToIndex(const std::string& name, int* index) { |
| 116 if (!StartsWithASCII(name, extension_name_prefix, true) || |
| 117 !base::StringToInt(name.substr(strlen(extension_name_prefix)), index)) { |
| 118 LOG(WARNING) << "Unable to convert extension name \"" << name |
| 119 << "\" to index"; |
| 120 return false; |
| 121 } |
| 122 return true; |
| 123 } |
| 124 |
| 125 } // namespace extensions_helper |
OLD | NEW |