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.
5 #include "chrome/browser/sync/test/integration/apps_helper.h"
7 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sync/test/integration/sync_app_helper.h"
11 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h"
12 #include "chrome/browser/sync/test/integration/sync_extension_helper.h"
13 #include "extensions/common/manifest.h"
15 using sync_datatype_helper::test
;
19 std::string
CreateFakeAppName(int index
) {
20 return "fakeapp" + base::IntToString(index
);
25 namespace apps_helper
{
27 bool HasSameAppsAsVerifier(int index
) {
28 return SyncAppHelper::GetInstance()->AppStatesMatch(
29 test()->GetProfile(index
), test()->verifier());
32 bool AllProfilesHaveSameAppsAsVerifier() {
33 for (int i
= 0; i
< test()->num_clients(); ++i
) {
34 if (!HasSameAppsAsVerifier(i
)) {
35 LOG(ERROR
) << "Profile " << i
<< " doesn't have the same apps as the"
43 std::string
InstallApp(Profile
* profile
, int index
) {
44 return SyncExtensionHelper::GetInstance()->InstallExtension(
46 CreateFakeAppName(index
),
47 extensions::Manifest::TYPE_HOSTED_APP
);
50 std::string
InstallPlatformApp(Profile
* profile
, int index
) {
51 return SyncExtensionHelper::GetInstance()->InstallExtension(
53 CreateFakeAppName(index
),
54 extensions::Manifest::TYPE_PLATFORM_APP
);
57 std::string
InstallAppForAllProfiles(int index
) {
58 for (int i
= 0; i
< test()->num_clients(); ++i
)
59 InstallApp(test()->GetProfile(i
), index
);
60 return InstallApp(test()->verifier(), index
);
63 void UninstallApp(Profile
* profile
, int index
) {
64 return SyncExtensionHelper::GetInstance()->UninstallExtension(
65 profile
, CreateFakeAppName(index
));
68 void EnableApp(Profile
* profile
, int index
) {
69 return SyncExtensionHelper::GetInstance()->EnableExtension(
70 profile
, CreateFakeAppName(index
));
73 void DisableApp(Profile
* profile
, int index
) {
74 return SyncExtensionHelper::GetInstance()->DisableExtension(
75 profile
, CreateFakeAppName(index
));
78 void IncognitoEnableApp(Profile
* profile
, int index
) {
79 return SyncExtensionHelper::GetInstance()->IncognitoEnableExtension(
80 profile
, CreateFakeAppName(index
));
83 void IncognitoDisableApp(Profile
* profile
, int index
) {
84 return SyncExtensionHelper::GetInstance()->IncognitoDisableExtension(
85 profile
, CreateFakeAppName(index
));
88 void InstallAppsPendingForSync(Profile
* profile
) {
89 SyncExtensionHelper::GetInstance()->InstallExtensionsPendingForSync(profile
);
92 syncer::StringOrdinal
GetPageOrdinalForApp(Profile
* profile
,
94 return SyncAppHelper::GetInstance()->GetPageOrdinalForApp(
95 profile
, CreateFakeAppName(app_index
));
98 void SetPageOrdinalForApp(Profile
* profile
,
100 const syncer::StringOrdinal
& page_ordinal
) {
101 SyncAppHelper::GetInstance()->SetPageOrdinalForApp(
102 profile
, CreateFakeAppName(app_index
), page_ordinal
);
105 syncer::StringOrdinal
GetAppLaunchOrdinalForApp(Profile
* profile
,
107 return SyncAppHelper::GetInstance()->GetAppLaunchOrdinalForApp(
108 profile
, CreateFakeAppName(app_index
));
111 void SetAppLaunchOrdinalForApp(
114 const syncer::StringOrdinal
& app_launch_ordinal
) {
115 SyncAppHelper::GetInstance()->SetAppLaunchOrdinalForApp(
116 profile
, CreateFakeAppName(app_index
), app_launch_ordinal
);
119 void CopyNTPOrdinals(Profile
* source
, Profile
* destination
, int index
) {
120 SetPageOrdinalForApp(destination
, index
, GetPageOrdinalForApp(source
, index
));
121 SetAppLaunchOrdinalForApp(
122 destination
, index
, GetAppLaunchOrdinalForApp(source
, index
));
125 void FixNTPOrdinalCollisions(Profile
* profile
) {
126 SyncAppHelper::GetInstance()->FixNTPOrdinalCollisions(profile
);
129 } // namespace apps_helper