| 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("foo.txt"), | 46 base::FilePath::FromUTF8Unsafe("/Downloads"), |
| 47 base::FilePath::FromUTF8Unsafe("/Downloads/foo.txt"), |
| 47 NULL, // No file types | 48 NULL, // No file types |
| 48 0, // Hence no file type index. | 49 0, // Hence no file type index. |
| 49 FILE_PATH_LITERAL("txt")); | 50 FILE_PATH_LITERAL("txt")); |
| 50 EXPECT_EQ("chrome-extension", url.scheme()); | 51 EXPECT_EQ("chrome-extension", url.scheme()); |
| 51 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); | 52 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); |
| 52 EXPECT_EQ("/main.html", url.path()); | 53 EXPECT_EQ("/main.html", url.path()); |
| 53 // Confirm that "%20" is used instead of "+" in the query. | 54 // Confirm that "%20" is used instead of "+" in the query. |
| 54 EXPECT_TRUE(url.query().find("+") == std::string::npos); | 55 EXPECT_TRUE(url.query().find("+") == std::string::npos); |
| 55 EXPECT_TRUE(url.query().find("%20") != std::string::npos); | 56 EXPECT_TRUE(url.query().find("%20") != std::string::npos); |
| 56 // The escaped query is hard to read. Pretty print the escaped JSON. | 57 // The escaped query is hard to read. Pretty print the escaped JSON. |
| 57 EXPECT_EQ("{\n" | 58 EXPECT_EQ("{\n" |
| 59 " \"currentDirectoryPath\": \"/Downloads\",\n" |
| 58 " \"defaultExtension\": \"txt\",\n" | 60 " \"defaultExtension\": \"txt\",\n" |
| 59 " \"defaultPath\": \"foo.txt\",\n" | 61 " \"selectionPath\": \"/Downloads/foo.txt\",\n" |
| 60 " \"shouldReturnLocalPath\": true,\n" | 62 " \"shouldReturnLocalPath\": true,\n" |
| 63 " \"targetName\": \"foo.txt\",\n" |
| 61 " \"title\": \"some title\",\n" | 64 " \"title\": \"some title\",\n" |
| 62 " \"type\": \"open-file\"\n" | 65 " \"type\": \"open-file\"\n" |
| 63 "}\n", | 66 "}\n", |
| 64 PrettyPrintEscapedJson(url.query())); | 67 PrettyPrintEscapedJson(url.query())); |
| 65 } | 68 } |
| 66 | 69 |
| 67 TEST(FileManagerUrlUtilTest, | 70 TEST(FileManagerUrlUtilTest, |
| 68 GetFileManagerMainPageUrlWithParams_WithFileTypes) { | 71 GetFileManagerMainPageUrlWithParams_WithFileTypes) { |
| 69 // Create a FileTypeInfo which looks like: | 72 // Create a FileTypeInfo which looks like: |
| 70 // extensions: [["htm", "html"], ["txt"]] | 73 // extensions: [["htm", "html"], ["txt"]] |
| 71 // descriptions: ["HTML", "TEXT"] | 74 // descriptions: ["HTML", "TEXT"] |
| 72 ui::SelectFileDialog::FileTypeInfo file_types; | 75 ui::SelectFileDialog::FileTypeInfo file_types; |
| 73 file_types.extensions.push_back(std::vector<base::FilePath::StringType>()); | 76 file_types.extensions.push_back(std::vector<base::FilePath::StringType>()); |
| 74 file_types.extensions[0].push_back(FILE_PATH_LITERAL("htm")); | 77 file_types.extensions[0].push_back(FILE_PATH_LITERAL("htm")); |
| 75 file_types.extensions[0].push_back(FILE_PATH_LITERAL("html")); | 78 file_types.extensions[0].push_back(FILE_PATH_LITERAL("html")); |
| 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[1].push_back(FILE_PATH_LITERAL("txt")); | 80 file_types.extensions[1].push_back(FILE_PATH_LITERAL("txt")); |
| 78 file_types.extension_description_overrides.push_back( | 81 file_types.extension_description_overrides.push_back( |
| 79 base::UTF8ToUTF16("HTML")); | 82 base::UTF8ToUTF16("HTML")); |
| 80 file_types.extension_description_overrides.push_back( | 83 file_types.extension_description_overrides.push_back( |
| 81 base::UTF8ToUTF16("TEXT")); | 84 base::UTF8ToUTF16("TEXT")); |
| 82 // "shouldReturnLocalPath" will be false if drive is supported. | 85 // "shouldReturnLocalPath" will be false if drive is supported. |
| 83 file_types.support_drive = true; | 86 file_types.support_drive = true; |
| 84 | 87 |
| 85 const GURL url = GetFileManagerMainPageUrlWithParams( | 88 const GURL url = GetFileManagerMainPageUrlWithParams( |
| 86 ui::SelectFileDialog::SELECT_OPEN_FILE, | 89 ui::SelectFileDialog::SELECT_OPEN_FILE, |
| 87 base::UTF8ToUTF16("some title"), | 90 base::UTF8ToUTF16("some title"), |
| 88 base::FilePath::FromUTF8Unsafe("foo.txt"), | 91 base::FilePath::FromUTF8Unsafe("/Downloads"), |
| 92 base::FilePath::FromUTF8Unsafe("/Downloads/foo.txt"), |
| 89 &file_types, | 93 &file_types, |
| 90 1, // The file type index is 1-based. | 94 1, // The file type index is 1-based. |
| 91 FILE_PATH_LITERAL("txt")); | 95 FILE_PATH_LITERAL("txt")); |
| 92 EXPECT_EQ("chrome-extension", url.scheme()); | 96 EXPECT_EQ("chrome-extension", url.scheme()); |
| 93 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); | 97 EXPECT_EQ("hhaomjibdihmijegdhdafkllkbggdgoj", url.host()); |
| 94 EXPECT_EQ("/main.html", url.path()); | 98 EXPECT_EQ("/main.html", url.path()); |
| 95 // Confirm that "%20" is used instead of "+" in the query. | 99 // Confirm that "%20" is used instead of "+" in the query. |
| 96 EXPECT_TRUE(url.query().find("+") == std::string::npos); | 100 EXPECT_TRUE(url.query().find("+") == std::string::npos); |
| 97 EXPECT_TRUE(url.query().find("%20") != std::string::npos); | 101 EXPECT_TRUE(url.query().find("%20") != std::string::npos); |
| 98 // The escaped query is hard to read. Pretty print the escaped JSON. | 102 // The escaped query is hard to read. Pretty print the escaped JSON. |
| 99 EXPECT_EQ("{\n" | 103 EXPECT_EQ("{\n" |
| 104 " \"currentDirectoryPath\": \"/Downloads\",\n" |
| 100 " \"defaultExtension\": \"txt\",\n" | 105 " \"defaultExtension\": \"txt\",\n" |
| 101 " \"defaultPath\": \"foo.txt\",\n" | |
| 102 " \"includeAllFiles\": false,\n" | 106 " \"includeAllFiles\": false,\n" |
| 107 " \"selectionPath\": \"/Downloads/foo.txt\",\n" |
| 103 " \"shouldReturnLocalPath\": false,\n" | 108 " \"shouldReturnLocalPath\": false,\n" |
| 109 " \"targetName\": \"foo.txt\",\n" |
| 104 " \"title\": \"some title\",\n" | 110 " \"title\": \"some title\",\n" |
| 105 " \"type\": \"open-file\",\n" | 111 " \"type\": \"open-file\",\n" |
| 106 " \"typeList\": [ {\n" | 112 " \"typeList\": [ {\n" |
| 107 " \"description\": \"HTML\",\n" | 113 " \"description\": \"HTML\",\n" |
| 108 " \"extensions\": [ \"htm\", \"html\" ],\n" | 114 " \"extensions\": [ \"htm\", \"html\" ],\n" |
| 109 " \"selected\": true\n" | 115 " \"selected\": true\n" |
| 110 " }, {\n" | 116 " }, {\n" |
| 111 " \"description\": \"TEXT\",\n" | 117 " \"description\": \"TEXT\",\n" |
| 112 " \"extensions\": [ \"txt\" ],\n" | 118 " \"extensions\": [ \"txt\" ],\n" |
| 113 " \"selected\": false\n" | 119 " \"selected\": false\n" |
| 114 " } ]\n" | 120 " } ]\n" |
| 115 "}\n", | 121 "}\n", |
| 116 PrettyPrintEscapedJson(url.query())); | 122 PrettyPrintEscapedJson(url.query())); |
| 117 } | 123 } |
| 118 | 124 |
| 119 } // namespace | 125 } // namespace |
| 120 } // namespace util | 126 } // namespace util |
| 121 } // namespace file_manager | 127 } // namespace file_manager |
| OLD | NEW |