Commit 7d7031e3 authored by chanpatorikku's avatar chanpatorikku Committed by Commit bot

[NaCl SDK] Implement FakePepperInterfaceGoogleDriveFs

Implement FakePepperInterfaceGoogleDriveFs, and implement
FakeDriveURLResponseInfoInterface and FakeDriveURLLoaderInterface, which
FakePepperInterfaceGoogleDriveFs uses.  FakePepperInterfaceGoogleDriveFs
is going to be used by the unit tests of the future code.

CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_nacl_sdk;master.tryserver.chromium.mac:mac_nacl_sdk;master.tryserver.chromium.win:win_nacl_sdk

Review-Url: https://codereview.chromium.org/2538163003
Cr-Commit-Position: refs/heads/master@{#438081}
parent acff1ef1
......@@ -29,6 +29,8 @@
'fake_ppapi/fake_node.h',
'fake_ppapi/fake_pepper_interface.cc',
'fake_ppapi/fake_pepper_interface.h',
'fake_ppapi/fake_pepper_interface_googledrivefs.cc',
'fake_ppapi/fake_pepper_interface_googledrivefs.h',
'fake_ppapi/fake_pepper_interface_html5_fs.cc',
'fake_ppapi/fake_pepper_interface_html5_fs.h',
'fake_ppapi/fake_pepper_interface_url_loader.cc',
......
// 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 <string>
#include "nacl_io/pepper_interface_dummy.h"
#include "sdk_util/macros.h"
#include "fake_ppapi/fake_core_interface.h"
#include "fake_ppapi/fake_file_ref_interface.h"
#include "fake_ppapi/fake_pepper_interface_url_loader.h"
#include "fake_ppapi/fake_var_interface.h"
#include "fake_ppapi/fake_var_manager.h"
struct FakeGoogleDriveServerResponse {
FakeGoogleDriveServerResponse() : status_code(0) {}
int status_code;
std::string body;
};
class FakeGoogleDriveServer {
public:
FakeGoogleDriveServer();
void Respond(const std::string& url,
const std::string& headers,
const std::string& method,
const std::string& body,
FakeGoogleDriveServerResponse* out_response);
};
class FakeDriveURLLoaderInterface : public FakeURLLoaderInterface {
public:
explicit FakeDriveURLLoaderInterface(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(FakeDriveURLLoaderInterface);
};
class FakeDriveURLResponseInfoInterface : public FakeURLResponseInfoInterface {
public:
FakeDriveURLResponseInfoInterface(FakeCoreInterface* core_interface,
FakeVarInterface* var_interface,
FakeFileRefInterface* file_ref_interface);
~FakeDriveURLResponseInfoInterface();
virtual PP_Resource GetBodyAsFileRef(PP_Resource response);
private:
FakeFileRefInterface* file_ref_interface_;
PP_Resource filesystem_resource_;
DISALLOW_COPY_AND_ASSIGN(FakeDriveURLResponseInfoInterface);
};
// 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::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_;
FakeFileRefInterface file_ref_interface_;
FakeGoogleDriveServer google_drive_server_template_;
FakeDriveURLLoaderInterface drive_url_loader_interface_;
FakeURLRequestInfoInterface url_request_info_interface_;
FakeDriveURLResponseInfoInterface drive_url_response_info_interface_;
PP_Instance instance_;
DISALLOW_COPY_AND_ASSIGN(FakePepperInterfaceGoogleDriveFs);
};
#endif // LIBRARIES_NACL_IO_TEST_FAKE_PEPPER_INTERFACE_GOOGLEDRIVEFS_H_
......@@ -11,6 +11,8 @@
#include "gtest/gtest.h"
#include <ppapi/c/pp_bool.h>
#include "fake_ppapi/fake_util.h"
#include "nacl_io/osinttypes.h"
......@@ -470,6 +472,13 @@ PP_Bool FakeURLRequestInfoInterface::SetProperty(PP_Resource request,
// Throw the value away for now. TODO(binji): add tests for this.
return PP_TRUE;
}
case PP_URLREQUESTPROPERTY_STREAMTOFILE: {
if (value.type != PP_VARTYPE_BOOL)
return PP_FALSE;
request_resource->stream_to_file = PP_ToBool(value.value.as_bool);
return PP_TRUE;
}
default:
EXPECT_TRUE(false) << "Unimplemented property " << property
<< " in "
......
......@@ -104,9 +104,10 @@ class FakeURLLoaderInterface : public nacl_io::URLLoaderInterface {
virtual void Close(PP_Resource loader);
private:
protected:
FakeCoreInterface* core_interface_; // Weak reference.
private:
DISALLOW_COPY_AND_ASSIGN(FakeURLLoaderInterface);
};
......@@ -139,10 +140,11 @@ class FakeURLResponseInfoInterface : public nacl_io::URLResponseInfoInterface {
PP_URLResponseProperty property);
virtual PP_Resource GetBodyAsFileRef(PP_Resource response);
private:
protected:
FakeCoreInterface* core_interface_; // Weak reference.
FakeVarInterface* var_interface_; // Weak reference.
private:
DISALLOW_COPY_AND_ASSIGN(FakeURLResponseInfoInterface);
};
......
......@@ -12,6 +12,8 @@
#include "fake_ppapi/fake_filesystem.h"
#include "fake_ppapi/fake_resource_manager.h"
const int32_t STATUSCODE_NOT_IMPLEMENTED = 501;
class FakeFileRefResource : public FakeResource {
public:
FakeFileRefResource() : filesystem(NULL) {}
......@@ -42,13 +44,14 @@ class FakeHtml5FsResource : public FakeResource {
class FakeURLRequestInfoResource : public FakeResource {
public:
FakeURLRequestInfoResource() {}
FakeURLRequestInfoResource() : stream_to_file(false) {}
static const char* classname() { return "FakeURLRequestInfoResource"; }
std::string url;
std::string method;
std::string headers;
std::string body;
bool stream_to_file;
};
class FakeURLResponseInfoResource : public FakeResource {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment