| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 NULL, // No file types | 43 NULL, // No file types |
| 44 0, // Hence no file type index. | 44 0, // Hence no file type index. |
| 45 FILE_PATH_LITERAL("txt")); | 45 FILE_PATH_LITERAL("txt")); |
| 46 EXPECT_EQ("chrome-extension", url.scheme()); | 46 EXPECT_EQ("chrome-extension", url.scheme()); |
| 47 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); | 47 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); |
| 48 EXPECT_EQ("/main.html", url.path()); | 48 EXPECT_EQ("/main.html", url.path()); |
| 49 // Confirm that "%20" is used instead of "+" in the query. | 49 // Confirm that "%20" is used instead of "+" in the query. |
| 50 EXPECT_TRUE(url.query().find("+") == std::string::npos); | 50 EXPECT_TRUE(url.query().find("+") == std::string::npos); |
| 51 EXPECT_TRUE(url.query().find("%20") != std::string::npos); | 51 EXPECT_TRUE(url.query().find("%20") != std::string::npos); |
| 52 // The escaped query is hard to read. Pretty print the escaped JSON. | 52 // The escaped query is hard to read. Pretty print the escaped JSON. |
| 53 EXPECT_EQ("{\n" | 53 EXPECT_EQ( |
| 54 " \"currentDirectoryURL\": " | 54 "{\n" |
| 55 "\"filesystem:chrome-extension://abc/Downloads/\",\n" | 55 " \"allowedPaths\": \"nativePath\",\n" |
| 56 " \"defaultExtension\": \"txt\",\n" | 56 " \"currentDirectoryURL\": " |
| 57 " \"selectionURL\": " | 57 "\"filesystem:chrome-extension://abc/Downloads/\",\n" |
| 58 "\"filesystem:chrome-extension://abc/Downloads/foo.txt\",\n" | 58 " \"defaultExtension\": \"txt\",\n" |
| 59 " \"shouldReturnLocalPath\": true,\n" | 59 " \"selectionURL\": " |
| 60 " \"targetName\": \"foo.txt\",\n" | 60 "\"filesystem:chrome-extension://abc/Downloads/foo.txt\",\n" |
| 61 " \"title\": \"some title\",\n" | 61 " \"targetName\": \"foo.txt\",\n" |
| 62 " \"type\": \"open-file\"\n" | 62 " \"title\": \"some title\",\n" |
| 63 "}\n", | 63 " \"type\": \"open-file\"\n" |
| 64 PrettyPrintEscapedJson(url.query())); | 64 "}\n", |
| 65 PrettyPrintEscapedJson(url.query())); |
| 65 } | 66 } |
| 66 | 67 |
| 67 TEST(FileManagerUrlUtilTest, | 68 TEST(FileManagerUrlUtilTest, |
| 68 GetFileManagerMainPageUrlWithParams_WithFileTypes) { | 69 GetFileManagerMainPageUrlWithParams_WithFileTypes) { |
| 69 // Create a FileTypeInfo which looks like: | 70 // Create a FileTypeInfo which looks like: |
| 70 // extensions: [["htm", "html"], ["txt"]] | 71 // extensions: [["htm", "html"], ["txt"]] |
| 71 // descriptions: ["HTML", "TEXT"] | 72 // descriptions: ["HTML", "TEXT"] |
| 72 ui::SelectFileDialog::FileTypeInfo file_types; | 73 ui::SelectFileDialog::FileTypeInfo file_types; |
| 73 file_types.extensions.push_back(std::vector<base::FilePath::StringType>()); | 74 file_types.extensions.push_back(std::vector<base::FilePath::StringType>()); |
| 74 file_types.extensions[0].push_back(FILE_PATH_LITERAL("htm")); | 75 file_types.extensions[0].push_back(FILE_PATH_LITERAL("htm")); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 91 &file_types, | 92 &file_types, |
| 92 1, // The file type index is 1-based. | 93 1, // The file type index is 1-based. |
| 93 FILE_PATH_LITERAL("txt")); | 94 FILE_PATH_LITERAL("txt")); |
| 94 EXPECT_EQ("chrome-extension", url.scheme()); | 95 EXPECT_EQ("chrome-extension", url.scheme()); |
| 95 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); | 96 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); |
| 96 EXPECT_EQ("/main.html", url.path()); | 97 EXPECT_EQ("/main.html", url.path()); |
| 97 // Confirm that "%20" is used instead of "+" in the query. | 98 // Confirm that "%20" is used instead of "+" in the query. |
| 98 EXPECT_TRUE(url.query().find("+") == std::string::npos); | 99 EXPECT_TRUE(url.query().find("+") == std::string::npos); |
| 99 EXPECT_TRUE(url.query().find("%20") != std::string::npos); | 100 EXPECT_TRUE(url.query().find("%20") != std::string::npos); |
| 100 // The escaped query is hard to read. Pretty print the escaped JSON. | 101 // The escaped query is hard to read. Pretty print the escaped JSON. |
| 101 EXPECT_EQ("{\n" | 102 EXPECT_EQ( |
| 102 " \"currentDirectoryURL\": " | 103 "{\n" |
| 103 "\"filesystem:chrome-extension://abc/Downloads/\",\n" | 104 " \"allowedPaths\": \"anyPath\",\n" |
| 104 " \"defaultExtension\": \"txt\",\n" | 105 " \"currentDirectoryURL\": " |
| 105 " \"includeAllFiles\": false,\n" | 106 "\"filesystem:chrome-extension://abc/Downloads/\",\n" |
| 106 " \"selectionURL\": " | 107 " \"defaultExtension\": \"txt\",\n" |
| 107 "\"filesystem:chrome-extension://abc/Downloads/foo.txt\",\n" | 108 " \"includeAllFiles\": false,\n" |
| 108 " \"shouldReturnLocalPath\": false,\n" | 109 " \"selectionURL\": " |
| 109 " \"targetName\": \"foo.txt\",\n" | 110 "\"filesystem:chrome-extension://abc/Downloads/foo.txt\",\n" |
| 110 " \"title\": \"some title\",\n" | 111 " \"targetName\": \"foo.txt\",\n" |
| 111 " \"type\": \"open-file\",\n" | 112 " \"title\": \"some title\",\n" |
| 112 " \"typeList\": [ {\n" | 113 " \"type\": \"open-file\",\n" |
| 113 " \"description\": \"HTML\",\n" | 114 " \"typeList\": [ {\n" |
| 114 " \"extensions\": [ \"htm\", \"html\" ],\n" | 115 " \"description\": \"HTML\",\n" |
| 115 " \"selected\": true\n" | 116 " \"extensions\": [ \"htm\", \"html\" ],\n" |
| 116 " }, {\n" | 117 " \"selected\": true\n" |
| 117 " \"description\": \"TEXT\",\n" | 118 " }, {\n" |
| 118 " \"extensions\": [ \"txt\" ],\n" | 119 " \"description\": \"TEXT\",\n" |
| 119 " \"selected\": false\n" | 120 " \"extensions\": [ \"txt\" ],\n" |
| 120 " } ]\n" | 121 " \"selected\": false\n" |
| 121 "}\n", | 122 " } ]\n" |
| 122 PrettyPrintEscapedJson(url.query())); | 123 "}\n", |
| 124 PrettyPrintEscapedJson(url.query())); |
| 123 } | 125 } |
| 124 | 126 |
| 125 } // namespace | 127 } // namespace |
| 126 } // namespace util | 128 } // namespace util |
| 127 } // namespace file_manager | 129 } // namespace file_manager |
| OLD | NEW |