| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 origin->buildRawString(builder); | 220 origin->buildRawString(builder); |
| 221 EXPECT_EQ("https://foobar_test.com", builder.toString()); | 221 EXPECT_EQ("https://foobar_test.com", builder.toString()); |
| 222 | 222 |
| 223 builder.clear(); | 223 builder.clear(); |
| 224 origin = SecurityOrigin::createFromString("https://test.com"); | 224 origin = SecurityOrigin::createFromString("https://test.com"); |
| 225 origin->addSuborigin("foobar"); | 225 origin->addSuborigin("foobar"); |
| 226 origin->buildRawString(builder); | 226 origin->buildRawString(builder); |
| 227 EXPECT_EQ("https://foobar_test.com", builder.toString()); | 227 EXPECT_EQ("https://foobar_test.com", builder.toString()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 TEST_F(SecurityOriginTest, SuboriginsIsSameSchemeHostPortAndSuborigin) |
| 231 { |
| 232 blink::RuntimeEnabledFeatures::setSuboriginsEnabled(true); |
| 233 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("https://fo
obar_test.com"); |
| 234 RefPtr<SecurityOrigin> other1 = SecurityOrigin::createFromString("https://ba
zbar_test.com"); |
| 235 RefPtr<SecurityOrigin> other2 = SecurityOrigin::createFromString("http://foo
bar_test.com"); |
| 236 RefPtr<SecurityOrigin> other3 = SecurityOrigin::createFromString("https://fo
obar_test.com:1234"); |
| 237 RefPtr<SecurityOrigin> other4 = SecurityOrigin::createFromString("https://te
st.com"); |
| 238 |
| 239 EXPECT_TRUE(origin->isSameSchemeHostPortAndSuborigin(origin.get())); |
| 240 EXPECT_FALSE(origin->isSameSchemeHostPortAndSuborigin(other1.get())); |
| 241 EXPECT_FALSE(origin->isSameSchemeHostPortAndSuborigin(other2.get())); |
| 242 EXPECT_FALSE(origin->isSameSchemeHostPortAndSuborigin(other3.get())); |
| 243 EXPECT_FALSE(origin->isSameSchemeHostPortAndSuborigin(other4.get())); |
| 244 } |
| 245 |
| 246 TEST_F(SecurityOriginTest, CanAccess) |
| 247 { |
| 248 RuntimeEnabledFeatures::setSuboriginsEnabled(true); |
| 249 |
| 250 struct TestCase { |
| 251 bool canAccess; |
| 252 bool canAccessCheckSuborigins; |
| 253 const char* origin1; |
| 254 const char* origin2; |
| 255 }; |
| 256 |
| 257 TestCase tests[] = { |
| 258 { true, true, "https://foobar.com", "https://foobar.com" }, |
| 259 { false, false, "https://foobar.com", "https://bazbar.com" }, |
| 260 { true, false, "https://foobar.com", "https://name_foobar.com" }, |
| 261 { true, false, "https://name_foobar.com", "https://foobar.com" }, |
| 262 { true, true, "https://name_foobar.com", "https://name_foobar.com" }, |
| 263 }; |
| 264 |
| 265 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 266 RefPtr<SecurityOrigin> origin1 = SecurityOrigin::createFromString(tests[
i].origin1); |
| 267 RefPtr<SecurityOrigin> origin2 = SecurityOrigin::createFromString(tests[
i].origin2); |
| 268 EXPECT_EQ(tests[i].canAccess, origin1->canAccess(origin2.get())); |
| 269 EXPECT_EQ(tests[i].canAccessCheckSuborigins, origin1->canAccessCheckSubo
rigins(origin2.get())); |
| 270 } |
| 271 } |
| 272 |
| 273 TEST_F(SecurityOriginTest, CanRequest) |
| 274 { |
| 275 RuntimeEnabledFeatures::setSuboriginsEnabled(true); |
| 276 |
| 277 struct TestCase { |
| 278 bool canRequest; |
| 279 bool canRequestNoSuborigin; |
| 280 const char* origin; |
| 281 const char* url; |
| 282 }; |
| 283 |
| 284 TestCase tests[] = { |
| 285 { true, true, "https://foobar.com", "https://foobar.com" }, |
| 286 { false, false, "https://foobar.com", "https://bazbar.com" }, |
| 287 { true, false, "https://name_foobar.com", "https://foobar.com" }, |
| 288 { false, false, "https://name_foobar.com", "https://bazbar.com" }, |
| 289 }; |
| 290 |
| 291 for (size_t i = 0; i < arraysize(tests); ++i) { |
| 292 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(tests[i
].origin); |
| 293 blink::KURL url(blink::ParsedURLString, tests[i].url); |
| 294 EXPECT_EQ(tests[i].canRequest, origin->canRequest(url)); |
| 295 EXPECT_EQ(tests[i].canRequestNoSuborigin, origin->canRequestNoSuborigin(
url)); |
| 296 } |
| 297 } |
| 298 |
| 230 } // namespace blink | 299 } // namespace blink |
| OLD | NEW |