Home | History | Annotate | Download | only in integration
      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 "chrome/browser/sync/test/integration/apps_helper.h"
      6 
      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 "chrome/common/extensions/manifest.h"
     14 
     15 using sync_datatype_helper::test;
     16 
     17 namespace {
     18 
     19 std::string CreateFakeAppName(int index) {
     20   return "fakeapp" + base::IntToString(index);
     21 }
     22 
     23 }  // namespace
     24 
     25 namespace apps_helper {
     26 
     27 bool HasSameAppsAsVerifier(int index) {
     28   return SyncAppHelper::GetInstance()->AppStatesMatch(
     29       test()->GetProfile(index), test()->verifier());
     30 }
     31 
     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"
     36                                        " verifier profile.";
     37       return false;
     38     }
     39   }
     40   return true;
     41 }
     42 
     43 std::string InstallApp(Profile* profile, int index) {
     44   return SyncExtensionHelper::GetInstance()->InstallExtension(
     45       profile,
     46       CreateFakeAppName(index),
     47       extensions::Manifest::TYPE_HOSTED_APP);
     48 }
     49 
     50 std::string InstallPlatformApp(Profile* profile, int index) {
     51   return SyncExtensionHelper::GetInstance()->InstallExtension(
     52       profile,
     53       CreateFakeAppName(index),
     54       extensions::Manifest::TYPE_PLATFORM_APP);
     55 }
     56 
     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);
     61 }
     62 
     63 void UninstallApp(Profile* profile, int index) {
     64   return SyncExtensionHelper::GetInstance()->UninstallExtension(
     65       profile, CreateFakeAppName(index));
     66 }
     67 
     68 void EnableApp(Profile* profile, int index) {
     69   return SyncExtensionHelper::GetInstance()->EnableExtension(
     70       profile, CreateFakeAppName(index));
     71 }
     72 
     73 void DisableApp(Profile* profile, int index) {
     74   return SyncExtensionHelper::GetInstance()->DisableExtension(
     75       profile, CreateFakeAppName(index));
     76 }
     77 
     78 void IncognitoEnableApp(Profile* profile, int index) {
     79   return SyncExtensionHelper::GetInstance()->IncognitoEnableExtension(
     80       profile, CreateFakeAppName(index));
     81 }
     82 
     83 void IncognitoDisableApp(Profile* profile, int index) {
     84   return SyncExtensionHelper::GetInstance()->IncognitoDisableExtension(
     85       profile, CreateFakeAppName(index));
     86 }
     87 
     88 void InstallAppsPendingForSync(Profile* profile) {
     89   SyncExtensionHelper::GetInstance()->InstallExtensionsPendingForSync(profile);
     90 }
     91 
     92 syncer::StringOrdinal GetPageOrdinalForApp(Profile* profile,
     93                                            int app_index) {
     94   return SyncAppHelper::GetInstance()->GetPageOrdinalForApp(
     95       profile, CreateFakeAppName(app_index));
     96 }
     97 
     98 void SetPageOrdinalForApp(Profile* profile,
     99                           int app_index,
    100                           const syncer::StringOrdinal& page_ordinal) {
    101   SyncAppHelper::GetInstance()->SetPageOrdinalForApp(
    102       profile, CreateFakeAppName(app_index), page_ordinal);
    103 }
    104 
    105 syncer::StringOrdinal GetAppLaunchOrdinalForApp(Profile* profile,
    106                                                 int app_index) {
    107   return SyncAppHelper::GetInstance()->GetAppLaunchOrdinalForApp(
    108       profile, CreateFakeAppName(app_index));
    109 }
    110 
    111 void SetAppLaunchOrdinalForApp(
    112     Profile* profile,
    113     int app_index,
    114     const syncer::StringOrdinal& app_launch_ordinal) {
    115   SyncAppHelper::GetInstance()->SetAppLaunchOrdinalForApp(
    116       profile, CreateFakeAppName(app_index), app_launch_ordinal);
    117 }
    118 
    119 void CopyNTPOrdinals(Profile* source, Profile* destination, int index) {
    120   SetPageOrdinalForApp(destination, index, GetPageOrdinalForApp(source, index));
    121   SetAppLaunchOrdinalForApp(
    122       destination, index, GetAppLaunchOrdinalForApp(source, index));
    123 }
    124 
    125 void FixNTPOrdinalCollisions(Profile* profile) {
    126   SyncAppHelper::GetInstance()->FixNTPOrdinalCollisions(profile);
    127 }
    128 
    129 }  // namespace apps_helper
    130