| Index: native_client_sdk/src/tests/nacl_io_test/mount_http_test.cc
|
| diff --git a/native_client_sdk/src/tests/nacl_io_test/mount_http_test.cc b/native_client_sdk/src/tests/nacl_io_test/mount_http_test.cc
|
| index 8ec27db43b0d73b625fa4e7a41fe6904c86e5256..79a2fcbf0c02c3863f2fced2042a6125718ce995 100644
|
| --- a/native_client_sdk/src/tests/nacl_io_test/mount_http_test.cc
|
| +++ b/native_client_sdk/src/tests/nacl_io_test/mount_http_test.cc
|
| @@ -10,36 +10,26 @@
|
| #include <sys/stat.h>
|
| #include <sys/types.h>
|
|
|
| -#include "mock_util.h"
|
| +#include "fake_pepper_interface_url_loader.h"
|
| +
|
| #include "nacl_io/kernel_handle.h"
|
| #include "nacl_io/kernel_intercept.h"
|
| #include "nacl_io/mount_http.h"
|
| #include "nacl_io/mount_node_dir.h"
|
| #include "nacl_io/osdirent.h"
|
| #include "nacl_io/osunistd.h"
|
| -#include "pepper_interface_mock.h"
|
|
|
| using namespace nacl_io;
|
|
|
| -using ::testing::_;
|
| -using ::testing::DoAll;
|
| -using ::testing::Mock;
|
| -using ::testing::Return;
|
| -using ::testing::SetArgPointee;
|
| -using ::testing::StrEq;
|
| +namespace {
|
|
|
| -class MountHttpMock : public MountHttp {
|
| +class MountHttpForTesting : public MountHttp {
|
| public:
|
| - MountHttpMock(StringMap_t map, PepperInterfaceMock* ppapi) {
|
| + MountHttpForTesting(StringMap_t map, PepperInterface* ppapi) {
|
| EXPECT_EQ(0, Init(1, map, ppapi));
|
| }
|
|
|
| - ~MountHttpMock() {
|
| - Destroy();
|
| - }
|
| -
|
| - NodeMap_t& GetMap() { return node_cache_; }
|
| -
|
| + using MountHttp::GetNodeCacheForTesting;
|
| using MountHttp::ParseManifest;
|
| using MountHttp::FindOrCreateDir;
|
| };
|
| @@ -47,103 +37,186 @@ class MountHttpMock : public MountHttp {
|
| class MountHttpTest : public ::testing::Test {
|
| public:
|
| MountHttpTest();
|
| - ~MountHttpTest();
|
|
|
| protected:
|
| - PepperInterfaceMock ppapi_;
|
| - MountHttpMock* mnt_;
|
| + FakePepperInterfaceURLLoader ppapi_;
|
| + MountHttpForTesting mnt_;
|
| +};
|
| +
|
| +MountHttpTest::MountHttpTest() : mnt_(StringMap_t(), &ppapi_) {}
|
| +
|
| +StringMap_t StringMap_NoCache() {
|
| + StringMap_t smap;
|
| + smap["cache_content"] = "false";
|
| + return smap;
|
| +}
|
| +
|
| +class MountHttpNoCacheTest : public ::testing::Test {
|
| + public:
|
| + MountHttpNoCacheTest();
|
|
|
| - static const PP_Instance instance_ = 123;
|
| + protected:
|
| + FakePepperInterfaceURLLoader ppapi_;
|
| + MountHttpForTesting mnt_;
|
| };
|
|
|
| -MountHttpTest::MountHttpTest()
|
| - : ppapi_(instance_),
|
| - mnt_(NULL) {
|
| +MountHttpNoCacheTest::MountHttpNoCacheTest() :
|
| + mnt_(StringMap_NoCache(), &ppapi_) {}
|
| +
|
| +} // namespace
|
| +
|
| +
|
| +TEST_F(MountHttpTest, Access) {
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("foo", "", NULL));
|
| +
|
| + ASSERT_EQ(0, mnt_.Access(Path("/foo"), R_OK));
|
| + ASSERT_EQ(EACCES, mnt_.Access(Path("/foo"), W_OK));
|
| + ASSERT_EQ(EACCES, mnt_.Access(Path("/foo"), X_OK));
|
| + ASSERT_EQ(ENOENT, mnt_.Access(Path("/bar"), F_OK));
|
| +}
|
| +
|
| +TEST_F(MountHttpTest, Read) {
|
| + const char contents[] = "contents";
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
|
| +
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(0, mnt_.Open(Path("/file"), O_RDONLY, &node));
|
| +
|
| + char buffer[10] = {0};
|
| + int bytes_read = 0;
|
| + HandleAttr attr;
|
| + EXPECT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
|
| + EXPECT_EQ(strlen(contents), bytes_read);
|
| + EXPECT_STREQ(contents, buffer);
|
| +
|
| + // Read nothing past the end of the file.
|
| + attr.offs = 100;
|
| + EXPECT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
|
| + EXPECT_EQ(0, bytes_read);
|
| +
|
| + // Read part of the data.
|
| + attr.offs = 4;
|
| + EXPECT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
|
| + ASSERT_EQ(strlen(contents) - 4, bytes_read);
|
| + buffer[bytes_read] = 0;
|
| + EXPECT_STREQ("ents", buffer);
|
| +}
|
| +
|
| +TEST_F(MountHttpTest, Write) {
|
| + const char contents[] = "contents";
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
|
| +
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(0, mnt_.Open(Path("/file"), O_WRONLY, &node));
|
| +
|
| + // Writing always fails.
|
| + HandleAttr attr;
|
| + attr.offs = 3;
|
| + int bytes_written = 1; // Set to a non-zero value.
|
| + EXPECT_EQ(EACCES, node->Write(attr, "struct", 6, &bytes_written));
|
| + EXPECT_EQ(0, bytes_written);
|
| }
|
|
|
| -MountHttpTest::~MountHttpTest() {
|
| - delete mnt_;
|
| +TEST_F(MountHttpTest, GetStat) {
|
| + const char contents[] = "contents";
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
|
| +
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(0, mnt_.Open(Path("/file"), O_RDONLY, &node));
|
| +
|
| + struct stat statbuf;
|
| + EXPECT_EQ(0, node->GetStat(&statbuf));
|
| + EXPECT_EQ(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH,
|
| + statbuf.st_mode);
|
| + EXPECT_EQ(strlen(contents), statbuf.st_size);
|
| + // These are not currently set.
|
| + EXPECT_EQ(0, statbuf.st_atime);
|
| + EXPECT_EQ(0, statbuf.st_ctime);
|
| + EXPECT_EQ(0, statbuf.st_mtime);
|
| }
|
|
|
| +TEST_F(MountHttpTest, FTruncate) {
|
| + const char contents[] = "contents";
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
|
|
|
| -TEST_F(MountHttpTest, MountEmpty) {
|
| - StringMap_t args;
|
| - mnt_ = new MountHttpMock(args, &ppapi_);
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(0, mnt_.Open(Path("/file"), O_RDWR, &node));
|
| + EXPECT_EQ(EACCES, node->FTruncate(4));
|
| }
|
|
|
| -TEST_F(MountHttpTest, Mkdir) {
|
| +TEST(MountHttpDirTest, Mkdir) {
|
| StringMap_t args;
|
| - mnt_ = new MountHttpMock(args, &ppapi_);
|
| + MountHttpForTesting mnt(args, NULL);
|
| char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n";
|
| - EXPECT_EQ(0, mnt_->ParseManifest(manifest));
|
| + ASSERT_EQ(0, mnt.ParseManifest(manifest));
|
| // mkdir of existing directories should give "File exists".
|
| - EXPECT_EQ(EEXIST, mnt_->Mkdir(Path("/"), 0));
|
| - EXPECT_EQ(EEXIST, mnt_->Mkdir(Path("/mydir"), 0));
|
| + EXPECT_EQ(EEXIST, mnt.Mkdir(Path("/"), 0));
|
| + EXPECT_EQ(EEXIST, mnt.Mkdir(Path("/mydir"), 0));
|
| // mkdir of non-existent directories should give "Permission denied".
|
| - EXPECT_EQ(EACCES, mnt_->Mkdir(Path("/non_existent"), 0));
|
| + EXPECT_EQ(EACCES, mnt.Mkdir(Path("/non_existent"), 0));
|
| }
|
|
|
| -TEST_F(MountHttpTest, Rmdir) {
|
| +TEST(MountHttpDirTest, Rmdir) {
|
| StringMap_t args;
|
| - mnt_ = new MountHttpMock(args, &ppapi_);
|
| + MountHttpForTesting mnt(args, NULL);
|
| char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n";
|
| - EXPECT_EQ(0, mnt_->ParseManifest(manifest));
|
| + ASSERT_EQ(0, mnt.ParseManifest(manifest));
|
| // Rmdir on existing dirs should give "Permission Denied"
|
| - EXPECT_EQ(EACCES, mnt_->Rmdir(Path("/")));
|
| - EXPECT_EQ(EACCES, mnt_->Rmdir(Path("/mydir")));
|
| + EXPECT_EQ(EACCES, mnt.Rmdir(Path("/")));
|
| + EXPECT_EQ(EACCES, mnt.Rmdir(Path("/mydir")));
|
| // Rmdir on existing files should give "Not a direcotory"
|
| - EXPECT_EQ(ENOTDIR, mnt_->Rmdir(Path("/mydir/foo")));
|
| + EXPECT_EQ(ENOTDIR, mnt.Rmdir(Path("/mydir/foo")));
|
| // Rmdir on non-existent files should give "No such file or directory"
|
| - EXPECT_EQ(ENOENT, mnt_->Rmdir(Path("/non_existent")));
|
| + EXPECT_EQ(ENOENT, mnt.Rmdir(Path("/non_existent")));
|
| }
|
|
|
| -TEST_F(MountHttpTest, Unlink) {
|
| +TEST(MountHttpDirTest, Unlink) {
|
| StringMap_t args;
|
| - mnt_ = new MountHttpMock(args, &ppapi_);
|
| + MountHttpForTesting mnt(args, NULL);
|
| char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n";
|
| - EXPECT_EQ(0, mnt_->ParseManifest(manifest));
|
| + ASSERT_EQ(0, mnt.ParseManifest(manifest));
|
| // Unlink of existing files should give "Permission Denied"
|
| - EXPECT_EQ(EACCES, mnt_->Unlink(Path("/mydir/foo")));
|
| + EXPECT_EQ(EACCES, mnt.Unlink(Path("/mydir/foo")));
|
| // Unlink of existing directory should give "Is a directory"
|
| - EXPECT_EQ(EISDIR, mnt_->Unlink(Path("/mydir")));
|
| + EXPECT_EQ(EISDIR, mnt.Unlink(Path("/mydir")));
|
| // Unlink of non-existent files should give "No such file or directory"
|
| - EXPECT_EQ(ENOENT, mnt_->Unlink(Path("/non_existent")));
|
| + EXPECT_EQ(ENOENT, mnt.Unlink(Path("/non_existent")));
|
| }
|
|
|
| -TEST_F(MountHttpTest, Remove) {
|
| +TEST(MountHttpDirTest, Remove) {
|
| StringMap_t args;
|
| - mnt_ = new MountHttpMock(args, &ppapi_);
|
| + MountHttpForTesting mnt(args, NULL);
|
| char manifest[] = "-r-- 123 /mydir/foo\n-rw- 234 /thatdir/bar\n";
|
| - EXPECT_EQ(0, mnt_->ParseManifest(manifest));
|
| + ASSERT_EQ(0, mnt.ParseManifest(manifest));
|
| // Remove of existing files should give "Permission Denied"
|
| - EXPECT_EQ(EACCES, mnt_->Remove(Path("/mydir/foo")));
|
| + EXPECT_EQ(EACCES, mnt.Remove(Path("/mydir/foo")));
|
| // Remove of existing directory should give "Permission Denied"
|
| - EXPECT_EQ(EACCES, mnt_->Remove(Path("/mydir")));
|
| + EXPECT_EQ(EACCES, mnt.Remove(Path("/mydir")));
|
| // Unlink of non-existent files should give "No such file or directory"
|
| - EXPECT_EQ(ENOENT, mnt_->Remove(Path("/non_existent")));
|
| + EXPECT_EQ(ENOENT, mnt.Remove(Path("/non_existent")));
|
| }
|
|
|
| -TEST_F(MountHttpTest, ParseManifest) {
|
| +TEST(MountHttpDirTest, ParseManifest) {
|
| StringMap_t args;
|
| size_t result_size = 0;
|
|
|
| - mnt_ = new MountHttpMock(args, &ppapi_);
|
| + MountHttpForTesting mnt(args, NULL);
|
|
|
| // Multiple consecutive newlines or spaces should be ignored.
|
| char manifest[] = "-r-- 123 /mydir/foo\n\n-rw- 234 /thatdir/bar\n";
|
| - EXPECT_EQ(0, mnt_->ParseManifest(manifest));
|
| + ASSERT_EQ(0, mnt.ParseManifest(manifest));
|
|
|
| ScopedMountNode root;
|
| - EXPECT_EQ(0, mnt_->FindOrCreateDir(Path("/"), &root));
|
| + EXPECT_EQ(0, mnt.FindOrCreateDir(Path("/"), &root));
|
| ASSERT_NE((MountNode*)NULL, root.get());
|
| EXPECT_EQ(2, root->ChildCount());
|
|
|
| ScopedMountNode dir;
|
| - EXPECT_EQ(0, mnt_->FindOrCreateDir(Path("/mydir"), &dir));
|
| + EXPECT_EQ(0, mnt.FindOrCreateDir(Path("/mydir"), &dir));
|
| ASSERT_NE((MountNode*)NULL, dir.get());
|
| EXPECT_EQ(1, dir->ChildCount());
|
|
|
| - MountNode* node = mnt_->GetMap()["/mydir/foo"].get();
|
| + MountNode* node = (*mnt.GetNodeCacheForTesting())["/mydir/foo"].get();
|
| EXPECT_NE((MountNode*)NULL, node);
|
| EXPECT_EQ(0, node->GetSize(&result_size));
|
| EXPECT_EQ(123, result_size);
|
| @@ -151,10 +224,10 @@ TEST_F(MountHttpTest, ParseManifest) {
|
| // Since these files are cached thanks to the manifest, we can open them
|
| // without accessing the PPAPI URL API.
|
| ScopedMountNode foo;
|
| - EXPECT_EQ(0, mnt_->Open(Path("/mydir/foo"), O_RDONLY, &foo));
|
| + ASSERT_EQ(0, mnt.Open(Path("/mydir/foo"), O_RDONLY, &foo));
|
|
|
| ScopedMountNode bar;
|
| - EXPECT_EQ(0, mnt_->Open(Path("/thatdir/bar"), O_RDWR, &bar));
|
| + ASSERT_EQ(0, mnt.Open(Path("/thatdir/bar"), O_RDWR, &bar));
|
|
|
| struct stat sfoo;
|
| struct stat sbar;
|
| @@ -169,459 +242,88 @@ TEST_F(MountHttpTest, ParseManifest) {
|
| EXPECT_EQ(S_IFREG | S_IRALL | S_IWALL, sbar.st_mode);
|
| }
|
|
|
| +TEST_F(MountHttpNoCacheTest, OpenAndClose) {
|
| + const char contents[] = "contents";
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
|
|
|
| -class MountHttpNodeTest : public MountHttpTest {
|
| - public:
|
| - MountHttpNodeTest();
|
| - virtual void TearDown();
|
| -
|
| - void SetMountArgs(const StringMap_t& args);
|
| - void ExpectOpen(const char* method);
|
| - void ExpectHeaders(const char* headers);
|
| - void OpenNode();
|
| - void SetResponse(int status_code, const char* headers);
|
| - // Set a response code, but expect the request to fail. Certain function calls
|
| - // expected by SetResponse are not expected here.
|
| - void SetResponseExpectFail(int status_code, const char* headers);
|
| - void SetResponseBody(const char* body);
|
| - void ResetMocks();
|
| -
|
| - protected:
|
| - MountHttpMock* mnt_;
|
| - ScopedMountNode node_;
|
| -
|
| - CoreInterfaceMock* core_;
|
| - VarInterfaceMock* var_;
|
| - URLLoaderInterfaceMock* loader_;
|
| - URLRequestInfoInterfaceMock* request_;
|
| - URLResponseInfoInterfaceMock* response_;
|
| - size_t response_body_offset_;
|
| -
|
| - static const char path_[];
|
| - static const char rel_path_[];
|
| - static const PP_Resource loader_resource_ = 235;
|
| - static const PP_Resource request_resource_ = 236;
|
| - static const PP_Resource response_resource_ = 237;
|
| -};
|
| -
|
| -// static
|
| -const char MountHttpNodeTest::path_[] = "/foo";
|
| -// static
|
| -const char MountHttpNodeTest::rel_path_[] = "foo";
|
| -
|
| -MountHttpNodeTest::MountHttpNodeTest()
|
| - : mnt_(NULL),
|
| - node_(NULL) {
|
| -}
|
| -
|
| -static PP_Var MakeString(PP_Resource resource) {
|
| - PP_Var result = { PP_VARTYPE_STRING, 0, {PP_FALSE} };
|
| - result.value.as_id = resource;
|
| - return result;
|
| -}
|
| -
|
| -void MountHttpNodeTest::SetMountArgs(const StringMap_t& args) {
|
| - mnt_ = new MountHttpMock(args, &ppapi_);
|
| -}
|
| -
|
| -void MountHttpNodeTest::ExpectOpen(const char* method) {
|
| - core_ = ppapi_.GetCoreInterface();
|
| - loader_ = ppapi_.GetURLLoaderInterface();
|
| - request_ = ppapi_.GetURLRequestInfoInterface();
|
| - response_ = ppapi_.GetURLResponseInfoInterface();
|
| - var_ = ppapi_.GetVarInterface();
|
| -
|
| - ON_CALL(*request_, SetProperty(request_resource_, _, _))
|
| - .WillByDefault(Return(PP_TRUE));
|
| - ON_CALL(*var_, VarFromUtf8(_, _)).WillByDefault(Return(PP_MakeUndefined()));
|
| -
|
| - EXPECT_CALL(*loader_, Create(instance_)).WillOnce(Return(loader_resource_));
|
| - EXPECT_CALL(*request_, Create(instance_)).WillOnce(Return(request_resource_));
|
| -
|
| - PP_Var var_head = MakeString(345);
|
| - PP_Var var_url = MakeString(346);
|
| - EXPECT_CALL(*var_, VarFromUtf8(StrEq(method), _)).WillOnce(Return(var_head));
|
| - EXPECT_CALL(*var_, VarFromUtf8(StrEq(rel_path_), _))
|
| - .WillOnce(Return(var_url));
|
| -
|
| -#define EXPECT_SET_PROPERTY(NAME, VAR) \
|
| - EXPECT_CALL(*request_, SetProperty(request_resource_, NAME, VAR))
|
| -
|
| - EXPECT_SET_PROPERTY(PP_URLREQUESTPROPERTY_URL, IsEqualToVar(var_url));
|
| - EXPECT_SET_PROPERTY(PP_URLREQUESTPROPERTY_METHOD, IsEqualToVar(var_head));
|
| - EXPECT_SET_PROPERTY(PP_URLREQUESTPROPERTY_ALLOWCROSSORIGINREQUESTS, _);
|
| - EXPECT_SET_PROPERTY(PP_URLREQUESTPROPERTY_ALLOWCREDENTIALS, _);
|
| -
|
| -#undef EXPECT_SET_PROPERTY
|
| -
|
| - EXPECT_CALL(*loader_, Open(loader_resource_, request_resource_, _))
|
| - .WillOnce(DoAll(CallCallback<2>(int32_t(PP_OK)),
|
| - Return(int32_t(PP_OK_COMPLETIONPENDING))));
|
| - EXPECT_CALL(*loader_, GetResponseInfo(loader_resource_))
|
| - .WillOnce(Return(response_resource_));
|
| -
|
| - EXPECT_CALL(*core_, ReleaseResource(loader_resource_));
|
| - EXPECT_CALL(*core_, ReleaseResource(request_resource_));
|
| - EXPECT_CALL(*core_, ReleaseResource(response_resource_));
|
| -}
|
| -
|
| -void MountHttpNodeTest::ExpectHeaders(const char* headers) {
|
| - PP_Var var_headers = MakeString(347);
|
| - var_ = ppapi_.GetVarInterface();
|
| - EXPECT_CALL(*var_, VarFromUtf8(StrEq(headers), _))
|
| - .WillOnce(Return(var_headers));
|
| -
|
| - EXPECT_CALL(*request_, SetProperty(request_resource_,
|
| - PP_URLREQUESTPROPERTY_HEADERS,
|
| - IsEqualToVar(var_headers))).Times(1);
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(0, mnt_.Open(Path("/file"), O_RDONLY, &node));
|
| }
|
|
|
| -void MountHttpNodeTest::SetResponse(int status_code, const char* headers) {
|
| - ON_CALL(*response_, GetProperty(response_resource_, _))
|
| - .WillByDefault(Return(PP_MakeUndefined()));
|
| -
|
| - PP_Var var_headers = MakeString(348);
|
| - EXPECT_CALL(*response_,
|
| - GetProperty(response_resource_,
|
| - PP_URLRESPONSEPROPERTY_STATUSCODE))
|
| - .WillOnce(Return(PP_MakeInt32(status_code)));
|
| - EXPECT_CALL(*response_,
|
| - GetProperty(response_resource_, PP_URLRESPONSEPROPERTY_HEADERS))
|
| - .WillOnce(Return(var_headers));
|
| - EXPECT_CALL(*var_, VarToUtf8(IsEqualToVar(var_headers), _))
|
| - .WillOnce(DoAll(SetArgPointee<1>(strlen(headers)),
|
| - Return(headers)));
|
| -}
|
| -
|
| -void MountHttpNodeTest::SetResponseExpectFail(int status_code,
|
| - const char* headers) {
|
| - ON_CALL(*response_, GetProperty(response_resource_, _))
|
| - .WillByDefault(Return(PP_MakeUndefined()));
|
| -
|
| - EXPECT_CALL(*response_,
|
| - GetProperty(response_resource_,
|
| - PP_URLRESPONSEPROPERTY_STATUSCODE))
|
| - .WillOnce(Return(PP_MakeInt32(status_code)));
|
| +TEST_F(MountHttpNoCacheTest, OpenAndCloseNotFound) {
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(ENOENT, mnt_.Open(Path("/file"), O_RDONLY, &node));
|
| }
|
|
|
| -ACTION_P3(ReadResponseBodyAction, offset, body, body_length) {
|
| - char* buf = static_cast<char*>(arg1);
|
| - size_t read_length = arg2;
|
| - PP_CompletionCallback callback = arg3;
|
| - if (*offset >= body_length)
|
| - return 0;
|
| -
|
| - read_length = std::min(read_length, body_length - *offset);
|
| - memcpy(buf, body + *offset, read_length);
|
| - *offset += read_length;
|
| -
|
| - // Also call the callback.
|
| - if (callback.func)
|
| - (*callback.func)(callback.user_data, PP_OK);
|
| -
|
| - return read_length;
|
| -}
|
| +TEST_F(MountHttpNoCacheTest, OpenAndCloseServerError) {
|
| + ASSERT_TRUE(ppapi_.server_template()->AddError("file", 500));
|
|
|
| -void MountHttpNodeTest::SetResponseBody(const char* body) {
|
| - response_body_offset_ = 0;
|
| - EXPECT_CALL(*loader_, ReadResponseBody(loader_resource_, _, _, _))
|
| - .WillRepeatedly(ReadResponseBodyAction(
|
| - &response_body_offset_, body, strlen(body)));
|
| -}
|
| -
|
| -void MountHttpNodeTest::OpenNode() {
|
| - ASSERT_EQ(0, mnt_->Open(Path(path_), O_RDONLY, &node_));
|
| - ASSERT_NE((MountNode*)NULL, node_.get());
|
| -}
|
| -
|
| -void MountHttpNodeTest::ResetMocks() {
|
| - Mock::VerifyAndClearExpectations(&ppapi_);
|
| - Mock::VerifyAndClearExpectations(loader_);
|
| - Mock::VerifyAndClearExpectations(request_);
|
| - Mock::VerifyAndClearExpectations(response_);
|
| - Mock::VerifyAndClearExpectations(var_);
|
| -}
|
| -
|
| -void MountHttpNodeTest::TearDown() {
|
| - node_.reset();
|
| - delete mnt_;
|
| -}
|
| -
|
| -// TODO(binji): These tests are all broken now. In another CL, I'll reimplement
|
| -// these tests using an HTTP fake.
|
| -TEST_F(MountHttpNodeTest, DISABLED_OpenAndCloseNoCache) {
|
| - StringMap_t smap;
|
| - smap["cache_content"] = "false";
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "");
|
| - OpenNode();
|
| -}
|
| -
|
| -TEST_F(MountHttpNodeTest, DISABLED_OpenAndCloseNotFound) {
|
| - StringMap_t smap;
|
| - smap["cache_content"] = "false";
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponseExpectFail(404, "");
|
| - ASSERT_EQ(ENOENT, mnt_->Open(Path(path_), O_RDONLY, &node_));
|
| -}
|
| -
|
| -TEST_F(MountHttpNodeTest, DISABLED_OpenAndCloseServerError) {
|
| - StringMap_t smap;
|
| - smap["cache_content"] = "false";
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponseExpectFail(500, "");
|
| - ASSERT_EQ(EIO, mnt_->Open(Path(path_), O_RDONLY, &node_));
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(ENOENT, mnt_.Open(Path("/file"), O_RDONLY, &node));
|
| }
|
|
|
| -TEST_F(MountHttpNodeTest, DISABLED_GetStat) {
|
| - StringMap_t smap;
|
| - smap["cache_content"] = "false";
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "Content-Length: 42\n");
|
| - OpenNode();
|
| -
|
| - struct stat stat;
|
| - EXPECT_EQ(0, node_->GetStat(&stat));
|
| - EXPECT_EQ(42, stat.st_size);
|
| -}
|
| +TEST_F(MountHttpNoCacheTest, GetSize) {
|
| + const char contents[] = "contents";
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
|
| + ppapi_.server_template()->set_send_content_length(true);
|
|
|
| -TEST_F(MountHttpNodeTest, DISABLED_Access) {
|
| - StringMap_t smap;
|
| - smap["cache_content"] = "false";
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "");
|
| - ASSERT_EQ(0, mnt_->Access(Path(path_), R_OK));
|
| + ScopedMountNode node;
|
| + struct stat statbuf;
|
| + ASSERT_EQ(0, mnt_.Open(Path("/file"), O_RDONLY, &node));
|
| + EXPECT_EQ(0, node->GetStat(&statbuf));
|
| + EXPECT_EQ(strlen(contents), statbuf.st_size);
|
| }
|
|
|
| -TEST_F(MountHttpNodeTest, DISABLED_AccessWrite) {
|
| - StringMap_t smap;
|
| - smap["cache_content"] = "false";
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "");
|
| - ASSERT_EQ(EACCES, mnt_->Access(Path(path_), W_OK));
|
| -}
|
| +TEST_F(MountHttpNoCacheTest, Access) {
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", "", NULL));
|
|
|
| -TEST_F(MountHttpNodeTest, DISABLED_AccessNotFound) {
|
| - StringMap_t smap;
|
| - smap["cache_content"] = "false";
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponseExpectFail(404, "");
|
| - ASSERT_EQ(ENOENT, mnt_->Access(Path(path_), R_OK));
|
| + ASSERT_EQ(0, mnt_.Access(Path("/file"), R_OK));
|
| + ASSERT_EQ(EACCES, mnt_.Access(Path("/file"), W_OK));
|
| + ASSERT_EQ(ENOENT, mnt_.Access(Path("/bar"), R_OK));
|
| }
|
|
|
| -TEST_F(MountHttpNodeTest, DISABLED_ReadCached) {
|
| - size_t result_size = 0;
|
| - int result_bytes = 0;
|
| -
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "Content-Length: 42\n");
|
| - OpenNode();
|
| - ResetMocks();
|
| -
|
| - EXPECT_EQ(0, node_->GetSize(&result_size));
|
| - EXPECT_EQ(42, result_size);
|
| -
|
| - char buf[10];
|
| - memset(&buf[0], 0, sizeof(buf));
|
| -
|
| - ExpectOpen("GET");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "Content-Length: 42\n");
|
| - SetResponseBody("Here is some response text. And some more.");
|
| - HandleAttr attr;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| - EXPECT_STREQ("Here is s", &buf[0]);
|
| - ResetMocks();
|
| +TEST_F(MountHttpNoCacheTest, ReadPartial) {
|
| + const char contents[] = "0123456789abcdefghi";
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
|
| + ppapi_.server_template()->set_allow_partial(true);
|
|
|
| - // Further reads should be cached.
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| - EXPECT_STREQ("Here is s", &buf[0]);
|
| - attr.offs = 10;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| - EXPECT_STREQ("me respon", &buf[0]);
|
| -
|
| - EXPECT_EQ(0, node_->GetSize(&result_size));
|
| - EXPECT_EQ(42, result_size);
|
| -}
|
| -
|
| -TEST_F(MountHttpNodeTest, DISABLED_ReadCachedNoContentLength) {
|
| - size_t result_size = 0;
|
| int result_bytes = 0;
|
|
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "");
|
| - OpenNode();
|
| - ResetMocks();
|
| -
|
| - ExpectOpen("GET");
|
| - ExpectHeaders("");
|
| - SetResponse(200, ""); // No Content-Length response here.
|
| - SetResponseBody("Here is some response text. And some more.");
|
| -
|
| - // GetSize will Read() because it didn't get the content length from the HEAD
|
| - // request.
|
| - EXPECT_EQ(0, node_->GetSize(&result_size));
|
| - EXPECT_EQ(42, result_size);
|
| -
|
| char buf[10];
|
| memset(&buf[0], 0, sizeof(buf));
|
|
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(0, mnt_.Open(Path("/file"), O_RDONLY, &node));
|
| HandleAttr attr;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| - EXPECT_STREQ("Here is s", &buf[0]);
|
| - ResetMocks();
|
| + EXPECT_EQ(0, node->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| + EXPECT_EQ(sizeof(buf) - 1, result_bytes);
|
| + EXPECT_STREQ("012345678", &buf[0]);
|
|
|
| - // Further reads should be cached.
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| - EXPECT_STREQ("Here is s", &buf[0]);
|
| attr.offs = 10;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| - EXPECT_STREQ("me respon", &buf[0]);
|
| -
|
| - EXPECT_EQ(0, node_->GetSize(&result_size));
|
| - EXPECT_EQ(42, result_size);
|
| -}
|
| -
|
| -TEST_F(MountHttpNodeTest, DISABLED_ReadCachedUnderrun) {
|
| - size_t result_size = 0;
|
| - int result_bytes = 0;
|
| -
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "Content-Length: 100\n");
|
| - OpenNode();
|
| - ResetMocks();
|
| -
|
| - EXPECT_EQ(0, node_->GetSize(&result_size));
|
| - EXPECT_EQ(100, result_size);
|
| -
|
| - char buf[10];
|
| - memset(&buf[0], 0, sizeof(buf));
|
| -
|
| - ExpectOpen("GET");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "Content-Length: 100\n");
|
| - SetResponseBody("abcdefghijklmnopqrstuvwxyz");
|
| - HandleAttr attr;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| + EXPECT_EQ(0, node->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| EXPECT_EQ(sizeof(buf) - 1, result_bytes);
|
| EXPECT_STREQ("abcdefghi", &buf[0]);
|
| - ResetMocks();
|
| -
|
| - EXPECT_EQ(0, node_->GetSize(&result_size));
|
| - EXPECT_EQ(26, result_size);
|
| }
|
|
|
| -TEST_F(MountHttpNodeTest, DISABLED_ReadCachedOverrun) {
|
| - size_t result_size = 0;
|
| - int result_bytes = 0;
|
| -
|
| - SetMountArgs(StringMap_t());
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "Content-Length: 15\n");
|
| - OpenNode();
|
| - ResetMocks();
|
| -
|
| - EXPECT_EQ(0, node_->GetSize(&result_size));
|
| - EXPECT_EQ(15, result_size);
|
| -
|
| - char buf[10];
|
| - memset(&buf[0], 0, sizeof(buf));
|
| +TEST_F(MountHttpNoCacheTest, ReadPartialNoServerSupport) {
|
| + const char contents[] = "0123456789abcdefghi";
|
| + ASSERT_TRUE(ppapi_.server_template()->AddEntity("file", contents, NULL));
|
| + ppapi_.server_template()->set_allow_partial(false);
|
|
|
| - ExpectOpen("GET");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "Content-Length: 15\n");
|
| - SetResponseBody("01234567890123456789");
|
| - HandleAttr attr;
|
| - attr.offs = 10;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| - EXPECT_EQ(5, result_bytes);
|
| - EXPECT_STREQ("01234", &buf[0]);
|
| - ResetMocks();
|
| -
|
| - EXPECT_EQ(0, node_->GetSize(&result_size));
|
| - EXPECT_EQ(15, result_size);
|
| -}
|
| -
|
| -TEST_F(MountHttpNodeTest, DISABLED_ReadPartial) {
|
| int result_bytes = 0;
|
|
|
| - StringMap_t args;
|
| - args["cache_content"] = "false";
|
| - SetMountArgs(args);
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "");
|
| - OpenNode();
|
| - ResetMocks();
|
| -
|
| char buf[10];
|
| memset(&buf[0], 0, sizeof(buf));
|
|
|
| - ExpectOpen("GET");
|
| - ExpectHeaders("Range: bytes=0-8\n");
|
| - SetResponse(206, "Content-Length: 9\nContent-Range: bytes=0-8\n");
|
| - SetResponseBody("012345678");
|
| + ScopedMountNode node;
|
| + ASSERT_EQ(0, mnt_.Open(Path("/file"), O_RDONLY, &node));
|
| HandleAttr attr;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| + EXPECT_EQ(0, node->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| EXPECT_EQ(sizeof(buf) - 1, result_bytes);
|
| EXPECT_STREQ("012345678", &buf[0]);
|
| - ResetMocks();
|
|
|
| - // Another read is another request.
|
| - ExpectOpen("GET");
|
| - ExpectHeaders("Range: bytes=10-18\n");
|
| - SetResponse(206, "Content-Length: 9\nContent-Range: bytes=10-18\n");
|
| - SetResponseBody("abcdefghi");
|
| attr.offs = 10;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| + EXPECT_EQ(0, node->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| EXPECT_EQ(sizeof(buf) - 1, result_bytes);
|
| EXPECT_STREQ("abcdefghi", &buf[0]);
|
| }
|
| -
|
| -TEST_F(MountHttpNodeTest, DISABLED_ReadPartialNoServerSupport) {
|
| - int result_bytes = 0;
|
| -
|
| - StringMap_t args;
|
| - args["cache_content"] = "false";
|
| - SetMountArgs(args);
|
| - ExpectOpen("HEAD");
|
| - ExpectHeaders("");
|
| - SetResponse(200, "");
|
| - OpenNode();
|
| - ResetMocks();
|
| -
|
| - char buf[10];
|
| - memset(&buf[0], 0, sizeof(buf));
|
| -
|
| - ExpectOpen("GET");
|
| - ExpectHeaders("Range: bytes=10-18\n");
|
| - SetResponse(200, "Content-Length: 20\n");
|
| - SetResponseBody("0123456789abcdefghij");
|
| - HandleAttr attr;
|
| - attr.offs = 10;
|
| - EXPECT_EQ(0, node_->Read(attr, buf, sizeof(buf) - 1, &result_bytes));
|
| - EXPECT_EQ(sizeof(buf) - 1, result_bytes);
|
| - EXPECT_STREQ("abcdefghi", &buf[0]);
|
| -}
|
| -
|
|
|