Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: extensions/common/file_util_unittest.cc

Issue 2574763003: Remove chrome-extension-resource:// scheme (Closed)
Patch Set: Remove BUILD reference to resources/extension outdir. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/common/file_util.cc ('k') | extensions/renderer/dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "extensions/common/file_util.h" 5 #include "extensions/common/file_util.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 base::FilePath::FromUTF8Unsafe(test_cases[i].expected_relative_path); 476 base::FilePath::FromUTF8Unsafe(test_cases[i].expected_relative_path);
477 base::FilePath actual_path = 477 base::FilePath actual_path =
478 extensions::file_util::ExtensionURLToRelativeFilePath(url); 478 extensions::file_util::ExtensionURLToRelativeFilePath(url);
479 EXPECT_FALSE(actual_path.IsAbsolute()) << 479 EXPECT_FALSE(actual_path.IsAbsolute()) <<
480 " For the path " << actual_path.value(); 480 " For the path " << actual_path.value();
481 EXPECT_EQ(expected_path.value(), actual_path.value()) << 481 EXPECT_EQ(expected_path.value(), actual_path.value()) <<
482 " For the path " << url; 482 " For the path " << url;
483 } 483 }
484 } 484 }
485 485
486 TEST_F(FileUtilTest, ExtensionResourceURLToFilePath) {
487 // Setup filesystem for testing.
488 base::FilePath root_path;
489 ASSERT_TRUE(base::CreateNewTempDirectory(
490 base::FilePath::StringType(), &root_path));
491 root_path = base::MakeAbsoluteFilePath(root_path);
492 ASSERT_FALSE(root_path.empty());
493
494 base::FilePath api_path = root_path.Append(FILE_PATH_LITERAL("apiname"));
495 ASSERT_TRUE(base::CreateDirectory(api_path));
496
497 const char data[] = "Test Data";
498 base::FilePath resource_path = api_path.Append(FILE_PATH_LITERAL("test.js"));
499 ASSERT_TRUE(base::WriteFile(resource_path, data, sizeof(data)));
500 resource_path = api_path.Append(FILE_PATH_LITERAL("escape spaces.js"));
501 ASSERT_TRUE(base::WriteFile(resource_path, data, sizeof(data)));
502 resource_path = api_path.Append(FILE_PATH_LITERAL("escape spaces.js"));
503 ASSERT_TRUE(base::WriteFile(resource_path, data, sizeof(data)));
504 resource_path = api_path.Append(FILE_PATH_LITERAL("..%2f..%2fsimple.html"));
505 ASSERT_TRUE(base::WriteFile(resource_path, data, sizeof(data)));
506
507 #ifdef FILE_PATH_USES_WIN_SEPARATORS
508 #define SEP "\\"
509 #else
510 #define SEP "/"
511 #endif
512 #define URL_PREFIX "chrome-extension-resource://"
513 struct TestCase {
514 const char* url;
515 const base::FilePath::CharType* expected_path;
516 } test_cases[] = {
517 {URL_PREFIX "apiname/test.js", FILE_PATH_LITERAL("test.js")},
518 {URL_PREFIX "/apiname/test.js", FILE_PATH_LITERAL("test.js")},
519 // Test % escape
520 {URL_PREFIX "apiname/%74%65st.js", FILE_PATH_LITERAL("test.js")},
521 {URL_PREFIX "apiname/escape%20spaces.js",
522 FILE_PATH_LITERAL("escape spaces.js")},
523 // Test file does not exist.
524 {URL_PREFIX "apiname/directory/to/file.js", NULL},
525 // Test apiname/../../test.js
526 {URL_PREFIX "apiname/../../test.js", FILE_PATH_LITERAL("test.js")},
527 {URL_PREFIX "apiname/..%2F../test.js", NULL},
528 {URL_PREFIX "apiname/f/../../../test.js", FILE_PATH_LITERAL("test.js")},
529 {URL_PREFIX "apiname/f%2F..%2F..%2F../test.js", NULL},
530 {URL_PREFIX "apiname/..%2f..%2fsimple.html",
531 FILE_PATH_LITERAL("..%2f..%2fsimple.html")},
532 };
533 #undef SEP
534 #undef URL_PREFIX
535
536 for (size_t i = 0; i < arraysize(test_cases); ++i) {
537 GURL url(test_cases[i].url);
538 base::FilePath expected_path;
539 if (test_cases[i].expected_path)
540 expected_path = root_path.Append(FILE_PATH_LITERAL("apiname")).Append(
541 test_cases[i].expected_path);
542 base::FilePath actual_path =
543 extensions::file_util::ExtensionResourceURLToFilePath(url, root_path);
544 EXPECT_EQ(expected_path.value(), actual_path.value()) <<
545 " For the path " << url;
546 }
547 // Remove temp files.
548 ASSERT_TRUE(base::DeleteFile(root_path, true));
549 }
550
551 } // namespace extensions 486 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/file_util.cc ('k') | extensions/renderer/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698