| 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 HasSameApps(Profile* profile1, Profile* profile2) { | 38 bool HasSameAppsAsVerifier(int index) { |
| 39 return SyncAppHelper::GetInstance()->AppStatesMatch(profile1, profile2); | 39 return SyncAppHelper::GetInstance()->AppStatesMatch( |
| 40 test()->GetProfile(index), test()->verifier()); |
| 40 } | 41 } |
| 41 | 42 |
| 42 bool AllProfilesHaveSameApps() { | 43 bool AllProfilesHaveSameAppsAsVerifier() { |
| 43 const auto& profiles = test()->GetAllProfiles(); | 44 for (int i = 0; i < test()->num_clients(); ++i) { |
| 44 for (auto* profile : profiles) { | 45 if (!HasSameAppsAsVerifier(i)) { |
| 45 if (profile != profiles.front() && | 46 DVLOG(1) << "Profile " << i << " doesn't have the same apps as the" |
| 46 !HasSameApps(profiles.front(), profile)) { | 47 " verifier 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 std::string extension_id; | 69 for (int i = 0; i < test()->num_clients(); ++i) |
| 70 for (auto* profile : test()->GetAllProfiles()) { | 70 InstallApp(test()->GetProfile(i), index); |
| 71 extension_id = InstallApp(profile, index); | 71 return InstallApp(test()->verifier(), index); |
| 72 } | |
| 73 return extension_id; | |
| 74 } | 72 } |
| 75 | 73 |
| 76 void UninstallApp(Profile* profile, int index) { | 74 void UninstallApp(Profile* profile, int index) { |
| 77 return SyncExtensionHelper::GetInstance()->UninstallExtension( | 75 return SyncExtensionHelper::GetInstance()->UninstallExtension( |
| 78 profile, CreateFakeAppName(index)); | 76 profile, CreateFakeAppName(index)); |
| 79 } | 77 } |
| 80 | 78 |
| 81 void EnableApp(Profile* profile, int index) { | 79 void EnableApp(Profile* profile, int index) { |
| 82 return SyncExtensionHelper::GetInstance()->EnableExtension( | 80 return SyncExtensionHelper::GetInstance()->EnableExtension( |
| 83 profile, CreateFakeAppName(index)); | 81 profile, CreateFakeAppName(index)); |
| 84 } | 82 } |
| 85 | 83 |
| 86 void DisableApp(Profile* profile, int index) { | 84 void DisableApp(Profile* profile, int index) { |
| 87 return SyncExtensionHelper::GetInstance()->DisableExtension( | 85 return SyncExtensionHelper::GetInstance()->DisableExtension( |
| 88 profile, CreateFakeAppName(index)); | 86 profile, CreateFakeAppName(index)); |
| 89 } | 87 } |
| 90 | 88 |
| 91 bool IsAppEnabled(Profile* profile, int index) { | |
| 92 return SyncExtensionHelper::GetInstance()->IsExtensionEnabled( | |
| 93 profile, CreateFakeAppName(index)); | |
| 94 } | |
| 95 | |
| 96 void IncognitoEnableApp(Profile* profile, int index) { | 89 void IncognitoEnableApp(Profile* profile, int index) { |
| 97 return SyncExtensionHelper::GetInstance()->IncognitoEnableExtension( | 90 return SyncExtensionHelper::GetInstance()->IncognitoEnableExtension( |
| 98 profile, CreateFakeAppName(index)); | 91 profile, CreateFakeAppName(index)); |
| 99 } | 92 } |
| 100 | 93 |
| 101 void IncognitoDisableApp(Profile* profile, int index) { | 94 void IncognitoDisableApp(Profile* profile, int index) { |
| 102 return SyncExtensionHelper::GetInstance()->IncognitoDisableExtension( | 95 return SyncExtensionHelper::GetInstance()->IncognitoDisableExtension( |
| 103 profile, CreateFakeAppName(index)); | 96 profile, CreateFakeAppName(index)); |
| 104 } | 97 } |
| 105 | 98 |
| 106 bool IsIncognitoEnabled(Profile* profile, int index) { | |
| 107 return SyncExtensionHelper::GetInstance()->IsIncognitoEnabled( | |
| 108 profile, CreateFakeAppName(index)); | |
| 109 } | |
| 110 | |
| 111 void InstallAppsPendingForSync(Profile* profile) { | 99 void InstallAppsPendingForSync(Profile* profile) { |
| 112 SyncExtensionHelper::GetInstance()->InstallExtensionsPendingForSync(profile); | 100 SyncExtensionHelper::GetInstance()->InstallExtensionsPendingForSync(profile); |
| 113 } | 101 } |
| 114 | 102 |
| 115 syncer::StringOrdinal GetPageOrdinalForApp(Profile* profile, | 103 syncer::StringOrdinal GetPageOrdinalForApp(Profile* profile, |
| 116 int app_index) { | 104 int app_index) { |
| 117 return SyncAppHelper::GetInstance()->GetPageOrdinalForApp( | 105 return SyncAppHelper::GetInstance()->GetPageOrdinalForApp( |
| 118 profile, CreateFakeAppName(app_index)); | 106 profile, CreateFakeAppName(app_index)); |
| 119 } | 107 } |
| 120 | 108 |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 for (int i = 0; i < test()->num_clients(); ++i) { | 340 for (int i = 0; i < test()->num_clients(); ++i) { |
| 353 profiles.push_back(test()->GetProfile(i)); | 341 profiles.push_back(test()->GetProfile(i)); |
| 354 } | 342 } |
| 355 | 343 |
| 356 AppsMatchChecker checker(profiles); | 344 AppsMatchChecker checker(profiles); |
| 357 checker.Wait(); | 345 checker.Wait(); |
| 358 return !checker.TimedOut(); | 346 return !checker.TimedOut(); |
| 359 } | 347 } |
| 360 | 348 |
| 361 } // namespace apps_helper | 349 } // namespace apps_helper |
| OLD | NEW |