Index: native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_googledrivefs.h |
diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_googledrivefs.h b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_googledrivefs.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a7107c6d765216be42ae3b9c6d1038befc7dee09 |
--- /dev/null |
+++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_googledrivefs.h |
@@ -0,0 +1,212 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef LIBRARIES_NACL_IO_TEST_FAKE_PEPPER_INTERFACE_GOOGLEDRIVEFS_H_ |
+#define LIBRARIES_NACL_IO_TEST_FAKE_PEPPER_INTERFACE_GOOGLEDRIVEFS_H_ |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "nacl_io/pepper_interface_dummy.h" |
+#include "sdk_util/macros.h" |
+ |
+#include "fake_ppapi/fake_core_interface.h" |
+#include "fake_ppapi/fake_file_io_interface.h" |
+#include "fake_ppapi/fake_var_interface.h" |
+#include "fake_ppapi/fake_var_manager.h" |
+#include "fake_ppapi/fake_pepper_interface_url_loader.h" |
+ |
+struct FakeGoogleDriveServerResponse { |
+ int status_code; |
+ std::string body; |
+}; |
+ |
+// A Google Drive item can mean a directory or a file. |
+// A directory or a file in FakeGoogleDriveServer can be a |
+// FakeGoogleDriveItem object. |
+class FakeGoogleDriveItem { |
+ public: |
+ FakeGoogleDriveItem() {} |
+ FakeGoogleDriveItem(std::string id, |
+ std::string name, |
+ std::string contents, |
+ std::string modified_time, |
+ std::string parent_dir_id, |
+ bool is_dir) |
+ : id_(id), |
+ name_(name), |
+ contents_(contents), |
+ modified_time_(modified_time), |
+ parent_dir_id_(parent_dir_id), |
+ is_dir_(is_dir) {} |
+ |
+ std::string id() const { return id_; } |
+ std::string name() const { return name_; } |
+ std::string contents() const { return contents_; } |
+ std::string modified_time() const { return modified_time_; } |
+ std::string parent_dir_id() const { return parent_dir_id_; } |
+ bool is_dir() const { return is_dir_; } |
+ |
+ void set_contents(const std::string& contents) { contents_ = contents; } |
+ |
+ private: |
+ std::string id_; |
+ std::string name_; |
+ std::string contents_; |
+ std::string modified_time_; |
+ std::string parent_dir_id_; |
+ bool is_dir_; |
+}; |
+ |
+class FakeGoogleDriveDirent { |
+ public: |
+ FakeGoogleDriveDirent() {} |
+ FakeGoogleDriveDirent(std::string parent_dir_id, size_t index) |
+ : parent_dir_id_(parent_dir_id), index_(index) {} |
+ |
+ std::string parent_dir_id() { return parent_dir_id_; } |
+ size_t index() { return index_; } |
+ |
+ private: |
+ std::string parent_dir_id_; |
+ size_t index_; |
+}; |
+ |
+typedef std::map<std::string, std::vector<FakeGoogleDriveItem*> > |
+ VectorOfItemsMap; |
+typedef std::map<std::string, FakeGoogleDriveDirent> DirentMap; |
+typedef std::map<std::string, FakeGoogleDriveItem> ItemMap; |
+ |
+class FakeGoogleDriveServer { |
+ public: |
+ FakeGoogleDriveServer(); |
+ FakeGoogleDriveServerResponse Respond(const std::string& url, |
+ const std::string& headers, |
+ const std::string& method, |
+ const std::string& body); |
+ static size_t files_per_page(); |
+ static std::string folder_mime_type(); |
+ |
+ private: |
+ void AddBody(const std::string& data, std::string* out_body); |
+ void MakeDriveFileListResponse( |
+ const std::vector<FakeGoogleDriveItem*>& dirents, |
+ size_t start_index, |
+ size_t end_index, |
+ const std::string& optional_next_page_token, |
+ std::string* out_body); |
+ int32_t GenerateItemId(std::string* out_item_id); |
+ int32_t ProduceNextPageToken(const std::string& parent_dir_id, |
+ size_t cur_index, |
+ std::string* out_next_page_token); |
+ |
+ int32_t GetItemField(const FakeGoogleDriveItem& item, |
+ const std::string& field, |
+ std::string* out_value); |
+ |
+ int32_t PauseNameFromBody(const std::string& body, std::string* out_name); |
+ int32_t PauseParentDirIdFromBody(const std::string& body, |
+ std::string* out_parent_dir_id); |
+ int32_t PauseIdFromUrlPath(const std::string& url, std::string* out_id); |
+ int32_t PauseParentDirIdFromUrlQuery(const std::string& url, |
+ std::string* out_parent_dir_id); |
+ int32_t PauseNameFromUrlQuery(const std::string& url, std::string* out_name); |
+ int32_t PauseValueStringFromUrlQuery(const std::string& url, |
+ const std::string& key, |
+ std::string* out_value_string); |
+ |
+ FakeGoogleDriveServerResponse RespondDirent(const std::string& url); |
+ FakeGoogleDriveServerResponse RespondDirentNextPage(const std::string& url); |
+ FakeGoogleDriveServerResponse RespondItemFieldValue(const std::string& url); |
+ FakeGoogleDriveServerResponse RespondFileWriteRequest( |
+ const std::string& url, |
+ const std::string& body); |
+ FakeGoogleDriveServerResponse RespondFileCreationRequest( |
+ const std::string& url, |
+ const std::string& body); |
+ FakeGoogleDriveServerResponse RespondFileReadRequest( |
+ const std::string& url, |
+ const std::string& headers); |
+ FakeGoogleDriveServerResponse RespondRemoveDirRequest(const std::string& url); |
+ FakeGoogleDriveServerResponse RespondItemId(const std::string& url); |
+ FakeGoogleDriveServerResponse RespondMakeDirRequest(const std::string& url, |
+ const std::string& body); |
+ |
+ VectorOfItemsMap vector_of_items_map_; |
+ DirentMap dirent_map_; |
+ ItemMap item_map_; |
+ int token_id_; |
+ int item_id_; |
+}; |
+ |
+class FakeGoogleDriveURLLoaderInterface : public FakeURLLoaderInterface { |
+ public: |
+ explicit FakeGoogleDriveURLLoaderInterface(FakeCoreInterface* core_interface); |
+ |
+ virtual PP_Resource Create(PP_Instance instance); |
+ virtual int32_t Open(PP_Resource loader, |
+ PP_Resource request_info, |
+ PP_CompletionCallback callback); |
+ virtual PP_Resource GetResponseInfo(PP_Resource loader); |
+ virtual int32_t FinishStreamingToFile(PP_Resource loader, |
+ PP_CompletionCallback callback); |
+ virtual void Close(PP_Resource loader); |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(FakeGoogleDriveURLLoaderInterface); |
+}; |
+ |
+// This class is a fake implementation of the interfaces necessary to access |
+// the GOOGLEDRIVEFS Filesystem from NaCl. |
+// |
+// Example: |
+// FakePepperInterfaceGoogleDriveFs ppapi_googledrivefs; |
+// ... |
+// PP_Resource ref_resource = |
+// ppapi_googledrivefs.GetURLLoaderInterface()->Create( |
+// ppapi_googledrivefs.GetInstance()); |
+// ... |
+// |
+// NOTE: This pepper interface creates an instance resource that can only be |
+// used with FakePepperInterfaceGoogleDriveFs, not other fake pepper |
+// implementations. |
+ |
+class FakePepperInterfaceGoogleDriveFs : public nacl_io::PepperInterfaceDummy { |
+ public: |
+ FakePepperInterfaceGoogleDriveFs(); |
+ ~FakePepperInterfaceGoogleDriveFs(); |
+ |
+ virtual PP_Instance GetInstance() { return instance_; } |
+ virtual nacl_io::CoreInterface* GetCoreInterface(); |
+ virtual nacl_io::FileIoInterface* GetFileIoInterface(); |
+ virtual nacl_io::FileRefInterface* GetFileRefInterface(); |
+ virtual nacl_io::VarInterface* GetVarInterface(); |
+ virtual nacl_io::URLLoaderInterface* GetURLLoaderInterface(); |
+ virtual nacl_io::URLRequestInfoInterface* GetURLRequestInfoInterface(); |
+ virtual nacl_io::URLResponseInfoInterface* GetURLResponseInfoInterface(); |
+ |
+ FakeGoogleDriveServer* server_template() { |
+ return &google_drive_server_template_; |
+ } |
+ |
+ private: |
+ void Init(); |
+ |
+ FakeResourceManager resource_manager_; |
+ FakeCoreInterface core_interface_; |
+ FakeVarInterface var_interface_; |
+ FakeVarManager var_manager_; |
+ FakeFileIoInterface file_io_interface_; |
+ FakeFileRefInterface file_ref_interface_; |
+ FakeGoogleDriveServer google_drive_server_template_; |
+ FakeGoogleDriveURLLoaderInterface google_drive_url_loader_interface_; |
+ FakeURLRequestInfoInterface url_request_info_interface_; |
+ FakeURLResponseInfoInterface url_response_info_interface_; |
+ PP_Instance instance_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakePepperInterfaceGoogleDriveFs); |
+}; |
+ |
+#endif // LIBRARIES_NACL_IO_TEST_FAKE_PEPPER_INTERFACE_GOOGLEDRIVEFS_H_ |