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

Side by Side Diff: chrome/common/extensions/extension_file_util_unittest.cc

Issue 19052005: Move PathIsWritable, DirectoryExists, ContentsEqual, and TextContentsEqual to the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/common/extensions/extension_file_util.h" 5 #include "chrome/common/extensions/extension_file_util.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 // Install in empty directory. Should create parent directories as needed. 45 // Install in empty directory. Should create parent directories as needed.
46 base::FilePath version_1 = extension_file_util::InstallExtension( 46 base::FilePath version_1 = extension_file_util::InstallExtension(
47 src, 47 src,
48 extension_id, 48 extension_id,
49 version, 49 version,
50 all_extensions); 50 all_extensions);
51 ASSERT_EQ(version_1.value(), 51 ASSERT_EQ(version_1.value(),
52 all_extensions.AppendASCII(extension_id).AppendASCII("1.0_0") 52 all_extensions.AppendASCII(extension_id).AppendASCII("1.0_0")
53 .value()); 53 .value());
54 ASSERT_TRUE(file_util::DirectoryExists(version_1)); 54 ASSERT_TRUE(base::DirectoryExists(version_1));
55 55
56 // Should have moved the source. 56 // Should have moved the source.
57 ASSERT_FALSE(file_util::DirectoryExists(src)); 57 ASSERT_FALSE(base::DirectoryExists(src));
58 58
59 // Install again. Should create a new one with different name. 59 // Install again. Should create a new one with different name.
60 ASSERT_TRUE(file_util::CreateDirectory(src)); 60 ASSERT_TRUE(file_util::CreateDirectory(src));
61 base::FilePath version_2 = extension_file_util::InstallExtension( 61 base::FilePath version_2 = extension_file_util::InstallExtension(
62 src, 62 src,
63 extension_id, 63 extension_id,
64 version, 64 version,
65 all_extensions); 65 all_extensions);
66 ASSERT_EQ(version_2.value(), 66 ASSERT_EQ(version_2.value(),
67 all_extensions.AppendASCII(extension_id).AppendASCII("1.0_1") 67 all_extensions.AppendASCII(extension_id).AppendASCII("1.0_1")
68 .value()); 68 .value());
69 ASSERT_TRUE(file_util::DirectoryExists(version_2)); 69 ASSERT_TRUE(base::DirectoryExists(version_2));
70 70
71 // Should have moved the source. 71 // Should have moved the source.
72 ASSERT_FALSE(file_util::DirectoryExists(src)); 72 ASSERT_FALSE(base::DirectoryExists(src));
73 73
74 // Install yet again. Should create a new one with a different name. 74 // Install yet again. Should create a new one with a different name.
75 ASSERT_TRUE(file_util::CreateDirectory(src)); 75 ASSERT_TRUE(file_util::CreateDirectory(src));
76 base::FilePath version_3 = extension_file_util::InstallExtension( 76 base::FilePath version_3 = extension_file_util::InstallExtension(
77 src, 77 src,
78 extension_id, 78 extension_id,
79 version, 79 version,
80 all_extensions); 80 all_extensions);
81 ASSERT_EQ(version_3.value(), 81 ASSERT_EQ(version_3.value(),
82 all_extensions.AppendASCII(extension_id).AppendASCII("1.0_2") 82 all_extensions.AppendASCII(extension_id).AppendASCII("1.0_2")
83 .value()); 83 .value());
84 ASSERT_TRUE(file_util::DirectoryExists(version_3)); 84 ASSERT_TRUE(base::DirectoryExists(version_3));
85 85
86 // Collect garbage. Should remove first one. 86 // Collect garbage. Should remove first one.
87 std::multimap<std::string, base::FilePath> extension_paths; 87 std::multimap<std::string, base::FilePath> extension_paths;
88 extension_paths.insert(std::make_pair(extension_id, 88 extension_paths.insert(std::make_pair(extension_id,
89 base::FilePath().AppendASCII(extension_id).Append(version_2.BaseName()))); 89 base::FilePath().AppendASCII(extension_id).Append(version_2.BaseName())));
90 extension_paths.insert(std::make_pair(extension_id, 90 extension_paths.insert(std::make_pair(extension_id,
91 base::FilePath().AppendASCII(extension_id).Append(version_3.BaseName()))); 91 base::FilePath().AppendASCII(extension_id).Append(version_3.BaseName())));
92 extension_file_util::GarbageCollectExtensions(all_extensions, 92 extension_file_util::GarbageCollectExtensions(all_extensions,
93 extension_paths); 93 extension_paths);
94 ASSERT_FALSE(file_util::DirectoryExists(version_1)); 94 ASSERT_FALSE(base::DirectoryExists(version_1));
95 ASSERT_TRUE(file_util::DirectoryExists(version_2)); 95 ASSERT_TRUE(base::DirectoryExists(version_2));
96 ASSERT_TRUE(file_util::DirectoryExists(version_3)); 96 ASSERT_TRUE(base::DirectoryExists(version_3));
97 97
98 // Uninstall. Should remove entire extension subtree. 98 // Uninstall. Should remove entire extension subtree.
99 extension_file_util::UninstallExtension(all_extensions, extension_id); 99 extension_file_util::UninstallExtension(all_extensions, extension_id);
100 ASSERT_FALSE(file_util::DirectoryExists(version_2.DirName())); 100 ASSERT_FALSE(base::DirectoryExists(version_2.DirName()));
101 ASSERT_FALSE(file_util::DirectoryExists(version_3.DirName())); 101 ASSERT_FALSE(base::DirectoryExists(version_3.DirName()));
102 ASSERT_TRUE(file_util::DirectoryExists(all_extensions)); 102 ASSERT_TRUE(base::DirectoryExists(all_extensions));
103 } 103 }
104 104
105 TEST_F(ExtensionFileUtilTest, LoadExtensionWithValidLocales) { 105 TEST_F(ExtensionFileUtilTest, LoadExtensionWithValidLocales) {
106 base::FilePath install_dir; 106 base::FilePath install_dir;
107 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir)); 107 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &install_dir));
108 install_dir = install_dir.AppendASCII("extensions") 108 install_dir = install_dir.AppendASCII("extensions")
109 .AppendASCII("good") 109 .AppendASCII("good")
110 .AppendASCII("Extensions") 110 .AppendASCII("Extensions")
111 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 111 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
112 .AppendASCII("1.0.0.0"); 112 .AppendASCII("1.0.0.0");
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension( 567 scoped_refptr<Extension> extension3(extension_file_util::LoadExtension(
568 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error)); 568 ext_dir, Manifest::UNPACKED, Extension::NO_FLAGS, &error));
569 EXPECT_TRUE(extension3.get() == NULL); 569 EXPECT_TRUE(extension3.get() == NULL);
570 EXPECT_STREQ("Could not load icon 'icon.png' for page action.", 570 EXPECT_STREQ("Could not load icon 'icon.png' for page action.",
571 error.c_str()); 571 error.c_str());
572 } 572 }
573 573
574 // TODO(aa): More tests as motivation allows. Maybe steal some from 574 // TODO(aa): More tests as motivation allows. Maybe steal some from
575 // ExtensionService? Many of them could probably be tested here without the 575 // ExtensionService? Many of them could probably be tested here without the
576 // MessageLoop shenanigans. 576 // MessageLoop shenanigans.
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.cc ('k') | chrome/common/mac/app_mode_chrome_locator_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698