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

Side by Side Diff: content/common/database_identifier_unittest.cc

Issue 1753403002: Move IsValidOriginIdentifier into appropriate header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
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
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
OLDNEW
« no previous file with comments | « content/browser/renderer_host/database_message_filter.cc ('k') | storage/browser/database/database_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698