| 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 "chrome/browser/sync/test/integration/apps_helper.h" | 5 #include "chrome/browser/sync/test/integration/apps_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 std::string CreateFakeAppName(int index) { | 30 std::string CreateFakeAppName(int index) { |
| 31 return "fakeapp" + base::IntToString(index); | 31 return "fakeapp" + base::IntToString(index); |
| 32 } | 32 } |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 namespace apps_helper { | 36 namespace apps_helper { |
| 37 | 37 |
| 38 bool HasSameAppsAsVerifier(int index) { | 38 bool HasSameApps(Profile* profile1, Profile* profile2) { |
| 39 return SyncAppHelper::GetInstance()->AppStatesMatch( | 39 return SyncAppHelper::GetInstance()->AppStatesMatch(profile1, profile2); |
| 40 test()->GetProfile(index), test()->verifier()); | |
| 41 } | 40 } |
| 42 | 41 |
| 43 bool AllProfilesHaveSameAppsAsVerifier() { | 42 bool AllProfilesHaveSameApps() { |
| 44 for (int i = 0; i < test()->num_clients(); ++i) { | 43 const auto& profiles = test()->GetAllProfiles(); |
| 45 if (!HasSameAppsAsVerifier(i)) { | 44 for (auto* profile : profiles) { |
| 46 DVLOG(1) << "Profile " << i << " doesn't have the same apps as the" | 45 if (profile != profiles.front() && |
| 47 " verifier profile."; | 46 !HasSameApps(profiles.front(), profile)) { |
| 47 DVLOG(1) << "Profiles apps do not match."; |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 return true; | 51 return true; |
| 52 } | 52 } |
| 53 | 53 |
| 54 std::string InstallApp(Profile* profile, int index) { | 54 std::string InstallApp(Profile* profile, int index) { |
| 55 return SyncExtensionHelper::GetInstance()->InstallExtension( | 55 return SyncExtensionHelper::GetInstance()->InstallExtension( |
| 56 profile, | 56 profile, |
| 57 CreateFakeAppName(index), | 57 CreateFakeAppName(index), |
| 58 extensions::Manifest::TYPE_HOSTED_APP); | 58 extensions::Manifest::TYPE_HOSTED_APP); |
| 59 } | 59 } |
| 60 | 60 |
| 61 std::string InstallPlatformApp(Profile* profile, int index) { | 61 std::string InstallPlatformApp(Profile* profile, int index) { |
| 62 return SyncExtensionHelper::GetInstance()->InstallExtension( | 62 return SyncExtensionHelper::GetInstance()->InstallExtension( |
| 63 profile, | 63 profile, |
| 64 CreateFakeAppName(index), | 64 CreateFakeAppName(index), |
| 65 extensions::Manifest::TYPE_PLATFORM_APP); | 65 extensions::Manifest::TYPE_PLATFORM_APP); |
| 66 } | 66 } |
| 67 | 67 |
| 68 std::string InstallAppForAllProfiles(int index) { | 68 std::string InstallAppForAllProfiles(int index) { |
| 69 for (int i = 0; i < test()->num_clients(); ++i) | 69 std::string extension_id; |
| 70 InstallApp(test()->GetProfile(i), index); | 70 for (auto* profile : test()->GetAllProfiles()) { |
| 71 return InstallApp(test()->verifier(), index); | 71 extension_id = InstallApp(profile, index); |
| 72 } |
| 73 return extension_id; |
| 72 } | 74 } |
| 73 | 75 |
| 74 void UninstallApp(Profile* profile, int index) { | 76 void UninstallApp(Profile* profile, int index) { |
| 75 return SyncExtensionHelper::GetInstance()->UninstallExtension( | 77 return SyncExtensionHelper::GetInstance()->UninstallExtension( |
| 76 profile, CreateFakeAppName(index)); | 78 profile, CreateFakeAppName(index)); |
| 77 } | 79 } |
| 78 | 80 |
| 79 void EnableApp(Profile* profile, int index) { | 81 void EnableApp(Profile* profile, int index) { |
| 80 return SyncExtensionHelper::GetInstance()->EnableExtension( | 82 return SyncExtensionHelper::GetInstance()->EnableExtension( |
| 81 profile, CreateFakeAppName(index)); | 83 profile, CreateFakeAppName(index)); |
| 82 } | 84 } |
| 83 | 85 |
| 84 void DisableApp(Profile* profile, int index) { | 86 void DisableApp(Profile* profile, int index) { |
| 85 return SyncExtensionHelper::GetInstance()->DisableExtension( | 87 return SyncExtensionHelper::GetInstance()->DisableExtension( |
| 86 profile, CreateFakeAppName(index)); | 88 profile, CreateFakeAppName(index)); |
| 87 } | 89 } |
| 88 | 90 |
| 91 bool IsAppEnabled(Profile* profile, int index) { |
| 92 return SyncExtensionHelper::GetInstance()->IsExtensionEnabled( |
| 93 profile, CreateFakeAppName(index)); |
| 94 } |
| 95 |
| 89 void IncognitoEnableApp(Profile* profile, int index) { | 96 void IncognitoEnableApp(Profile* profile, int index) { |
| 90 return SyncExtensionHelper::GetInstance()->IncognitoEnableExtension( | 97 return SyncExtensionHelper::GetInstance()->IncognitoEnableExtension( |
| 91 profile, CreateFakeAppName(index)); | 98 profile, CreateFakeAppName(index)); |
| 92 } | 99 } |
| 93 | 100 |
| 94 void IncognitoDisableApp(Profile* profile, int index) { | 101 void IncognitoDisableApp(Profile* profile, int index) { |
| 95 return SyncExtensionHelper::GetInstance()->IncognitoDisableExtension( | 102 return SyncExtensionHelper::GetInstance()->IncognitoDisableExtension( |
| 96 profile, CreateFakeAppName(index)); | 103 profile, CreateFakeAppName(index)); |
| 97 } | 104 } |
| 98 | 105 |
| 106 bool IsIncognitoEnabled(Profile* profile, int index) { |
| 107 return SyncExtensionHelper::GetInstance()->IsIncognitoEnabled( |
| 108 profile, CreateFakeAppName(index)); |
| 109 } |
| 110 |
| 99 void InstallAppsPendingForSync(Profile* profile) { | 111 void InstallAppsPendingForSync(Profile* profile) { |
| 100 SyncExtensionHelper::GetInstance()->InstallExtensionsPendingForSync(profile); | 112 SyncExtensionHelper::GetInstance()->InstallExtensionsPendingForSync(profile); |
| 101 } | 113 } |
| 102 | 114 |
| 103 syncer::StringOrdinal GetPageOrdinalForApp(Profile* profile, | 115 syncer::StringOrdinal GetPageOrdinalForApp(Profile* profile, |
| 104 int app_index) { | 116 int app_index) { |
| 105 return SyncAppHelper::GetInstance()->GetPageOrdinalForApp( | 117 return SyncAppHelper::GetInstance()->GetPageOrdinalForApp( |
| 106 profile, CreateFakeAppName(app_index)); | 118 profile, CreateFakeAppName(app_index)); |
| 107 } | 119 } |
| 108 | 120 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 for (int i = 0; i < test()->num_clients(); ++i) { | 352 for (int i = 0; i < test()->num_clients(); ++i) { |
| 341 profiles.push_back(test()->GetProfile(i)); | 353 profiles.push_back(test()->GetProfile(i)); |
| 342 } | 354 } |
| 343 | 355 |
| 344 AppsMatchChecker checker(profiles); | 356 AppsMatchChecker checker(profiles); |
| 345 checker.Wait(); | 357 checker.Wait(); |
| 346 return !checker.TimedOut(); | 358 return !checker.TimedOut(); |
| 347 } | 359 } |
| 348 | 360 |
| 349 } // namespace apps_helper | 361 } // namespace apps_helper |
| OLD | NEW |