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

Side by Side Diff: content/child/blink_platform_impl_unittest.cc

Issue 2561363002: Add std::string constructors for Origin/SchemeHostPort to reduce copies (Closed)
Patch Set: fix content_unittests Created 4 years 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
« no previous file with comments | « no previous file | url/origin.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 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 "content/child/blink_platform_impl.h" 5 #include "content/child/blink_platform_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 12 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 13 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "url/origin.h" 14 #include "url/origin.h"
15 15
16 namespace content { 16 namespace content {
17 17
18 void CheckCastedOriginsAlreadyNormalized( 18 void CheckCastedOriginsAlreadyNormalized(
19 const blink::WebSecurityOrigin& origin) { 19 const blink::WebSecurityOrigin& origin) {
20 url::Origin checked_origin = 20 url::Origin checked_origin =
21 url::Origin::UnsafelyCreateOriginWithoutNormalization( 21 url::Origin::UnsafelyCreateOriginWithoutNormalization(
22 origin.protocol().utf8(), origin.host().utf8(), 22 origin.protocol().utf8(), origin.host().utf8(),
23 origin.effectivePort()); 23 origin.effectivePort());
24 url::Origin non_checked_origin = url::Origin::CreateFromNormalizedTuple( 24 url::Origin non_checked_origin =
25 origin.protocol().utf8(), origin.host().utf8(), origin.effectivePort()); 25 url::Origin::CreateFromNormalizedTupleWithSuborigin(
26 origin.protocol().utf8(), origin.host().utf8(),
27 origin.effectivePort(), origin.suborigin().utf8());
26 EXPECT_EQ(checked_origin.scheme(), non_checked_origin.scheme()); 28 EXPECT_EQ(checked_origin.scheme(), non_checked_origin.scheme());
27 EXPECT_EQ(checked_origin.host(), non_checked_origin.host()); 29 EXPECT_EQ(checked_origin.host(), non_checked_origin.host());
28 EXPECT_EQ(checked_origin.port(), non_checked_origin.port()); 30 EXPECT_EQ(checked_origin.port(), non_checked_origin.port());
29 } 31 }
30 32
31 TEST(BlinkPlatformTest, CastWebSecurityOrigin) { 33 TEST(BlinkPlatformTest, CastWebSecurityOrigin) {
32 struct TestCase { 34 struct TestCase {
33 const char* url; 35 const char* url;
34 const char* scheme; 36 const char* scheme;
35 const char* host; 37 const char* host;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 url::Origin url_origin = web_origin; 139 url::Origin url_origin = web_origin;
138 EXPECT_TRUE(url_origin.unique()); 140 EXPECT_TRUE(url_origin.unique());
139 EXPECT_EQ("", url_origin.suborigin()); 141 EXPECT_EQ("", url_origin.suborigin());
140 142
141 web_origin = url::Origin(GURL("")); 143 web_origin = url::Origin(GURL(""));
142 EXPECT_TRUE(web_origin.isUnique()); 144 EXPECT_TRUE(web_origin.isUnique());
143 } 145 }
144 } 146 }
145 147
146 // This test ensures that WebSecurityOrigins can safely use 148 // This test ensures that WebSecurityOrigins can safely use
147 // url::Origin::CreateFromNormalizedTuple when doing conversions. 149 // url::Origin::CreateFromNormalizedTupleWithSuborigin when doing conversions.
148 TEST(BlinkPlatformTest, WebSecurityOriginNormalization) { 150 TEST(BlinkPlatformTest, WebSecurityOriginNormalization) {
149 struct TestCases { 151 struct TestCases {
150 const char* url; 152 const char* url;
151 } cases[] = {{""}, 153 } cases[] = {{""},
152 {"javascript:alert(1)"}, 154 {"javascript:alert(1)"},
153 {"file://example.com:443/etc/passwd"}, 155 {"file://example.com:443/etc/passwd"},
154 {"blob:https://example.com/uuid-goes-here"}, 156 {"blob:https://example.com/uuid-goes-here"},
155 {"filesystem:https://example.com/temporary/yay.png"}, 157 {"filesystem:https://example.com/temporary/yay.png"},
156 {"data"}, 158 {"data"},
157 {"blob:"}, 159 {"blob:"},
(...skipping 20 matching lines...) Expand all
178 for (const auto& test : cases) { 180 for (const auto& test : cases) {
179 SCOPED_TRACE(testing::Message() << test.url); 181 SCOPED_TRACE(testing::Message() << test.url);
180 blink::WebSecurityOrigin web_origin = 182 blink::WebSecurityOrigin web_origin =
181 blink::WebSecurityOrigin::createFromString( 183 blink::WebSecurityOrigin::createFromString(
182 blink::WebString::fromUTF8(test.url)); 184 blink::WebString::fromUTF8(test.url));
183 CheckCastedOriginsAlreadyNormalized(web_origin); 185 CheckCastedOriginsAlreadyNormalized(web_origin);
184 } 186 }
185 } 187 }
186 188
187 } // namespace content 189 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | url/origin.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698