This source file includes following definitions.
- PrettyPrintEscapedJson
- TEST
- TEST
- TEST
- TEST
#include "chrome/browser/chromeos/file_manager/url_util.h"
#include "base/files/file_path.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "net/base/escape.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace file_manager {
namespace util {
namespace {
std::string PrettyPrintEscapedJson(const std::string& query) {
const std::string json = net::UnescapeURLComponent(
query, net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
scoped_ptr<base::Value> value(base::JSONReader::Read(json));
std::string pretty_json;
base::JSONWriter::WriteWithOptions(value.get(),
base::JSONWriter::OPTIONS_PRETTY_PRINT,
&pretty_json);
return pretty_json;
}
TEST(FileManagerUrlUtilTest, GetFileManagerBaseUrl) {
EXPECT_EQ("chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/",
GetFileManagerBaseUrl().spec());
}
TEST(FileManagerUrlUtilTest, GetFileManagerMainPageUrl) {
EXPECT_EQ("chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html",
GetFileManagerMainPageUrl().spec());
}
TEST(FileManagerUrlUtilTest, GetFileManagerMainPageUrlWithParams_NoFileTypes) {
const GURL url = GetFileManagerMainPageUrlWithParams(
ui::SelectFileDialog::SELECT_OPEN_FILE,
base::UTF8ToUTF16("some title"),
GURL("filesystem:chrome-extension://abc/Downloads/"),
GURL("filesystem:chrome-extension://abc/Downloads/foo.txt"),
"foo.txt",
NULL,
0,
FILE_PATH_LITERAL("txt"));
EXPECT_EQ("chrome-extension", url.scheme());
EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host());
EXPECT_EQ("/main.html", url.path());
EXPECT_TRUE(url.query().find("+") == std::string::npos);
EXPECT_TRUE(url.query().find("%20") != std::string::npos);
EXPECT_EQ("{\n"
" \"currentDirectoryURL\": "
"\"filesystem:chrome-extension://abc/Downloads/\",\n"
" \"defaultExtension\": \"txt\",\n"
" \"selectionURL\": "
"\"filesystem:chrome-extension://abc/Downloads/foo.txt\",\n"
" \"shouldReturnLocalPath\": true,\n"
" \"targetName\": \"foo.txt\",\n"
" \"title\": \"some title\",\n"
" \"type\": \"open-file\"\n"
"}\n",
PrettyPrintEscapedJson(url.query()));
}
TEST(FileManagerUrlUtilTest,
GetFileManagerMainPageUrlWithParams_WithFileTypes) {
ui::SelectFileDialog::FileTypeInfo file_types;
file_types.extensions.push_back(std::vector<base::FilePath::StringType>());
file_types.extensions[0].push_back(FILE_PATH_LITERAL("htm"));
file_types.extensions[0].push_back(FILE_PATH_LITERAL("html"));
file_types.extensions.push_back(std::vector<base::FilePath::StringType>());
file_types.extensions[1].push_back(FILE_PATH_LITERAL("txt"));
file_types.extension_description_overrides.push_back(
base::UTF8ToUTF16("HTML"));
file_types.extension_description_overrides.push_back(
base::UTF8ToUTF16("TEXT"));
file_types.support_drive = true;
const GURL url = GetFileManagerMainPageUrlWithParams(
ui::SelectFileDialog::SELECT_OPEN_FILE,
base::UTF8ToUTF16("some title"),
GURL("filesystem:chrome-extension://abc/Downloads/"),
GURL("filesystem:chrome-extension://abc/Downloads/foo.txt"),
"foo.txt",
&file_types,
1,
FILE_PATH_LITERAL("txt"));
EXPECT_EQ("chrome-extension", url.scheme());
EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host());
EXPECT_EQ("/main.html", url.path());
EXPECT_TRUE(url.query().find("+") == std::string::npos);
EXPECT_TRUE(url.query().find("%20") != std::string::npos);
EXPECT_EQ("{\n"
" \"currentDirectoryURL\": "
"\"filesystem:chrome-extension://abc/Downloads/\",\n"
" \"defaultExtension\": \"txt\",\n"
" \"includeAllFiles\": false,\n"
" \"selectionURL\": "
"\"filesystem:chrome-extension://abc/Downloads/foo.txt\",\n"
" \"shouldReturnLocalPath\": false,\n"
" \"targetName\": \"foo.txt\",\n"
" \"title\": \"some title\",\n"
" \"type\": \"open-file\",\n"
" \"typeList\": [ {\n"
" \"description\": \"HTML\",\n"
" \"extensions\": [ \"htm\", \"html\" ],\n"
" \"selected\": true\n"
" }, {\n"
" \"description\": \"TEXT\",\n"
" \"extensions\": [ \"txt\" ],\n"
" \"selected\": false\n"
" } ]\n"
"}\n",
PrettyPrintEscapedJson(url.query()));
}
}
}
}