| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "platform/weborigin/SecurityOrigin.h" | 32 #include "platform/weborigin/SecurityOrigin.h" |
| 33 | 33 |
| 34 #include "platform/RuntimeEnabledFeatures.h" | 34 #include "platform/RuntimeEnabledFeatures.h" |
| 35 #include "platform/weborigin/KURL.h" | 35 #include "platform/weborigin/KURL.h" |
| 36 #include "wtf/text/StringBuilder.h" | 36 #include "wtf/text/StringBuilder.h" |
| 37 #include "wtf/text/WTFString.h" | 37 #include "wtf/text/WTFString.h" |
| 38 #include <gtest/gtest.h> | 38 #include <gtest/gtest.h> |
| 39 | 39 |
| 40 using blink::SecurityOrigin; | |
| 41 | |
| 42 namespace blink { | 40 namespace blink { |
| 43 | 41 |
| 44 const int MaxAllowedPort = 65535; | 42 const int MaxAllowedPort = 65535; |
| 45 | 43 |
| 46 class SecurityOriginTest : public ::testing::Test { }; | 44 class SecurityOriginTest : public ::testing::Test { }; |
| 47 | 45 |
| 48 TEST_F(SecurityOriginTest, InvalidPortsCreateUniqueOrigins) | 46 TEST_F(SecurityOriginTest, InvalidPortsCreateUniqueOrigins) |
| 49 { | 47 { |
| 50 int ports[] = { -100, -1, MaxAllowedPort + 1, 1000000 }; | 48 int ports[] = { -100, -1, MaxAllowedPort + 1, 1000000 }; |
| 51 | 49 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 { true, "blob:https://example.com/578223a1-8c13-17b3-84d5-eca045ae384a"
}, | 157 { true, "blob:https://example.com/578223a1-8c13-17b3-84d5-eca045ae384a"
}, |
| 160 { true, "https://example.com/" }, | 158 { true, "https://example.com/" }, |
| 161 { true, "wss://example.com/" }, | 159 { true, "wss://example.com/" }, |
| 162 | 160 |
| 163 { true, "about:blank" }, | 161 { true, "about:blank" }, |
| 164 { false, "" }, | 162 { false, "" }, |
| 165 { false, "\0" }, | 163 { false, "\0" }, |
| 166 }; | 164 }; |
| 167 | 165 |
| 168 for (auto test : inputs) | 166 for (auto test : inputs) |
| 169 EXPECT_EQ(test.isSecure, SecurityOrigin::isSecure(blink::KURL(blink::Par
sedURLString, test.url))) << "URL: '" << test.url << "'"; | 167 EXPECT_EQ(test.isSecure, SecurityOrigin::isSecure(KURL(ParsedURLString,
test.url))) << "URL: '" << test.url << "'"; |
| 170 | 168 |
| 171 EXPECT_FALSE(SecurityOrigin::isSecure(blink::KURL())); | 169 EXPECT_FALSE(SecurityOrigin::isSecure(KURL())); |
| 172 } | 170 } |
| 173 | 171 |
| 174 TEST_F(SecurityOriginTest, Suborigins) | 172 TEST_F(SecurityOriginTest, Suborigins) |
| 175 { | 173 { |
| 176 blink::RuntimeEnabledFeatures::setSuboriginsEnabled(true); | 174 RuntimeEnabledFeatures::setSuboriginsEnabled(true); |
| 177 | 175 |
| 178 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("https://te
st.com"); | 176 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString("https://te
st.com"); |
| 179 EXPECT_FALSE(origin->hasSuborigin()); | 177 EXPECT_FALSE(origin->hasSuborigin()); |
| 180 origin->addSuborigin("foobar"); | 178 origin->addSuborigin("foobar"); |
| 181 EXPECT_TRUE(origin->hasSuborigin()); | 179 EXPECT_TRUE(origin->hasSuborigin()); |
| 182 EXPECT_EQ("foobar", origin->suboriginName()); | 180 EXPECT_EQ("foobar", origin->suboriginName()); |
| 183 | 181 |
| 184 origin = SecurityOrigin::createFromString("https://foobar_test.com"); | 182 origin = SecurityOrigin::createFromString("https://foobar_test.com"); |
| 185 EXPECT_EQ("https", origin->protocol()); | 183 EXPECT_EQ("https", origin->protocol()); |
| 186 EXPECT_EQ("test.com", origin->host()); | 184 EXPECT_EQ("test.com", origin->host()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 198 | 196 |
| 199 origin = adoptRef<SecurityOrigin>(new SecurityOrigin); | 197 origin = adoptRef<SecurityOrigin>(new SecurityOrigin); |
| 200 EXPECT_FALSE(origin->hasSuborigin()); | 198 EXPECT_FALSE(origin->hasSuborigin()); |
| 201 | 199 |
| 202 origin = SecurityOrigin::createFromString("https://foobar_test.com"); | 200 origin = SecurityOrigin::createFromString("https://foobar_test.com"); |
| 203 EXPECT_DEATH(origin->addSuborigin("shouldhitassert"), ""); | 201 EXPECT_DEATH(origin->addSuborigin("shouldhitassert"), ""); |
| 204 } | 202 } |
| 205 | 203 |
| 206 TEST_F(SecurityOriginTest, SuboriginsParsing) | 204 TEST_F(SecurityOriginTest, SuboriginsParsing) |
| 207 { | 205 { |
| 208 blink::RuntimeEnabledFeatures::setSuboriginsEnabled(true); | 206 RuntimeEnabledFeatures::setSuboriginsEnabled(true); |
| 209 String host, realHost, suborigin; | 207 String host, realHost, suborigin; |
| 210 host = "test.com"; | 208 host = "test.com"; |
| 211 EXPECT_FALSE(SecurityOrigin::deserializeSuboriginAndHost(host, suborigin, re
alHost)); | 209 EXPECT_FALSE(SecurityOrigin::deserializeSuboriginAndHost(host, suborigin, re
alHost)); |
| 212 | 210 |
| 213 host = "foobar_test.com"; | 211 host = "foobar_test.com"; |
| 214 EXPECT_TRUE(SecurityOrigin::deserializeSuboriginAndHost(host, suborigin, rea
lHost)); | 212 EXPECT_TRUE(SecurityOrigin::deserializeSuboriginAndHost(host, suborigin, rea
lHost)); |
| 215 EXPECT_EQ("test.com", realHost); | 213 EXPECT_EQ("test.com", realHost); |
| 216 EXPECT_EQ("foobar", suborigin); | 214 EXPECT_EQ("foobar", suborigin); |
| 217 | 215 |
| 218 RefPtr<SecurityOrigin> origin; | 216 RefPtr<SecurityOrigin> origin; |
| 219 StringBuilder builder; | 217 StringBuilder builder; |
| 220 | 218 |
| 221 origin = SecurityOrigin::createFromString("https://foobar_test.com"); | 219 origin = SecurityOrigin::createFromString("https://foobar_test.com"); |
| 222 origin->buildRawString(builder); | 220 origin->buildRawString(builder); |
| 223 EXPECT_EQ("https://foobar_test.com", builder.toString()); | 221 EXPECT_EQ("https://foobar_test.com", builder.toString()); |
| 224 | 222 |
| 225 builder.clear(); | 223 builder.clear(); |
| 226 origin = SecurityOrigin::createFromString("https://test.com"); | 224 origin = SecurityOrigin::createFromString("https://test.com"); |
| 227 origin->addSuborigin("foobar"); | 225 origin->addSuborigin("foobar"); |
| 228 origin->buildRawString(builder); | 226 origin->buildRawString(builder); |
| 229 EXPECT_EQ("https://foobar_test.com", builder.toString()); | 227 EXPECT_EQ("https://foobar_test.com", builder.toString()); |
| 230 } | 228 } |
| 231 | 229 |
| 232 } // namespace | 230 } // namespace blink |
| OLD | NEW |