| Index: chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document_unittest.cc
|
| diff --git a/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document_unittest.cc b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..61a51f08cd9dfd4d8239f38915b266f126cef115
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document_unittest.cc
|
| @@ -0,0 +1,216 @@
|
| +// 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.
|
| +
|
| +#include <string>
|
| +#include <vector>
|
| +
|
| +#include "base/files/file_path.h"
|
| +#include "base/macros.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_document.h"
|
| +#include "chrome/browser/chromeos/arc/fileapi/arc_documents_provider_util.h"
|
| +#include "components/arc/common/file_system.mojom.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace arc {
|
| +
|
| +namespace {
|
| +
|
| +class ArcDocumentsProviderDocumentTest : public testing::Test {
|
| + public:
|
| + ArcDocumentsProviderDocumentTest() = default;
|
| + ~ArcDocumentsProviderDocumentTest() override = default;
|
| +
|
| + void SetUp() override {
|
| + root_directory_.reset(new ArcDocumentsProviderDocument("root", true));
|
| + EXPECT_EQ("root", root_directory_->document_id());
|
| + EXPECT_TRUE(root_directory_->is_directory());
|
| + }
|
| +
|
| + protected:
|
| + std::unique_ptr<ArcDocumentsProviderDocument> root_directory_;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(ArcDocumentsProviderDocumentTest);
|
| +};
|
| +
|
| +mojom::DocumentPtr MakeDocument(const std::string& document_id,
|
| + const std::string& display_name,
|
| + std::string mime_type) {
|
| + mojom::DocumentPtr document = mojom::Document::New();
|
| + document->document_id = document_id;
|
| + document->display_name = display_name;
|
| + document->mime_type = mime_type;
|
| + return document;
|
| +}
|
| +
|
| +std::string DocumentTreeToDebugString(ArcDocumentsProviderDocument* document,
|
| + int indent_level = 0) {
|
| + const std::string indent(indent_level, ' ');
|
| + std::string text =
|
| + base::StringPrintf("(id=%s, dir=%s)\n", document->document_id().c_str(),
|
| + document->is_directory() ? "true" : "false");
|
| + if (document->is_directory()) {
|
| + for (const auto& pair : document->children()) {
|
| + text += base::StringPrintf(
|
| + "%s- %s %s", indent.c_str(), pair.first.c_str(),
|
| + DocumentTreeToDebugString(pair.second.get(), indent_level + 2)
|
| + .c_str());
|
| + }
|
| + }
|
| + return text;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +TEST_F(ArcDocumentsProviderDocumentTest, Basic) {
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(
|
| + MakeDocument("pet-id", "pet", kAndroidDirectoryMimeType));
|
| + root_directory_->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- pet (id=pet-id, dir=true)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +
|
| + ArcDocumentsProviderDocument* pet =
|
| + root_directory_->Lookup(base::FilePath(FILE_PATH_LITERAL("pet")));
|
| + ASSERT_TRUE(pet);
|
| +
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(MakeDocument("cat-id", "cat.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("dog-id", "dog.mp3", "audio/mp3"));
|
| + pet->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- pet (id=pet-id, dir=true)\n"
|
| + " - cat.jpg (id=cat-id, dir=false)\n"
|
| + " - dog.mp3 (id=dog-id, dir=false)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +
|
| + EXPECT_TRUE(root_directory_->Lookup(
|
| + base::FilePath(FILE_PATH_LITERAL("pet/cat.jpg"))));
|
| + EXPECT_TRUE(root_directory_->Lookup(
|
| + base::FilePath(FILE_PATH_LITERAL("pet/dog.mp3"))));
|
| +}
|
| +
|
| +TEST_F(ArcDocumentsProviderDocumentTest, ReplaceSlash) {
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(MakeDocument("test", "\\^o^/.jpg", "image/jpeg"));
|
| + root_directory_->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- \\^o^_.jpg (id=test, dir=false)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +}
|
| +
|
| +TEST_F(ArcDocumentsProviderDocumentTest, ReplaceDots) {
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(
|
| + MakeDocument("dot1", ".", kAndroidDirectoryMimeType));
|
| + documents.emplace_back(
|
| + MakeDocument("dot2", "..", kAndroidDirectoryMimeType));
|
| + root_directory_->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- dot (id=dot1, dir=true)\n"
|
| + "- dotdot (id=dot2, dir=true)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +}
|
| +
|
| +TEST_F(ArcDocumentsProviderDocumentTest, AppendExtension) {
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(MakeDocument("cow", "cow.bin", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("rat", "rat.bin", "image/x-unknown"));
|
| + root_directory_->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- cow.bin.jpg (id=cow, dir=false)\n"
|
| + "- rat.bin (id=rat, dir=false)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +}
|
| +
|
| +TEST_F(ArcDocumentsProviderDocumentTest, DuplicatedNames) {
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(MakeDocument("fox1", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox2", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox3", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox4", "fox 2.jpg", "image/jpeg"));
|
| + root_directory_->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- fox 1.jpg (id=fox2, dir=false)\n"
|
| + "- fox 2.jpg (id=fox4, dir=false)\n"
|
| + "- fox 3.jpg (id=fox3, dir=false)\n"
|
| + "- fox.jpg (id=fox1, dir=false)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +}
|
| +
|
| +TEST_F(ArcDocumentsProviderDocumentTest, KeepMapping) {
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(MakeDocument("fox1", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox2", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox3", "fox.jpg", "image/jpeg"));
|
| + root_directory_->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- fox 1.jpg (id=fox2, dir=false)\n"
|
| + "- fox 2.jpg (id=fox3, dir=false)\n"
|
| + "- fox.jpg (id=fox1, dir=false)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(MakeDocument("fox2", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox3", "fox.jpg", "image/jpeg"));
|
| + root_directory_->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- fox 1.jpg (id=fox2, dir=false)\n"
|
| + "- fox 2.jpg (id=fox3, dir=false)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +
|
| + {
|
| + std::vector<mojom::DocumentPtr> documents;
|
| + documents.emplace_back(MakeDocument("fox2", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox3", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox4", "fox.jpg", "image/jpeg"));
|
| + documents.emplace_back(MakeDocument("fox5", "fox.jpg", "image/jpeg"));
|
| + root_directory_->UpdateWithChildDocuments(documents);
|
| + }
|
| +
|
| + EXPECT_EQ(
|
| + "(id=root, dir=true)\n"
|
| + "- fox 1.jpg (id=fox2, dir=false)\n"
|
| + "- fox 2.jpg (id=fox3, dir=false)\n"
|
| + "- fox 3.jpg (id=fox5, dir=false)\n"
|
| + "- fox.jpg (id=fox4, dir=false)\n",
|
| + DocumentTreeToDebugString(root_directory_.get()));
|
| +}
|
| +
|
| +} // namespace arc
|
|
|