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

Side by Side Diff: content/browser/download/file_metadata_unittest_linux.cc

Issue 10821069: Moving file_metadata files under content/browser/download (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Git-based patch to overcome the 'svn mv' problem Created 8 years, 4 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
« no previous file with comments | « content/browser/download/file_metadata_mac.mm ('k') | content/browser/file_metadata_mac.h » ('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 (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 <errno.h> 5 #include <errno.h>
6 #include <sys/types.h> 6 #include <sys/types.h>
7 #include <sys/xattr.h> 7 #include <sys/xattr.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <sstream> 10 #include <sstream>
11 #include <string> 11 #include <string>
12 12
13 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/scoped_temp_dir.h" 16 #include "base/scoped_temp_dir.h"
17 #include "base/string_split.h" 17 #include "base/string_split.h"
18 #include "content/browser/download/file_metadata_linux.h" 18 #include "content/browser/download/file_metadata_linux.h"
19 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 21
22 namespace content {
22 namespace { 23 namespace {
23 24
24 using std::istringstream; 25 using std::istringstream;
25 using std::string; 26 using std::string;
26 using std::vector; 27 using std::vector;
27 28
28 class FileMetadataLinuxTest : public testing::Test { 29 class FileMetadataLinuxTest : public testing::Test {
29 public: 30 public:
30 FileMetadataLinuxTest() 31 FileMetadataLinuxTest()
31 : source_url_("http://www.source.com"), 32 : source_url_("http://www.source.com"),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 base::SplitString(string(buffer, len), '\0', attr_names); 86 base::SplitString(string(buffer, len), '\0', attr_names);
86 delete[] buffer; 87 delete[] buffer;
87 } 88 }
88 89
89 void VerifyAttributesAreSetCorrectly() const { 90 void VerifyAttributesAreSetCorrectly() const {
90 vector<string> attr_names; 91 vector<string> attr_names;
91 GetExtendedAttributeNames(&attr_names); 92 GetExtendedAttributeNames(&attr_names);
92 93
93 // Check if the attributes are set on the file 94 // Check if the attributes are set on the file
94 vector<string>::const_iterator pos = find(attr_names.begin(), 95 vector<string>::const_iterator pos = find(attr_names.begin(),
95 attr_names.end(), content::kSourceURLAttrName); 96 attr_names.end(), kSourceURLAttrName);
96 EXPECT_NE(pos, attr_names.end()); 97 EXPECT_NE(pos, attr_names.end());
97 pos = find(attr_names.begin(), attr_names.end(), 98 pos = find(attr_names.begin(), attr_names.end(), kReferrerURLAttrName);
98 content::kReferrerURLAttrName);
99 EXPECT_NE(pos, attr_names.end()); 99 EXPECT_NE(pos, attr_names.end());
100 100
101 // Check if the attribute values are set correctly 101 // Check if the attribute values are set correctly
102 CheckExtendedAttributeValue(content::kSourceURLAttrName, 102 CheckExtendedAttributeValue(kSourceURLAttrName, source_url().spec());
103 source_url().spec()); 103 CheckExtendedAttributeValue(kReferrerURLAttrName, referrer_url().spec());
104 CheckExtendedAttributeValue(content::kReferrerURLAttrName,
105 referrer_url().spec());
106 } 104 }
107 105
108 private: 106 private:
109 ScopedTempDir temp_dir_; 107 ScopedTempDir temp_dir_;
110 FilePath test_file_; 108 FilePath test_file_;
111 GURL source_url_; 109 GURL source_url_;
112 GURL referrer_url_; 110 GURL referrer_url_;
113 bool is_xattr_supported_; 111 bool is_xattr_supported_;
114 }; 112 };
115 113
116 TEST_F(FileMetadataLinuxTest, CheckMetadataSetCorrectly) { 114 TEST_F(FileMetadataLinuxTest, CheckMetadataSetCorrectly) {
117 if (!is_xattr_supported()) return; 115 if (!is_xattr_supported()) return;
118 content::AddOriginMetadataToFile(test_file(), source_url(), referrer_url()); 116 AddOriginMetadataToFile(test_file(), source_url(), referrer_url());
119 VerifyAttributesAreSetCorrectly(); 117 VerifyAttributesAreSetCorrectly();
120 } 118 }
121 119
122 TEST_F(FileMetadataLinuxTest, SetMetadataMultipleTimes) { 120 TEST_F(FileMetadataLinuxTest, SetMetadataMultipleTimes) {
123 if (!is_xattr_supported()) return; 121 if (!is_xattr_supported()) return;
124 content::AddOriginMetadataToFile(test_file(), 122 GURL dummy_url("http://www.dummy.com");
125 GURL("http://www.dummy.com"), GURL("http://www.dummy.com")); 123 AddOriginMetadataToFile(test_file(), dummy_url, dummy_url);
126 content::AddOriginMetadataToFile(test_file(), source_url(), referrer_url()); 124 AddOriginMetadataToFile(test_file(), source_url(), referrer_url());
127 VerifyAttributesAreSetCorrectly(); 125 VerifyAttributesAreSetCorrectly();
128 } 126 }
129 127
130 TEST_F(FileMetadataLinuxTest, InvalidSourceURLTest) { 128 TEST_F(FileMetadataLinuxTest, InvalidSourceURLTest) {
131 if (!is_xattr_supported()) return; 129 if (!is_xattr_supported()) return;
132 GURL invalid_url; 130 GURL invalid_url;
133 vector<string> attr_names; 131 vector<string> attr_names;
134 content::AddOriginMetadataToFile(test_file(), invalid_url, referrer_url()); 132 AddOriginMetadataToFile(test_file(), invalid_url, referrer_url());
135 GetExtendedAttributeNames(&attr_names); 133 GetExtendedAttributeNames(&attr_names);
136 EXPECT_EQ(attr_names.end(), find(attr_names.begin(), attr_names.end(), 134 EXPECT_EQ(attr_names.end(), find(attr_names.begin(), attr_names.end(),
137 content::kSourceURLAttrName)); 135 kSourceURLAttrName));
138 CheckExtendedAttributeValue(content::kReferrerURLAttrName, 136 CheckExtendedAttributeValue(kReferrerURLAttrName, referrer_url().spec());
139 referrer_url().spec());
140 } 137 }
141 138
142 TEST_F(FileMetadataLinuxTest, InvalidReferrerURLTest) { 139 TEST_F(FileMetadataLinuxTest, InvalidReferrerURLTest) {
143 if (!is_xattr_supported()) return; 140 if (!is_xattr_supported()) return;
144 GURL invalid_url; 141 GURL invalid_url;
145 vector<string> attr_names; 142 vector<string> attr_names;
146 content::AddOriginMetadataToFile(test_file(), source_url(), invalid_url); 143 AddOriginMetadataToFile(test_file(), source_url(), invalid_url);
147 GetExtendedAttributeNames(&attr_names); 144 GetExtendedAttributeNames(&attr_names);
148 EXPECT_EQ(attr_names.end(), find(attr_names.begin(), attr_names.end(), 145 EXPECT_EQ(attr_names.end(), find(attr_names.begin(), attr_names.end(),
149 content::kReferrerURLAttrName)); 146 kReferrerURLAttrName));
150 CheckExtendedAttributeValue(content::kSourceURLAttrName, source_url().spec()); 147 CheckExtendedAttributeValue(kSourceURLAttrName, source_url().spec());
151 } 148 }
152 149
153 TEST_F(FileMetadataLinuxTest, InvalidURLsTest) { 150 TEST_F(FileMetadataLinuxTest, InvalidURLsTest) {
154 if (!is_xattr_supported()) return; 151 if (!is_xattr_supported()) return;
155 GURL invalid_url; 152 GURL invalid_url;
156 vector<string> attr_names; 153 vector<string> attr_names;
157 content::AddOriginMetadataToFile(test_file(), invalid_url, invalid_url); 154 AddOriginMetadataToFile(test_file(), invalid_url, invalid_url);
158 GetExtendedAttributeNames(&attr_names); 155 GetExtendedAttributeNames(&attr_names);
159 EXPECT_EQ(attr_names.end(), find(attr_names.begin(), attr_names.end(), 156 EXPECT_EQ(attr_names.end(), find(attr_names.begin(), attr_names.end(),
160 content::kSourceURLAttrName)); 157 kSourceURLAttrName));
161 EXPECT_EQ(attr_names.end(), find(attr_names.begin(), attr_names.end(), 158 EXPECT_EQ(attr_names.end(), find(attr_names.begin(), attr_names.end(),
162 content::kReferrerURLAttrName)); 159 kReferrerURLAttrName));
163 } 160 }
164 161
165 } // namespace 162 } // namespace
163 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/file_metadata_mac.mm ('k') | content/browser/file_metadata_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698