Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / drive / fake_drive_service.h
index 9da4b6e..738c621 100644 (file)
@@ -6,9 +6,17 @@
 #define CHROME_BROWSER_DRIVE_FAKE_DRIVE_SERVICE_H_
 
 #include "base/files/file_path.h"
-#include "base/values.h"
 #include "chrome/browser/drive/drive_service_interface.h"
-#include "chrome/browser/google_apis/auth_service_interface.h"
+
+namespace base {
+class DictionaryValue;
+}
+
+namespace google_apis {
+class AboutResource;
+class ChangeResource;
+class FileResource;
+}
 
 namespace drive {
 
@@ -23,16 +31,6 @@ class FakeDriveService : public DriveServiceInterface {
   FakeDriveService();
   virtual ~FakeDriveService();
 
-  // Loads the resource list for WAPI. Returns true on success.
-  bool LoadResourceListForWapi(const std::string& relative_path);
-
-  // Loads the account metadata for WAPI. Returns true on success.  Also adds
-  // the largest changestamp in the account metadata to the existing
-  // entries. The changestamp information will be used to generate change
-  // lists in GetResourceList() when non-zero |start_changestamp| is
-  // specified.
-  bool LoadAccountMetadataForWapi(const std::string& relative_path);
-
   // Loads the app list for Drive API. Returns true on success.
   bool LoadAppListForDriveApi(const std::string& relative_path);
 
@@ -61,9 +59,10 @@ class FakeDriveService : public DriveServiceInterface {
   // Changes the quota fields returned from GetAboutResource().
   void SetQuotaValue(int64 used, int64 total);
 
-  // Returns the largest changestamp, which starts from 0 by default. See
-  // also comments at LoadAccountMetadataForWapi().
-  int64 largest_changestamp() const { return largest_changestamp_; }
+  // Returns the AboutResource.
+  const google_apis::AboutResource& about_resource() const {
+    return *about_resource_;
+  }
 
   // Returns the number of times the resource list is successfully loaded by
   // GetAllResourceList().
@@ -153,6 +152,9 @@ class FakeDriveService : public DriveServiceInterface {
       const std::string& resource_id,
       const std::string& etag,
       const google_apis::EntryActionCallback& callback) OVERRIDE;
+  virtual google_apis::CancelCallback TrashResource(
+      const std::string& resource_id,
+      const google_apis::EntryActionCallback& callback) OVERRIDE;
   virtual google_apis::CancelCallback DownloadFile(
       const base::FilePath& local_cache_path,
       const std::string& resource_id,
@@ -165,27 +167,17 @@ class FakeDriveService : public DriveServiceInterface {
       const std::string& new_title,
       const base::Time& last_modified,
       const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
-  // The new resource ID for the copied document will look like
-  // |resource_id| + "_copied".
-  virtual google_apis::CancelCallback CopyHostedDocument(
-      const std::string& resource_id,
-      const std::string& new_title,
-      const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
-  virtual google_apis::CancelCallback MoveResource(
+  virtual google_apis::CancelCallback UpdateResource(
       const std::string& resource_id,
       const std::string& parent_resource_id,
       const std::string& new_title,
       const base::Time& last_modified,
+      const base::Time& last_viewed_by_me,
       const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
   virtual google_apis::CancelCallback RenameResource(
       const std::string& resource_id,
       const std::string& new_title,
       const google_apis::EntryActionCallback& callback) OVERRIDE;
-  virtual google_apis::CancelCallback TouchResource(
-      const std::string& resource_id,
-      const base::Time& modified_date,
-      const base::Time& last_viewed_by_me_date,
-      const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
   virtual google_apis::CancelCallback AddResourceToDirectory(
       const std::string& parent_resource_id,
       const std::string& resource_id,
@@ -197,18 +189,20 @@ class FakeDriveService : public DriveServiceInterface {
   virtual google_apis::CancelCallback AddNewDirectory(
       const std::string& parent_resource_id,
       const std::string& directory_title,
+      const AddNewDirectoryOptions& options,
       const google_apis::GetResourceEntryCallback& callback) OVERRIDE;
   virtual google_apis::CancelCallback InitiateUploadNewFile(
       const std::string& content_type,
       int64 content_length,
       const std::string& parent_resource_id,
       const std::string& title,
+      const InitiateUploadNewFileOptions& options,
       const google_apis::InitiateUploadCallback& callback) OVERRIDE;
   virtual google_apis::CancelCallback InitiateUploadExistingFile(
       const std::string& content_type,
       int64 content_length,
       const std::string& resource_id,
-      const std::string& etag,
+      const InitiateUploadExistingFileOptions& options,
       const google_apis::InitiateUploadCallback& callback) OVERRIDE;
   virtual google_apis::CancelCallback ResumeUpload(
       const GURL& upload_url,
@@ -227,12 +221,14 @@ class FakeDriveService : public DriveServiceInterface {
       const std::string& resource_id,
       const std::string& app_id,
       const google_apis::AuthorizeAppCallback& callback) OVERRIDE;
-  virtual google_apis::CancelCallback GetResourceListInDirectoryByWapi(
-      const std::string& directory_resource_id,
-      const google_apis::GetResourceListCallback& callback) OVERRIDE;
-  virtual google_apis::CancelCallback GetRemainingResourceList(
-      const GURL& next_link,
-      const google_apis::GetResourceListCallback& callback) OVERRIDE;
+  virtual google_apis::CancelCallback UninstallApp(
+      const std::string& app_id,
+      const google_apis::EntryActionCallback& callback) OVERRIDE;
+  virtual google_apis::CancelCallback AddPermission(
+      const std::string& resource_id,
+      const std::string& email,
+      google_apis::drive::PermissionRole role,
+      const google_apis::EntryActionCallback& callback) OVERRIDE;
 
   // Adds a new file with the given parameters. On success, returns
   // HTTP_CREATED with the parsed entry.
@@ -244,6 +240,28 @@ class FakeDriveService : public DriveServiceInterface {
                   bool shared_with_me,
                   const google_apis::GetResourceEntryCallback& callback);
 
+  // Adds a new file with the given |resource_id|. If the id already exists,
+  // it's an error. This is used for testing cross profile file sharing that
+  // needs to have matching resource IDs in different fake service instances.
+  // |callback| must not be null.
+  void AddNewFileWithResourceId(
+      const std::string& resource_id,
+      const std::string& content_type,
+      const std::string& content_data,
+      const std::string& parent_resource_id,
+      const std::string& title,
+      bool shared_with_me,
+      const google_apis::GetResourceEntryCallback& callback);
+
+  // Adds a new directory with the given |resource_id|.
+  // |callback| must not be null.
+  google_apis::CancelCallback AddNewDirectoryWithResourceId(
+      const std::string& resource_id,
+      const std::string& parent_resource_id,
+      const std::string& directory_title,
+      const AddNewDirectoryOptions& options,
+      const google_apis::GetResourceEntryCallback& callback);
+
   // Sets the last modified time for an entry specified by |resource_id|.
   // On success, returns HTTP_SUCCESS with the parsed entry.
   // |callback| must not be null.
@@ -253,34 +271,33 @@ class FakeDriveService : public DriveServiceInterface {
       const google_apis::GetResourceEntryCallback& callback);
 
  private:
+  struct EntryInfo;
   struct UploadSession;
 
   // Returns a pointer to the entry that matches |resource_id|, or NULL if
   // not found.
-  base::DictionaryValue* FindEntryByResourceId(const std::string& resource_id);
-
-  // Returns a pointer to the entry that matches |content_url|, or NULL if
-  // not found.
-  base::DictionaryValue* FindEntryByContentUrl(const GURL& content_url);
+  EntryInfo* FindEntryByResourceId(const std::string& resource_id);
 
   // Returns a new resource ID, which looks like "resource_id_<num>" where
   // <num> is a monotonically increasing number starting from 1.
   std::string GetNewResourceId();
 
-  // Increments |largest_changestamp_| and adds the new changestamp and ETag to
-  // |entry|.
-  void AddNewChangestampAndETag(base::DictionaryValue* entry);
-
-  // Adds a new entry based on the given parameters. |entry_kind| should be
-  // "file" or "folder". Returns a pointer to the newly added entry, or NULL
-  // if failed.
-  const base::DictionaryValue* AddNewEntry(
-    const std::string& content_type,
-    const std::string& content_data,
-    const std::string& parent_resource_id,
-    const std::string& title,
-    bool shared_with_me,
-    const std::string& entry_kind);
+  // Increments |largest_changestamp_| and adds the new changestamp.
+  void AddNewChangestamp(google_apis::ChangeResource* change);
+
+  // Update ETag of |file| based on |largest_changestamp_|.
+  void UpdateETag(google_apis::FileResource* file);
+
+  // Adds a new entry based on the given parameters.
+  // |resource_id| can be empty, in the case, the id is automatically generated.
+  // Returns a pointer to the newly added entry, or NULL if failed.
+  const EntryInfo* AddNewEntry(
+      const std::string& resource_id,
+      const std::string& content_type,
+      const std::string& content_data,
+      const std::string& parent_resource_id,
+      const std::string& title,
+      bool shared_with_me);
 
   // Core implementation of GetResourceList.
   // This method returns the slice of the all matched entries, and its range
@@ -299,11 +316,11 @@ class FakeDriveService : public DriveServiceInterface {
   // Returns new upload session URL.
   GURL GetNewUploadSessionUrl();
 
-  scoped_ptr<base::DictionaryValue> resource_list_value_;
-  scoped_ptr<base::DictionaryValue> account_metadata_value_;
-  scoped_ptr<base::Value> app_info_value_;
+  typedef std::map<std::string, EntryInfo*> EntryInfoMap;
+  EntryInfoMap entries_;
+  scoped_ptr<google_apis::AboutResource> about_resource_;
+  scoped_ptr<base::DictionaryValue> app_info_value_;
   std::map<GURL, UploadSession> upload_sessions_;
-  int64 largest_changestamp_;
   int64 published_date_seq_;
   int64 next_upload_sequence_number_;
   int default_max_results_;