| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/file_manager/url_util.h" | 5 #include "chrome/browser/chromeos/file_manager/url_util.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 TEST(FileManagerUrlUtilTest, GetFileManagerMainPageUrl) { | 37 TEST(FileManagerUrlUtilTest, GetFileManagerMainPageUrl) { |
| 38 EXPECT_EQ("chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html", | 38 EXPECT_EQ("chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/main.html", |
| 39 GetFileManagerMainPageUrl().spec()); | 39 GetFileManagerMainPageUrl().spec()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 TEST(FileManagerUrlUtilTest, GetFileManagerMainPageUrlWithParams_NoFileTypes) { | 42 TEST(FileManagerUrlUtilTest, GetFileManagerMainPageUrlWithParams_NoFileTypes) { |
| 43 const GURL url = GetFileManagerMainPageUrlWithParams( | 43 const GURL url = GetFileManagerMainPageUrlWithParams( |
| 44 ui::SelectFileDialog::SELECT_OPEN_FILE, | 44 ui::SelectFileDialog::SELECT_OPEN_FILE, |
| 45 base::UTF8ToUTF16("some title"), | 45 base::UTF8ToUTF16("some title"), |
| 46 base::FilePath::FromUTF8Unsafe("/Downloads"), | 46 GURL("filesystem:chrome-extension://abc/Downloads/"), |
| 47 base::FilePath::FromUTF8Unsafe("/Downloads/foo.txt"), | 47 GURL("filesystem:chrome-extension://abc/Downloads/foo.txt"), |
| 48 "foo.txt", |
| 48 NULL, // No file types | 49 NULL, // No file types |
| 49 0, // Hence no file type index. | 50 0, // Hence no file type index. |
| 50 FILE_PATH_LITERAL("txt")); | 51 FILE_PATH_LITERAL("txt")); |
| 51 EXPECT_EQ("chrome-extension", url.scheme()); | 52 EXPECT_EQ("chrome-extension", url.scheme()); |
| 52 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); | 53 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); |
| 53 EXPECT_EQ("/main.html", url.path()); | 54 EXPECT_EQ("/main.html", url.path()); |
| 54 // Confirm that "%20" is used instead of "+" in the query. | 55 // Confirm that "%20" is used instead of "+" in the query. |
| 55 EXPECT_TRUE(url.query().find("+") == std::string::npos); | 56 EXPECT_TRUE(url.query().find("+") == std::string::npos); |
| 56 EXPECT_TRUE(url.query().find("%20") != std::string::npos); | 57 EXPECT_TRUE(url.query().find("%20") != std::string::npos); |
| 57 // The escaped query is hard to read. Pretty print the escaped JSON. | 58 // The escaped query is hard to read. Pretty print the escaped JSON. |
| 58 EXPECT_EQ("{\n" | 59 EXPECT_EQ("{\n" |
| 59 " \"currentDirectoryPath\": \"/Downloads\",\n" | 60 " \"currentDirectoryURL\": " |
| 61 "\"filesystem:chrome-extension://abc/Downloads/\",\n" |
| 60 " \"defaultExtension\": \"txt\",\n" | 62 " \"defaultExtension\": \"txt\",\n" |
| 61 " \"selectionPath\": \"/Downloads/foo.txt\",\n" | 63 " \"selectionURL\": " |
| 64 "\"filesystem:chrome-extension://abc/Downloads/foo.txt\",\n" |
| 62 " \"shouldReturnLocalPath\": true,\n" | 65 " \"shouldReturnLocalPath\": true,\n" |
| 63 " \"targetName\": \"foo.txt\",\n" | 66 " \"targetName\": \"foo.txt\",\n" |
| 64 " \"title\": \"some title\",\n" | 67 " \"title\": \"some title\",\n" |
| 65 " \"type\": \"open-file\"\n" | 68 " \"type\": \"open-file\"\n" |
| 66 "}\n", | 69 "}\n", |
| 67 PrettyPrintEscapedJson(url.query())); | 70 PrettyPrintEscapedJson(url.query())); |
| 68 } | 71 } |
| 69 | 72 |
| 70 TEST(FileManagerUrlUtilTest, | 73 TEST(FileManagerUrlUtilTest, |
| 71 GetFileManagerMainPageUrlWithParams_WithFileTypes) { | 74 GetFileManagerMainPageUrlWithParams_WithFileTypes) { |
| 72 // Create a FileTypeInfo which looks like: | 75 // Create a FileTypeInfo which looks like: |
| 73 // extensions: [["htm", "html"], ["txt"]] | 76 // extensions: [["htm", "html"], ["txt"]] |
| 74 // descriptions: ["HTML", "TEXT"] | 77 // descriptions: ["HTML", "TEXT"] |
| 75 ui::SelectFileDialog::FileTypeInfo file_types; | 78 ui::SelectFileDialog::FileTypeInfo file_types; |
| 76 file_types.extensions.push_back(std::vector<base::FilePath::StringType>()); | 79 file_types.extensions.push_back(std::vector<base::FilePath::StringType>()); |
| 77 file_types.extensions[0].push_back(FILE_PATH_LITERAL("htm")); | 80 file_types.extensions[0].push_back(FILE_PATH_LITERAL("htm")); |
| 78 file_types.extensions[0].push_back(FILE_PATH_LITERAL("html")); | 81 file_types.extensions[0].push_back(FILE_PATH_LITERAL("html")); |
| 79 file_types.extensions.push_back(std::vector<base::FilePath::StringType>()); | 82 file_types.extensions.push_back(std::vector<base::FilePath::StringType>()); |
| 80 file_types.extensions[1].push_back(FILE_PATH_LITERAL("txt")); | 83 file_types.extensions[1].push_back(FILE_PATH_LITERAL("txt")); |
| 81 file_types.extension_description_overrides.push_back( | 84 file_types.extension_description_overrides.push_back( |
| 82 base::UTF8ToUTF16("HTML")); | 85 base::UTF8ToUTF16("HTML")); |
| 83 file_types.extension_description_overrides.push_back( | 86 file_types.extension_description_overrides.push_back( |
| 84 base::UTF8ToUTF16("TEXT")); | 87 base::UTF8ToUTF16("TEXT")); |
| 85 // "shouldReturnLocalPath" will be false if drive is supported. | 88 // "shouldReturnLocalPath" will be false if drive is supported. |
| 86 file_types.support_drive = true; | 89 file_types.support_drive = true; |
| 87 | 90 |
| 88 const GURL url = GetFileManagerMainPageUrlWithParams( | 91 const GURL url = GetFileManagerMainPageUrlWithParams( |
| 89 ui::SelectFileDialog::SELECT_OPEN_FILE, | 92 ui::SelectFileDialog::SELECT_OPEN_FILE, |
| 90 base::UTF8ToUTF16("some title"), | 93 base::UTF8ToUTF16("some title"), |
| 91 base::FilePath::FromUTF8Unsafe("/Downloads"), | 94 GURL("filesystem:chrome-extension://abc/Downloads/"), |
| 92 base::FilePath::FromUTF8Unsafe("/Downloads/foo.txt"), | 95 GURL("filesystem:chrome-extension://abc/Downloads/foo.txt"), |
| 96 "foo.txt", |
| 93 &file_types, | 97 &file_types, |
| 94 1, // The file type index is 1-based. | 98 1, // The file type index is 1-based. |
| 95 FILE_PATH_LITERAL("txt")); | 99 FILE_PATH_LITERAL("txt")); |
| 96 EXPECT_EQ("chrome-extension", url.scheme()); | 100 EXPECT_EQ("chrome-extension", url.scheme()); |
| 97 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); | 101 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); |
| 98 EXPECT_EQ("/main.html", url.path()); | 102 EXPECT_EQ("/main.html", url.path()); |
| 99 // Confirm that "%20" is used instead of "+" in the query. | 103 // Confirm that "%20" is used instead of "+" in the query. |
| 100 EXPECT_TRUE(url.query().find("+") == std::string::npos); | 104 EXPECT_TRUE(url.query().find("+") == std::string::npos); |
| 101 EXPECT_TRUE(url.query().find("%20") != std::string::npos); | 105 EXPECT_TRUE(url.query().find("%20") != std::string::npos); |
| 102 // The escaped query is hard to read. Pretty print the escaped JSON. | 106 // The escaped query is hard to read. Pretty print the escaped JSON. |
| 103 EXPECT_EQ("{\n" | 107 EXPECT_EQ("{\n" |
| 104 " \"currentDirectoryPath\": \"/Downloads\",\n" | 108 " \"currentDirectoryURL\": " |
| 109 "\"filesystem:chrome-extension://abc/Downloads/\",\n" |
| 105 " \"defaultExtension\": \"txt\",\n" | 110 " \"defaultExtension\": \"txt\",\n" |
| 106 " \"includeAllFiles\": false,\n" | 111 " \"includeAllFiles\": false,\n" |
| 107 " \"selectionPath\": \"/Downloads/foo.txt\",\n" | 112 " \"selectionURL\": " |
| 113 "\"filesystem:chrome-extension://abc/Downloads/foo.txt\",\n" |
| 108 " \"shouldReturnLocalPath\": false,\n" | 114 " \"shouldReturnLocalPath\": false,\n" |
| 109 " \"targetName\": \"foo.txt\",\n" | 115 " \"targetName\": \"foo.txt\",\n" |
| 110 " \"title\": \"some title\",\n" | 116 " \"title\": \"some title\",\n" |
| 111 " \"type\": \"open-file\",\n" | 117 " \"type\": \"open-file\",\n" |
| 112 " \"typeList\": [ {\n" | 118 " \"typeList\": [ {\n" |
| 113 " \"description\": \"HTML\",\n" | 119 " \"description\": \"HTML\",\n" |
| 114 " \"extensions\": [ \"htm\", \"html\" ],\n" | 120 " \"extensions\": [ \"htm\", \"html\" ],\n" |
| 115 " \"selected\": true\n" | 121 " \"selected\": true\n" |
| 116 " }, {\n" | 122 " }, {\n" |
| 117 " \"description\": \"TEXT\",\n" | 123 " \"description\": \"TEXT\",\n" |
| 118 " \"extensions\": [ \"txt\" ],\n" | 124 " \"extensions\": [ \"txt\" ],\n" |
| 119 " \"selected\": false\n" | 125 " \"selected\": false\n" |
| 120 " } ]\n" | 126 " } ]\n" |
| 121 "}\n", | 127 "}\n", |
| 122 PrettyPrintEscapedJson(url.query())); | 128 PrettyPrintEscapedJson(url.query())); |
| 123 } | 129 } |
| 124 | 130 |
| 125 } // namespace | 131 } // namespace |
| 126 } // namespace util | 132 } // namespace util |
| 127 } // namespace file_manager | 133 } // namespace file_manager |
| OLD | NEW |