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
3 // found in the LICENSE file.
5 #include "content/browser/transition_request_manager.h"
6 #include "net/http/http_response_headers.h"
7 #include "net/http/http_util.h"
8 #include "testing/gtest/include/gtest/gtest.h"
12 class TransitionRequestManagerTest
: public testing::Test
{
14 virtual ~TransitionRequestManagerTest() {}
17 TEST_F(TransitionRequestManagerTest
,
18 ParseTransitionStylesheetsFromNullHeaders
) {
19 const GURL
url("http://www.test.com/");
20 std::vector
<GURL
> entering_stylesheets
;
21 scoped_refptr
<net::HttpResponseHeaders
> headers
;
23 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
24 headers
, entering_stylesheets
, url
);
25 ASSERT_TRUE(entering_stylesheets
.empty());
28 TEST_F(TransitionRequestManagerTest
,
29 ParseTransitionStylesheetsFromEmptyHeaders
) {
30 const GURL
url("http://www.test.com/");
31 std::vector
<GURL
> entering_stylesheets
;
33 char headers_string
[] = "";
34 scoped_refptr
<net::HttpResponseHeaders
> headers(
35 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
36 headers_string
, sizeof(headers_string
))));
38 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
39 headers
, entering_stylesheets
, url
);
40 ASSERT_TRUE(entering_stylesheets
.empty());
43 TEST_F(TransitionRequestManagerTest
,
44 ParseTransitionStylesheetsFromHeadersForInvalidURL
) {
46 std::vector
<GURL
> entering_stylesheets
;
48 char headers_string
[] =
50 "link: <transition.css>;rel=transition-entering-stylesheet;scope=*\r\n"
52 scoped_refptr
<net::HttpResponseHeaders
> headers(
53 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
54 headers_string
, sizeof(headers_string
))));
56 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
57 headers
, entering_stylesheets
, url
);
58 ASSERT_TRUE(entering_stylesheets
.empty());
61 TEST_F(TransitionRequestManagerTest
, ParseTransitionStylesheetsFromHeaders
) {
62 const GURL
url("http://www.test.com/");
63 std::vector
<GURL
> entering_stylesheets
;
65 char headers_string
[] =
67 "link: <transition.css>;rel=transition-entering-stylesheet;scope=*\r\n"
69 scoped_refptr
<net::HttpResponseHeaders
> headers(
70 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
71 headers_string
, sizeof(headers_string
))));
73 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
74 headers
, entering_stylesheets
, url
);
75 ASSERT_TRUE(entering_stylesheets
.size() == 1);
76 ASSERT_STREQ((url
.spec() + "transition.css").c_str(),
77 entering_stylesheets
[0].spec().c_str());
80 TEST_F(TransitionRequestManagerTest
,
81 ParseMultipleTransitionStylesheetsFromHeaders
) {
82 const GURL
url("http://www.test.com/");
83 std::vector
<GURL
> entering_stylesheets
;
85 char headers_string
[] =
87 "link: <transition0.css>;rel=transition-entering-stylesheet;scope=*\r\n"
88 "link: <transition1.css>;rel=transition-entering-stylesheet;scope=*\r\n"
89 "link: <transition2.css>;rel=transition-entering-stylesheet;scope=*\r\n"
91 scoped_refptr
<net::HttpResponseHeaders
> headers(
92 new net::HttpResponseHeaders(net::HttpUtil::AssembleRawHeaders(
93 headers_string
, sizeof(headers_string
))));
95 TransitionRequestManager::ParseTransitionStylesheetsFromHeaders(
96 headers
, entering_stylesheets
, url
);
97 ASSERT_TRUE(entering_stylesheets
.size() == 3);
98 ASSERT_STREQ((url
.spec() + "transition0.css").c_str(),
99 entering_stylesheets
[0].spec().c_str());
100 ASSERT_STREQ((url
.spec() + "transition1.css").c_str(),
101 entering_stylesheets
[1].spec().c_str());
102 ASSERT_STREQ((url
.spec() + "transition2.css").c_str(),
103 entering_stylesheets
[2].spec().c_str());
106 } // namespace content