OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "content/public/test/browser_test.h" | 9 #include "content/public/test/browser_test.h" |
10 #include "headless/public/domains/page.h" | 10 #include "headless/public/domains/page.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 .Build(); | 233 .Build(); |
234 EXPECT_TRUE(web_contents); | 234 EXPECT_TRUE(web_contents); |
235 | 235 |
236 EXPECT_TRUE(WaitForLoad(web_contents)); | 236 EXPECT_TRUE(WaitForLoad(web_contents)); |
237 } | 237 } |
238 | 238 |
239 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, HttpProtocolHandler) { | 239 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, HttpProtocolHandler) { |
240 const std::string kResponseBody = "<p>HTTP response body</p>"; | 240 const std::string kResponseBody = "<p>HTTP response body</p>"; |
241 ProtocolHandlerMap protocol_handlers; | 241 ProtocolHandlerMap protocol_handlers; |
242 protocol_handlers[url::kHttpScheme] = | 242 protocol_handlers[url::kHttpScheme] = |
243 base::WrapUnique(new TestProtocolHandler(kResponseBody)); | 243 base::MakeUnique<TestProtocolHandler>(kResponseBody); |
244 | 244 |
245 HeadlessBrowserContext* browser_context = | 245 HeadlessBrowserContext* browser_context = |
246 browser() | 246 browser() |
247 ->CreateBrowserContextBuilder() | 247 ->CreateBrowserContextBuilder() |
248 .SetProtocolHandlers(std::move(protocol_handlers)) | 248 .SetProtocolHandlers(std::move(protocol_handlers)) |
249 .Build(); | 249 .Build(); |
250 | 250 |
251 // Load a page which doesn't actually exist, but which is fetched by our | 251 // Load a page which doesn't actually exist, but which is fetched by our |
252 // custom protocol handler. | 252 // custom protocol handler. |
253 HeadlessWebContents* web_contents = | 253 HeadlessWebContents* web_contents = |
254 browser_context->CreateWebContentsBuilder() | 254 browser_context->CreateWebContentsBuilder() |
255 .SetInitialURL(GURL("http://not-an-actual-domain.tld/hello.html")) | 255 .SetInitialURL(GURL("http://not-an-actual-domain.tld/hello.html")) |
256 .Build(); | 256 .Build(); |
257 EXPECT_TRUE(web_contents); | 257 EXPECT_TRUE(web_contents); |
258 EXPECT_TRUE(WaitForLoad(web_contents)); | 258 EXPECT_TRUE(WaitForLoad(web_contents)); |
259 | 259 |
260 std::string inner_html; | 260 std::string inner_html; |
261 EXPECT_TRUE(EvaluateScript(web_contents, "document.body.innerHTML") | 261 EXPECT_TRUE(EvaluateScript(web_contents, "document.body.innerHTML") |
262 ->GetResult() | 262 ->GetResult() |
263 ->GetValue() | 263 ->GetValue() |
264 ->GetAsString(&inner_html)); | 264 ->GetAsString(&inner_html)); |
265 EXPECT_EQ(kResponseBody, inner_html); | 265 EXPECT_EQ(kResponseBody, inner_html); |
266 } | 266 } |
267 | 267 |
268 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, HttpsProtocolHandler) { | 268 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, HttpsProtocolHandler) { |
269 const std::string kResponseBody = "<p>HTTPS response body</p>"; | 269 const std::string kResponseBody = "<p>HTTPS response body</p>"; |
270 ProtocolHandlerMap protocol_handlers; | 270 ProtocolHandlerMap protocol_handlers; |
271 protocol_handlers[url::kHttpsScheme] = | 271 protocol_handlers[url::kHttpsScheme] = |
272 base::WrapUnique(new TestProtocolHandler(kResponseBody)); | 272 base::MakeUnique<TestProtocolHandler>(kResponseBody); |
273 | 273 |
274 HeadlessBrowserContext* browser_context = | 274 HeadlessBrowserContext* browser_context = |
275 browser() | 275 browser() |
276 ->CreateBrowserContextBuilder() | 276 ->CreateBrowserContextBuilder() |
277 .SetProtocolHandlers(std::move(protocol_handlers)) | 277 .SetProtocolHandlers(std::move(protocol_handlers)) |
278 .Build(); | 278 .Build(); |
279 | 279 |
280 // Load a page which doesn't actually exist, but which is fetched by our | 280 // Load a page which doesn't actually exist, but which is fetched by our |
281 // custom protocol handler. | 281 // custom protocol handler. |
282 HeadlessWebContents* web_contents = | 282 HeadlessWebContents* web_contents = |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 *sent_cookies_ = cookie_list; | 444 *sent_cookies_ = cookie_list; |
445 NotifyHeadersComplete(); | 445 NotifyHeadersComplete(); |
446 } | 446 } |
447 | 447 |
448 } // namespace | 448 } // namespace |
449 | 449 |
450 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, ReadCookiesInProtocolHandler) { | 450 IN_PROC_BROWSER_TEST_F(HeadlessBrowserTest, ReadCookiesInProtocolHandler) { |
451 net::CookieList sent_cookies; | 451 net::CookieList sent_cookies; |
452 ProtocolHandlerMap protocol_handlers; | 452 ProtocolHandlerMap protocol_handlers; |
453 protocol_handlers[url::kHttpsScheme] = | 453 protocol_handlers[url::kHttpsScheme] = |
454 base::WrapUnique(new ProtocolHandlerWithCookies(&sent_cookies)); | 454 base::MakeUnique<ProtocolHandlerWithCookies>(&sent_cookies); |
455 | 455 |
456 HeadlessBrowserContext* browser_context = | 456 HeadlessBrowserContext* browser_context = |
457 browser() | 457 browser() |
458 ->CreateBrowserContextBuilder() | 458 ->CreateBrowserContextBuilder() |
459 .SetProtocolHandlers(std::move(protocol_handlers)) | 459 .SetProtocolHandlers(std::move(protocol_handlers)) |
460 .Build(); | 460 .Build(); |
461 | 461 |
462 HeadlessWebContents* web_contents = | 462 HeadlessWebContents* web_contents = |
463 browser_context->CreateWebContentsBuilder() | 463 browser_context->CreateWebContentsBuilder() |
464 .SetInitialURL(GURL("https://example.com/cookie.html")) | 464 .SetInitialURL(GURL("https://example.com/cookie.html")) |
(...skipping 10 matching lines...) Expand all Loading... |
475 ->HasExceptionDetails()); | 475 ->HasExceptionDetails()); |
476 EXPECT_TRUE(WaitForLoad(web_contents)); | 476 EXPECT_TRUE(WaitForLoad(web_contents)); |
477 | 477 |
478 // We should have sent the cookie this time. | 478 // We should have sent the cookie this time. |
479 EXPECT_EQ(1u, sent_cookies.size()); | 479 EXPECT_EQ(1u, sent_cookies.size()); |
480 EXPECT_EQ("shape", sent_cookies[0].Name()); | 480 EXPECT_EQ("shape", sent_cookies[0].Name()); |
481 EXPECT_EQ("oblong", sent_cookies[0].Value()); | 481 EXPECT_EQ("oblong", sent_cookies[0].Value()); |
482 } | 482 } |
483 | 483 |
484 } // namespace headless | 484 } // namespace headless |
OLD | NEW |