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 #ifndef CHROME_BROWSER_SYNC_TEST_INTEGRATION_APPS_HELPER_H_ 6 #define CHROME_BROWSER_SYNC_TEST_INTEGRATION_APPS_HELPER_H_ 7 8 #include <memory> 9 #include <string> 10 #include <vector> 11 12 #include "base/compiler_specific.h" 13 #include "chrome/browser/sync/test/integration/status_change_checker.h" 14 #include "chrome/browser/sync/test/integration/sync_test.h" 15 #include "components/sync/model/string_ordinal.h" 16 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_registrar.h" 18 #include "extensions/browser/extension_prefs_observer.h" 19 #include "extensions/browser/extension_registry_observer.h" 20 21 class Profile; 22 class SyncedExtensionInstaller; 23 24 namespace apps_helper { 25 26 // Returns true iff |profile1| has same apps (hosted, legacy packaged and 27 // platform) as |profile2|. 28 bool HasSameApps(Profile* profile1, Profile* profile2); 29 30 // Returns true iff all existing profiles have the same apps (hosted, 31 // legacy packaged and platform). 32 bool AllProfilesHaveSameApps() WARN_UNUSED_RESULT; 33 34 // Installs the hosted app for the given index to |profile|, and returns the 35 // extension ID of the new app. 36 std::string InstallHostedApp(Profile* profile, int index); 37 38 // Installs the platform app for the given index to |profile|, and returns the 39 // extension ID of the new app. Indices passed to this method should be distinct 40 // from indices passed to InstallApp. 41 std::string InstallPlatformApp(Profile* profile, int index); 42 43 // Installs the hosted app for the given index to all profiles (including the 44 // verifier), and returns the extension ID of the new app. 45 std::string InstallHostedAppForAllProfiles(int index); 46 47 // Uninstalls the app for the given index from |profile|. Assumes that it was 48 // previously installed. 49 void UninstallApp(Profile* profile, int index); 50 51 // Installs all pending synced apps for |profile|, including waiting for the 52 // App Service to settle. 53 void InstallAppsPendingForSync(Profile* profile); 54 55 // Waits for the App Service state for |profile| to settle. 56 void WaitForAppService(Profile* profile); 57 58 // Enables the app for the given index on |profile|. 59 void EnableApp(Profile* profile, int index); 60 61 // Disables the app for the given index on |profile|. 62 void DisableApp(Profile* profile, int index); 63 64 // Returns true if the app with index |index| is enabled on |profile|. 65 bool IsAppEnabled(Profile* profile, int index); 66 67 // Enables the app for the given index in incognito mode on |profile|. 68 void IncognitoEnableApp(Profile* profile, int index); 69 70 // Disables the app for the given index in incognito mode on |profile|. 71 void IncognitoDisableApp(Profile* profile, int index); 72 73 // Returns true if the app with index |index| is enabled in incognito mode on 74 // |profile|. 75 bool IsIncognitoEnabled(Profile* profile, int index); 76 77 // Gets the page ordinal value for the application at the given index on 78 // |profile|. 79 syncer::StringOrdinal GetPageOrdinalForApp(Profile* profile, int app_index); 80 81 // Sets a new |page_ordinal| value for the application at the given index 82 // on |profile|. 83 void SetPageOrdinalForApp( 84 Profile* profile, int app_index, 85 const syncer::StringOrdinal& page_ordinal); 86 87 // Gets the app launch ordinal value for the application at the given index on 88 // |profile|. 89 syncer::StringOrdinal GetAppLaunchOrdinalForApp( 90 Profile* profile, int app_index); 91 92 // Sets a new |page_ordinal| value for the application at the given index 93 // on |profile|. 94 void SetAppLaunchOrdinalForApp( 95 Profile* profile, int app_index, 96 const syncer::StringOrdinal& app_launch_ordinal); 97 98 // Copy the page and app launch ordinal value for the application at the given 99 // index on |profile_source| to |profile_destination|. 100 // The main intention of this is to properly setup the values on the verifier 101 // profile in situations where the other profiles have conflicting values. 102 void CopyNTPOrdinals(Profile* source, Profile* destination, int index); 103 104 // Fix any NTP icon collisions that are currently in |profile|. 105 void FixNTPOrdinalCollisions(Profile* profile); 106 107 } // namespace apps_helper 108 109 // Checker to block for a set of profiles to have matching extensions lists. If 110 // the verifier profile is enabled, it will be included in the set of profiles 111 // to check against. 112 class AppsMatchChecker : public StatusChangeChecker, 113 public extensions::ExtensionRegistryObserver, 114 public extensions::ExtensionPrefsObserver, 115 public content::NotificationObserver { 116 public: 117 AppsMatchChecker(); 118 ~AppsMatchChecker() override; 119 120 // StatusChangeChecker implementation. 121 bool IsExitConditionSatisfied(std::ostream* os) override; 122 123 // extensions::ExtensionRegistryObserver implementation. 124 void OnExtensionLoaded(content::BrowserContext* context, 125 const extensions::Extension* extension) override; 126 void OnExtensionUnloaded(content::BrowserContext* context, 127 const extensions::Extension* extension, 128 extensions::UnloadedExtensionReason reason) override; 129 void OnExtensionInstalled(content::BrowserContext* browser_context, 130 const extensions::Extension* extension, 131 bool is_update) override; 132 void OnExtensionUninstalled(content::BrowserContext* browser_context, 133 const extensions::Extension* extension, 134 extensions::UninstallReason reason) override; 135 136 // extensions::ExtensionPrefsObserver implementation. 137 void OnExtensionDisableReasonsChanged(const std::string& extension_id, 138 int disabled_reasons) override; 139 void OnExtensionRegistered(const std::string& extension_id, 140 const base::Time& install_time, 141 bool is_enabled) override; 142 void OnExtensionPrefsLoaded(const std::string& extension_id, 143 const extensions::ExtensionPrefs* prefs) override; 144 void OnExtensionPrefsDeleted(const std::string& extension_id) override; 145 void OnExtensionStateChanged(const std::string& extension_id, 146 bool state) override; 147 148 // Implementation of content::NotificationObserver. 149 void Observe(int type, 150 const content::NotificationSource& source, 151 const content::NotificationDetails& details) override; 152 153 private: 154 std::vector<Profile*> profiles_; 155 156 content::NotificationRegistrar registrar_; 157 158 // This installs apps, too. 159 std::vector<std::unique_ptr<SyncedExtensionInstaller>> 160 synced_extension_installers_; 161 162 DISALLOW_COPY_AND_ASSIGN(AppsMatchChecker); 163 }; 164 165 #endif // CHROME_BROWSER_SYNC_TEST_INTEGRATION_APPS_HELPER_H_ 166