OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "storage/common/database/database_identifier.h" | 5 #include "storage/common/database/database_identifier.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 DatabaseIdentifier::Parse(bogus_components[i]); | 238 DatabaseIdentifier::Parse(bogus_components[i]); |
239 EXPECT_EQ("__0", identifier.ToString()) | 239 EXPECT_EQ("__0", identifier.ToString()) |
240 << "test case " << bogus_components[i]; | 240 << "test case " << bogus_components[i]; |
241 EXPECT_EQ(GURL("null"), identifier.ToOrigin()) | 241 EXPECT_EQ(GURL("null"), identifier.ToOrigin()) |
242 << "test case " << bogus_components[i]; | 242 << "test case " << bogus_components[i]; |
243 EXPECT_EQ(true, identifier.is_unique()) | 243 EXPECT_EQ(true, identifier.is_unique()) |
244 << "test case " << bogus_components[i]; | 244 << "test case " << bogus_components[i]; |
245 } | 245 } |
246 } | 246 } |
247 | 247 |
248 static GURL ToAndFromOriginIdentifier(const GURL origin_url) { | |
249 std::string id = storage::GetIdentifierFromOrigin(origin_url); | |
250 return storage::GetOriginFromIdentifier(id); | |
251 } | |
252 | |
253 static void TestValidOriginIdentifier(bool expected_result, | |
254 const std::string& id) { | |
255 EXPECT_EQ(expected_result, | |
256 storage::IsValidOriginIdentifier(id)); | |
257 } | |
258 | |
259 TEST(DatabaseIdentifierTest, OriginIdentifiers) { | |
jsbell
2016/03/02 20:29:09
These are probably redundant with above cases. Lef
| |
260 const GURL kFileOrigin(GURL("file:///").GetOrigin()); | |
261 const GURL kHttpOrigin(GURL("http://bar/").GetOrigin()); | |
262 EXPECT_EQ(kFileOrigin, ToAndFromOriginIdentifier(kFileOrigin)); | |
263 EXPECT_EQ(kHttpOrigin, ToAndFromOriginIdentifier(kHttpOrigin)); | |
264 } | |
265 | |
266 TEST(DatabaseIdentifierTest, IsValidOriginIdentifier) { | |
267 TestValidOriginIdentifier(true, "http_bar_0"); | |
268 TestValidOriginIdentifier(false, ""); | |
269 TestValidOriginIdentifier(false, "bad..id"); | |
270 TestValidOriginIdentifier(false, "bad/id"); | |
271 TestValidOriginIdentifier(false, "bad\\id"); | |
272 TestValidOriginIdentifier(false, "http_bad:0_2"); | |
273 TestValidOriginIdentifier(false, std::string("bad\0id", 6)); | |
274 } | |
275 | |
248 } // namespace | 276 } // namespace |
249 } // namespace content | 277 } // namespace content |
OLD | NEW |