Chromium Code Reviews| 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..42cc20dea78737cb66079d1959acfefe935e57d3 |
| --- /dev/null |
| +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_pepper_interface_googledrivefs.h |
| @@ -0,0 +1,192 @@ |
| +// 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 Response { |
| + int status_code; |
| + std::string body; |
| +}; |
| + |
| +class ItemMetadata { |
| + public: |
| + ItemMetadata() |
| + : id_(""), name_(""), contents_(""), modified_time_(""), is_dir_(true) {} |
|
binji
2016/08/22 19:21:53
not necessary to initialize strings to "", that's
chanpatorikku
2016/08/29 17:14:03
Done.
|
| + ItemMetadata(std::string id, |
| + std::string name, |
| + std::string contents, |
| + std::string modified_time, |
| + bool is_dir) |
| + : id_(id), |
| + name_(name), |
| + contents_(contents), |
| + modified_time_(modified_time), |
| + is_dir_(is_dir) {} |
| + |
| + std::string id() { return id_; } |
| + std::string name() { return name_; } |
| + std::string contents() { return contents_; } |
| + std::string modified_time() { return modified_time_; } |
| + bool is_dir() { 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_; |
| + bool is_dir_; |
| +}; |
| + |
| +class NextEntry { |
| + public: |
| + NextEntry() : parent_dir_id_(""), index_(-1) {} |
| + NextEntry(std::string parent_dir_id, int index) |
| + : parent_dir_id_(parent_dir_id), index_(index) {} |
| + |
| + std::string parent_dir_id() { return parent_dir_id_; } |
| + int index() { return index_; } |
| + |
| + private: |
| + std::string parent_dir_id_; |
| + int index_; |
| +}; |
| + |
| +class FakeGoogleDriveServer { |
| + public: |
| + FakeGoogleDriveServer(); |
| + Response Respond(const std::string& url, |
| + const std::string& headers, |
| + const std::string& method, |
| + const std::string& body); |
| + bool AddFile(const std::string& parent_dir_id, |
| + const std::string& name, |
| + const std::string& contents); |
| + static int FILES_PER_PAGE; |
| + |
| + private: |
| + void AddBody(const std::string& data, std::string* out_body); |
| + std::string GetIdFromUrlPath(const std::string& url); |
| + std::string GetParentDirIdFromUrlQuery(const std::string& url); |
| + std::string GetNameFromUrlQuery(const std::string& url); |
| + void MakeIdExistResponse(const std::string& id, |
| + const std::string& name, |
| + std::string* out_body); |
| + void MakeIdNotExistResponse(std::string* out_body); |
| + void AddItemArray(const std::string& parent_dir_id, |
| + int file_list_start_index, |
| + std::string* out_body); |
| + std::string GetPageTokenFromUrlQuery(const std::string& url); |
| + std::string GetNameFromBody(const std::string& body); |
| + std::string GetParentDirIdFromBody(const std::string& body); |
| + |
| + Response RespondDirent(const std::string& url); |
| + Response RespondDirentNextPage(const std::string& url); |
| + Response RespondFileWriteRequest(const std::string& url, |
| + const std::string& body); |
| + Response RespondFileCreationRequest(const std::string& url, |
| + const std::string& body); |
| + Response RespondFileReadRequest(const std::string& url, |
| + const std::string& headers); |
| + Response RespondRemoveDirRequest(const std::string& url); |
| + Response RespondItemModifiedTime(const std::string& url); |
| + Response RespondItemSize(const std::string& url); |
| + Response RespondItemId(const std::string& url); |
| + Response RespondDirId(const std::string& url); |
| + Response RespondMakeDirRequest(const std::string& url, |
| + const std::string& body); |
| + |
| + std::map<std::string, std::vector<ItemMetadata*> > dir_id_to_file_list; |
| + std::map<std::string, NextEntry> token_to_next_entry; |
| + std::map<std::string, ItemMetadata> item_id_to_metadata; |
| + |
| + 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_ |