Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "net/websockets/websocket_stream.h" | 5 #include "net/websockets/websocket_stream.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 const std::string& extra_request_headers, | 117 const std::string& extra_request_headers, |
| 118 const std::string& response_body, | 118 const std::string& response_body, |
| 119 scoped_ptr<base::Timer> timer = scoped_ptr<base::Timer>()) { | 119 scoped_ptr<base::Timer> timer = scoped_ptr<base::Timer>()) { |
| 120 url_request_context_host_.SetExpectations( | 120 url_request_context_host_.SetExpectations( |
| 121 WebSocketStandardRequest(socket_path, socket_host, origin, | 121 WebSocketStandardRequest(socket_path, socket_host, origin, |
| 122 extra_request_headers), | 122 extra_request_headers), |
| 123 response_body); | 123 response_body); |
| 124 CreateAndConnectStream(socket_url, sub_protocols, origin, timer.Pass()); | 124 CreateAndConnectStream(socket_url, sub_protocols, origin, timer.Pass()); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void CreateAndConnectCustomResponseWithCookies( | |
| 128 const std::string& socket_url, | |
| 129 const std::string& socket_host, | |
| 130 const std::string& socket_path, | |
|
Ryan Sleevi
2015/01/24 04:13:07
Why is this not simply a single GURL?
[edit: I gu
Adam Rice
2015/01/26 06:38:59
Because then both the production code and the test
Ryan Sleevi
2015/01/27 00:47:22
I'm sorry, I don't understand this?
It's not your
Adam Rice
2015/01/27 06:32:46
In principle, yes. However, if the implementation
Ryan Sleevi
2015/01/27 22:28:10
Because quality matters. Because I've had to deal
| |
| 131 const std::vector<std::string>& sub_protocols, | |
| 132 const std::string& origin, | |
| 133 const std::string& cookies, | |
| 134 const std::string& extra_request_headers, | |
| 135 const std::string& response_body, | |
| 136 scoped_ptr<base::Timer> timer = scoped_ptr<base::Timer>()) { | |
| 137 url_request_context_host_.SetExpectations( | |
| 138 WebSocketStandardRequestWithCookies(socket_path, socket_host, origin, | |
| 139 cookies, extra_request_headers), | |
| 140 response_body); | |
| 141 CreateAndConnectStream(socket_url, sub_protocols, origin, timer.Pass()); | |
| 142 } | |
| 143 | |
| 127 // |extra_request_headers| and |extra_response_headers| must end in "\r\n" or | 144 // |extra_request_headers| and |extra_response_headers| must end in "\r\n" or |
| 128 // errors like "Unable to perform synchronous IO while stopped" will occur. | 145 // errors like "Unable to perform synchronous IO while stopped" will occur. |
| 129 void CreateAndConnectStandard( | 146 void CreateAndConnectStandard( |
| 130 const std::string& socket_url, | 147 const std::string& socket_url, |
| 131 const std::string& socket_host, | 148 const std::string& socket_host, |
| 132 const std::string& socket_path, | 149 const std::string& socket_path, |
| 133 const std::vector<std::string>& sub_protocols, | 150 const std::vector<std::string>& sub_protocols, |
| 134 const std::string& origin, | 151 const std::string& origin, |
| 135 const std::string& extra_request_headers, | 152 const std::string& extra_request_headers, |
| 136 const std::string& extra_response_headers, | 153 const std::string& extra_response_headers, |
| 137 scoped_ptr<base::Timer> timer = scoped_ptr<base::Timer>()) { | 154 scoped_ptr<base::Timer> timer = scoped_ptr<base::Timer>()) { |
| 138 CreateAndConnectCustomResponse( | 155 CreateAndConnectCustomResponse( |
| 139 socket_url, socket_host, socket_path, sub_protocols, origin, | 156 socket_url, socket_host, socket_path, sub_protocols, origin, |
| 140 extra_request_headers, | 157 extra_request_headers, |
| 141 WebSocketStandardResponse(extra_response_headers), timer.Pass()); | 158 WebSocketStandardResponse(extra_response_headers), timer.Pass()); |
| 142 } | 159 } |
| 143 | 160 |
| 161 // |cookies| must be empty or end with "\r\n". | |
| 162 // |extra_request_headers| and |extra_response_headers| must end in "\r\n" or | |
| 163 // errors like "Unable to perform synchronous IO while stopped" will occur. | |
|
Ryan Sleevi
2015/01/24 04:13:08
Both of these seem undesirable. Can this be expres
Adam Rice
2015/01/26 06:38:59
How? We can't make compile-time assertions about t
Ryan Sleevi
2015/01/27 00:47:22
It seems entirely pointless to require "" or "some
Adam Rice
2015/01/27 06:32:46
That's logic. Logic requires tests. At some point
Ryan Sleevi
2015/01/27 22:28:10
I'm sorry, I really have to disagree with you on y
| |
| 164 void CreateAndConnectStandardWithCookies( | |
| 165 const std::string& socket_url, | |
| 166 const std::string& socket_host, | |
| 167 const std::string& socket_path, | |
| 168 const std::vector<std::string>& sub_protocols, | |
| 169 const std::string& origin, | |
| 170 const std::string& cookies, | |
| 171 const std::string& extra_request_headers, | |
| 172 const std::string& extra_response_headers, | |
| 173 scoped_ptr<base::Timer> timer = scoped_ptr<base::Timer>()) { | |
| 174 CreateAndConnectCustomResponseWithCookies( | |
| 175 socket_url, socket_host, socket_path, sub_protocols, origin, cookies, | |
| 176 extra_request_headers, | |
| 177 WebSocketStandardResponse(extra_response_headers), timer.Pass()); | |
| 178 } | |
| 179 | |
| 144 void CreateAndConnectRawExpectations( | 180 void CreateAndConnectRawExpectations( |
| 145 const std::string& socket_url, | 181 const std::string& socket_url, |
| 146 const std::vector<std::string>& sub_protocols, | 182 const std::vector<std::string>& sub_protocols, |
| 147 const std::string& origin, | 183 const std::string& origin, |
| 148 scoped_ptr<DeterministicSocketData> socket_data, | 184 scoped_ptr<DeterministicSocketData> socket_data, |
| 149 scoped_ptr<base::Timer> timer = scoped_ptr<base::Timer>()) { | 185 scoped_ptr<base::Timer> timer = scoped_ptr<base::Timer>()) { |
| 150 AddRawExpectations(socket_data.Pass()); | 186 AddRawExpectations(socket_data.Pass()); |
| 151 CreateAndConnectStream(socket_url, sub_protocols, origin, timer.Pass()); | 187 CreateAndConnectStream(socket_url, sub_protocols, origin, timer.Pass()); |
| 152 } | 188 } |
| 153 | 189 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 409 }; | 445 }; |
| 410 | 446 |
| 411 scoped_ptr<base::HistogramSamples> GetSamples(const std::string& name) { | 447 scoped_ptr<base::HistogramSamples> GetSamples(const std::string& name) { |
| 412 base::HistogramBase* histogram = | 448 base::HistogramBase* histogram = |
| 413 base::StatisticsRecorder::FindHistogram(name); | 449 base::StatisticsRecorder::FindHistogram(name); |
| 414 return histogram ? histogram->SnapshotSamples() | 450 return histogram ? histogram->SnapshotSamples() |
| 415 : scoped_ptr<base::HistogramSamples>(); | 451 : scoped_ptr<base::HistogramSamples>(); |
| 416 } | 452 } |
| 417 }; | 453 }; |
| 418 | 454 |
| 455 struct WebSocketStreamUseCookieTestParameter { | |
|
Ryan Sleevi
2015/01/24 04:13:08
Document & Pluralize (Parameters)
| |
| 456 WebSocketStreamUseCookieTestParameter(const GURL& url, | |
|
Ryan Sleevi
2015/01/24 04:13:07
Document
| |
| 457 const GURL& cookie_url, | |
| 458 const std::string& origin, | |
| 459 const std::string& cookie_line, | |
| 460 const std::string& cookies) | |
| 461 : url(url), | |
| 462 cookie_url(cookie_url), | |
| 463 origin(origin), | |
| 464 cookie_line(cookie_line), | |
| 465 cookies(cookies) {} | |
| 466 | |
| 467 const GURL url; | |
| 468 const GURL cookie_url; | |
| 469 const std::string origin; | |
| 470 const std::string cookie_line; | |
| 471 const std::string cookies; | |
|
Ryan Sleevi
2015/01/24 04:13:07
Making these const prevents operator=, which would
| |
| 472 }; | |
| 473 | |
| 474 class WebSocketStreamUseCookieTest | |
| 475 : public WebSocketStreamCreateTest, | |
| 476 public ::testing::WithParamInterface< | |
| 477 WebSocketStreamUseCookieTestParameter> { | |
| 478 public: | |
| 479 void SetCookie(CookieStore* store, | |
| 480 const GURL& url, | |
| 481 const std::string& cookie_line) { | |
| 482 class RunLoop { | |
|
Ryan Sleevi
2015/01/24 04:13:07
This is deeply confusing, because it shadows a nam
| |
| 483 public: | |
| 484 void Run() { run_loop_.Run(); } | |
| 485 void Quit(bool) { run_loop_.Quit(); } | |
| 486 | |
| 487 private: | |
| 488 base::RunLoop run_loop_; | |
| 489 }; | |
| 490 | |
| 491 RunLoop run_loop; | |
| 492 store->SetCookieWithOptionsAsync( | |
| 493 url, cookie_line, CookieOptions(), | |
| 494 base::Bind(&RunLoop::Quit, base::Unretained(&run_loop))); | |
|
Ryan Sleevi
2015/01/24 04:13:07
You should be using https://code.google.com/p/chro
Adam Rice
2015/01/26 06:38:59
We need to swallow the bool parameter that SetCook
Ryan Sleevi
2015/01/27 00:47:22
Then just use a bound free function
static void I
| |
| 495 run_loop.Run(); | |
| 496 } | |
| 497 }; | |
| 498 | |
| 499 class WebSocketStreamSetCookieTest | |
| 500 : public WebSocketStreamCreateTest, | |
| 501 public ::testing::WithParamInterface< | |
| 502 WebSocketStreamUseCookieTestParameter> { | |
| 503 public: | |
| 504 std::string GetCookies(CookieStore* store, const GURL& url) { | |
| 505 struct GetCookiesHelper { | |
| 506 void Run() { run_loop_.Run(); } | |
| 507 void Quit(const std::string& cookies) { | |
| 508 cookies_ = cookies; | |
| 509 run_loop_.Quit(); | |
| 510 } | |
| 511 | |
| 512 const std::string& cookies() const { return cookies_; } | |
| 513 | |
| 514 private: | |
| 515 base::RunLoop run_loop_; | |
| 516 std::string cookies_; | |
| 517 }; | |
| 518 GetCookiesHelper helper; | |
| 519 | |
| 520 store->GetCookiesWithOptionsAsync( | |
| 521 url, CookieOptions(), | |
| 522 base::Bind(&GetCookiesHelper::Quit, base::Unretained(&helper))); | |
|
Ryan Sleevi
2015/01/24 04:13:08
static void StashCookiesHelper(const base::Closure
| |
| 523 helper.Run(); | |
| 524 return helper.cookies(); | |
| 525 } | |
| 526 }; | |
| 527 | |
| 419 // Confirm that the basic case works as expected. | 528 // Confirm that the basic case works as expected. |
| 420 TEST_F(WebSocketStreamCreateTest, SimpleSuccess) { | 529 TEST_F(WebSocketStreamCreateTest, SimpleSuccess) { |
| 421 CreateAndConnectStandard("ws://localhost/", "localhost", "/", | 530 CreateAndConnectStandard("ws://localhost/", "localhost", "/", |
| 422 NoSubProtocols(), "http://localhost", "", ""); | 531 NoSubProtocols(), "http://localhost", "", ""); |
| 423 EXPECT_FALSE(request_info_); | 532 EXPECT_FALSE(request_info_); |
| 424 EXPECT_FALSE(response_info_); | 533 EXPECT_FALSE(response_info_); |
| 425 RunUntilIdle(); | 534 RunUntilIdle(); |
| 426 EXPECT_FALSE(has_failed()); | 535 EXPECT_FALSE(has_failed()); |
| 427 EXPECT_TRUE(stream_); | 536 EXPECT_TRUE(stream_); |
| 428 EXPECT_TRUE(request_info_); | 537 EXPECT_TRUE(request_info_); |
| (...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1374 scoped_ptr<base::HistogramSamples> samples(GetSamples(name)); | 1483 scoped_ptr<base::HistogramSamples> samples(GetSamples(name)); |
| 1375 ASSERT_TRUE(samples); | 1484 ASSERT_TRUE(samples); |
| 1376 if (original) { | 1485 if (original) { |
| 1377 samples->Subtract(*original); // Cancel the original values. | 1486 samples->Subtract(*original); // Cancel the original values. |
| 1378 } | 1487 } |
| 1379 EXPECT_EQ(1, samples->GetCount(INCOMPLETE)); | 1488 EXPECT_EQ(1, samples->GetCount(INCOMPLETE)); |
| 1380 EXPECT_EQ(0, samples->GetCount(CONNECTED)); | 1489 EXPECT_EQ(0, samples->GetCount(CONNECTED)); |
| 1381 EXPECT_EQ(0, samples->GetCount(FAILED)); | 1490 EXPECT_EQ(0, samples->GetCount(FAILED)); |
| 1382 } | 1491 } |
| 1383 | 1492 |
| 1493 TEST_P(WebSocketStreamUseCookieTest, UseCookie) { | |
| 1494 // In case we use a TLS connection. | |
|
Ryan Sleevi
2015/01/24 04:13:07
This comment doesn't make sense. It sounds like yo
| |
| 1495 ssl_data_.push_back(new SSLSocketDataProvider(ASYNC, OK)); | |
| 1496 | |
| 1497 CookieStore* store = | |
| 1498 url_request_context_host_.GetURLRequestContext()->cookie_store(); | |
| 1499 | |
| 1500 const GURL& url = GetParam().url; | |
| 1501 const GURL& cookie_url = GetParam().cookie_url; | |
| 1502 const std::string& origin = GetParam().origin; | |
| 1503 const std::string& cookie_line = GetParam().cookie_line; | |
| 1504 const std::string& cookies = GetParam().cookies; | |
| 1505 | |
| 1506 SetCookie(store, cookie_url, cookie_line); | |
| 1507 | |
| 1508 CreateAndConnectStandardWithCookies(url.spec(), url.host(), url.path(), | |
| 1509 NoSubProtocols(), origin, cookies, "", | |
| 1510 ""); | |
|
Ryan Sleevi
2015/01/24 04:13:08
s/""/std::string()/
| |
| 1511 | |
| 1512 RunUntilIdle(); | |
| 1513 EXPECT_FALSE(has_failed()); | |
| 1514 } | |
| 1515 | |
| 1516 INSTANTIATE_TEST_CASE_P( | |
| 1517 WebSocketStreamUseCookieTest, | |
| 1518 WebSocketStreamUseCookieTest, | |
| 1519 ::testing::Values( | |
| 1520 // Non-secure cookies for ws | |
| 1521 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
|
Ryan Sleevi
2015/01/24 04:13:07
If you deal with the constness I mentioned above,
yhirano
2015/01/26 07:01:40
IIUC having constant members is not related to ini
Ryan Sleevi
2015/01/27 00:47:22
Using { } to initialize POD structs is not a C++11
Adam Rice
2015/01/27 06:32:46
Indeed. Brace-initialisation of function arguments
Ryan Sleevi
2015/01/27 22:28:10
This hasn't applied to unit tests historically, bu
| |
| 1522 GURL("http://www.example.com"), | |
| 1523 "http://www.example.com", | |
| 1524 "test-cookie", | |
| 1525 "Cookie: test-cookie\r\n"), | |
|
Ryan Sleevi
2015/01/24 04:13:08
The amount of copy-pasta for thees \r\n makes it s
| |
| 1526 | |
| 1527 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1528 GURL("https://www.example.com"), | |
| 1529 "http://www.example.com", | |
| 1530 "test-cookie", | |
| 1531 "Cookie: test-cookie\r\n"), | |
| 1532 | |
| 1533 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1534 GURL("ws://www.example.com"), | |
| 1535 "http://www.example.com", | |
| 1536 "test-cookie", | |
| 1537 "Cookie: test-cookie\r\n"), | |
| 1538 | |
| 1539 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1540 GURL("wss://www.example.com"), | |
| 1541 "http://www.example.com", | |
| 1542 "test-cookie", | |
| 1543 "Cookie: test-cookie\r\n"), | |
| 1544 | |
| 1545 // Non-secure cookies for wss | |
| 1546 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1547 GURL("http://www.example.com"), | |
| 1548 "https://www.example.com", | |
| 1549 "test-cookie", | |
| 1550 "Cookie: test-cookie\r\n"), | |
| 1551 | |
| 1552 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1553 GURL("https://www.example.com"), | |
| 1554 "https://www.example.com", | |
| 1555 "test-cookie", | |
| 1556 "Cookie: test-cookie\r\n"), | |
| 1557 | |
| 1558 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1559 GURL("ws://www.example.com"), | |
| 1560 "https://www.example.com", | |
| 1561 "test-cookie", | |
| 1562 "Cookie: test-cookie\r\n"), | |
| 1563 | |
| 1564 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1565 GURL("wss://www.example.com"), | |
| 1566 "https://www.example.com", | |
| 1567 "test-cookie", | |
| 1568 "Cookie: test-cookie\r\n"), | |
| 1569 | |
| 1570 // Secure-cookies for ws | |
| 1571 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1572 GURL("https://www.example.com"), | |
| 1573 "http://www.example.com", | |
| 1574 "test-cookie; secure", | |
| 1575 ""), | |
| 1576 | |
| 1577 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1578 GURL("wss://www.example.com"), | |
| 1579 "http://www.example.com", | |
| 1580 "test-cookie; secure", | |
| 1581 ""), | |
| 1582 | |
| 1583 // Secure-cookies for wss | |
| 1584 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1585 GURL("https://www.example.com"), | |
| 1586 "https://www.example.com", | |
| 1587 "test-cookie; secure", | |
| 1588 "Cookie: test-cookie\r\n"), | |
| 1589 | |
| 1590 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1591 GURL("wss://www.example.com"), | |
| 1592 "https://www.example.com", | |
| 1593 "test-cookie; secure", | |
| 1594 "Cookie: test-cookie\r\n"), | |
| 1595 | |
| 1596 // Non-secure cookies for ws (sharing domain) | |
| 1597 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1598 GURL("http://www2.example.com"), | |
| 1599 "http://www.example.com", | |
| 1600 "test-cookie; Domain=example.com", | |
| 1601 "Cookie: test-cookie\r\n"), | |
| 1602 | |
| 1603 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1604 GURL("https://www2.example.com"), | |
| 1605 "http://www.example.com", | |
| 1606 "test-cookie; Domain=example.com", | |
| 1607 "Cookie: test-cookie\r\n"), | |
| 1608 | |
| 1609 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1610 GURL("ws://www2.example.com"), | |
| 1611 "http://www.example.com", | |
| 1612 "test-cookie; Domain=example.com", | |
| 1613 "Cookie: test-cookie\r\n"), | |
| 1614 | |
| 1615 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1616 GURL("wss://www2.example.com"), | |
| 1617 "http://www.example.com", | |
| 1618 "test-cookie; Domain=example.com", | |
| 1619 "Cookie: test-cookie\r\n"), | |
| 1620 | |
| 1621 // Non-secure cookies for wss (sharing domain) | |
| 1622 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1623 GURL("http://www2.example.com"), | |
| 1624 "https://www.example.com", | |
| 1625 "test-cookie; Domain=example.com", | |
| 1626 "Cookie: test-cookie\r\n"), | |
| 1627 | |
| 1628 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1629 GURL("https://www2.example.com"), | |
| 1630 "https://www.example.com", | |
| 1631 "test-cookie; Domain=example.com", | |
| 1632 "Cookie: test-cookie\r\n"), | |
| 1633 | |
| 1634 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1635 GURL("ws://www2.example.com"), | |
| 1636 "https://www.example.com", | |
| 1637 "test-cookie; Domain=example.com", | |
| 1638 "Cookie: test-cookie\r\n"), | |
| 1639 | |
| 1640 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1641 GURL("wss://www2.example.com"), | |
| 1642 "https://www.example.com", | |
| 1643 "test-cookie; Domain=example.com", | |
| 1644 "Cookie: test-cookie\r\n"), | |
| 1645 | |
| 1646 // Secure-cookies for ws (sharing domain) | |
| 1647 WebSocketStreamUseCookieTestParameter( | |
| 1648 GURL("ws://www.example.com"), | |
| 1649 GURL("https://www2.example.com"), | |
| 1650 "http://www.example.com", | |
| 1651 "test-cookie; Domain=example.com; secure", | |
| 1652 ""), | |
|
Ryan Sleevi
2015/01/24 04:13:08
s/""/std::string()/
| |
| 1653 | |
| 1654 WebSocketStreamUseCookieTestParameter( | |
| 1655 GURL("ws://www.example.com"), | |
| 1656 GURL("wss://www2.example.com"), | |
| 1657 "http://www.example.com", | |
| 1658 "test-cookie; Domain=example.com; secure", | |
| 1659 ""), | |
| 1660 | |
| 1661 // Secure-cookies for wss (sharing domain) | |
| 1662 WebSocketStreamUseCookieTestParameter( | |
| 1663 GURL("wss://www.example.com"), | |
| 1664 GURL("https://www2.example.com"), | |
| 1665 "https://www.example.com", | |
| 1666 "test-cookie; Domain=example.com; secure", | |
| 1667 "Cookie: test-cookie\r\n"), | |
| 1668 | |
| 1669 WebSocketStreamUseCookieTestParameter( | |
| 1670 GURL("wss://www.example.com"), | |
| 1671 GURL("wss://www2.example.com"), | |
| 1672 "https://www.example.com", | |
| 1673 "test-cookie; Domain=example.com; secure", | |
| 1674 "Cookie: test-cookie\r\n"), | |
| 1675 | |
| 1676 // Non-matching cookies for ws | |
| 1677 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1678 GURL("http://www2.example.com"), | |
| 1679 "http://www.example.com", | |
| 1680 "test-cookie", | |
| 1681 ""), | |
| 1682 | |
| 1683 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1684 GURL("https://www2.example.com"), | |
| 1685 "http://www.example.com", | |
| 1686 "test-cookie", | |
| 1687 ""), | |
| 1688 | |
| 1689 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1690 GURL("ws://www2.example.com"), | |
| 1691 "http://www.example.com", | |
| 1692 "test-cookie", | |
| 1693 ""), | |
| 1694 | |
| 1695 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1696 GURL("wss://www2.example.com"), | |
| 1697 "http://www.example.com", | |
| 1698 "test-cookie", | |
| 1699 ""), | |
| 1700 | |
| 1701 // Non-matching cookies for wss | |
| 1702 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1703 GURL("http://www2.example.com"), | |
| 1704 "https://www.example.com", | |
| 1705 "test-cookie", | |
| 1706 ""), | |
| 1707 | |
| 1708 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1709 GURL("https://www2.example.com"), | |
| 1710 "https://www.example.com", | |
| 1711 "test-cookie", | |
| 1712 ""), | |
| 1713 | |
| 1714 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1715 GURL("ws://www2.example.com"), | |
| 1716 "https://www.example.com", | |
| 1717 "test-cookie", | |
| 1718 ""), | |
| 1719 | |
| 1720 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1721 GURL("wss://www2.example.com"), | |
| 1722 "https://www.example.com", | |
| 1723 "test-cookie", | |
| 1724 ""))); | |
| 1725 | |
| 1726 TEST_P(WebSocketStreamSetCookieTest, SetCookie) { | |
| 1727 // In case we use a TLS connection. | |
| 1728 ssl_data_.push_back(new SSLSocketDataProvider(ASYNC, OK)); | |
| 1729 | |
| 1730 const GURL& url = GetParam().url; | |
| 1731 const GURL& cookie_url = GetParam().cookie_url; | |
| 1732 const std::string& origin = GetParam().origin; | |
| 1733 const std::string& cookie_line = GetParam().cookie_line; | |
| 1734 const std::string& cookies = GetParam().cookies; | |
| 1735 | |
| 1736 const std::string response = base::StringPrintf( | |
| 1737 "HTTP/1.1 101 Switching Protocols\r\n" | |
| 1738 "Upgrade: websocket\r\n" | |
| 1739 "Connection: Upgrade\r\n" | |
| 1740 "%s" | |
| 1741 "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n" | |
| 1742 "\r\n", | |
| 1743 cookies.c_str()); | |
| 1744 | |
| 1745 CookieStore* store = | |
| 1746 url_request_context_host_.GetURLRequestContext()->cookie_store(); | |
| 1747 | |
| 1748 CreateAndConnectCustomResponse(url.spec(), url.host(), url.path(), | |
| 1749 NoSubProtocols(), origin, "", response); | |
| 1750 | |
| 1751 RunUntilIdle(); | |
| 1752 EXPECT_FALSE(has_failed()); | |
| 1753 | |
| 1754 EXPECT_EQ(cookie_line, GetCookies(store, cookie_url)); | |
| 1755 } | |
| 1756 | |
| 1757 INSTANTIATE_TEST_CASE_P( | |
| 1758 WebSocketStreamSetCookieTest, | |
| 1759 WebSocketStreamSetCookieTest, | |
| 1760 ::testing::Values( | |
| 1761 // Cookies for ws | |
|
Adam Rice
2015/01/23 12:58:00
Nitpick: the cookie comes *from* ws (or is "set by
| |
| 1762 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1763 GURL("http://www.example.com"), | |
| 1764 "http://www.example.com", | |
| 1765 "test-cookie", | |
| 1766 "Set-Cookie: test-cookie\r\n"), | |
| 1767 | |
| 1768 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1769 GURL("https://www.example.com"), | |
| 1770 "http://www.example.com", | |
| 1771 "test-cookie", | |
| 1772 "Set-Cookie: test-cookie\r\n"), | |
| 1773 | |
| 1774 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1775 GURL("ws://www.example.com"), | |
| 1776 "http://www.example.com", | |
| 1777 "test-cookie", | |
| 1778 "Set-Cookie: test-cookie\r\n"), | |
| 1779 | |
| 1780 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1781 GURL("wss://www.example.com"), | |
| 1782 "http://www.example.com", | |
| 1783 "test-cookie", | |
| 1784 "Set-Cookie: test-cookie\r\n"), | |
| 1785 | |
| 1786 // Cookies for wss | |
|
Adam Rice
2015/01/23 12:58:00
Maybe we should test that the "Secure" attribute w
| |
| 1787 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1788 GURL("http://www.example.com"), | |
| 1789 "https://www.example.com", | |
| 1790 "test-cookie", | |
| 1791 "Set-Cookie: test-cookie\r\n"), | |
| 1792 | |
| 1793 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1794 GURL("https://www.example.com"), | |
| 1795 "https://www.example.com", | |
| 1796 "test-cookie", | |
| 1797 "Set-Cookie: test-cookie\r\n"), | |
| 1798 | |
| 1799 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1800 GURL("ws://www.example.com"), | |
| 1801 "https://www.example.com", | |
| 1802 "test-cookie", | |
| 1803 "Set-Cookie: test-cookie\r\n"), | |
| 1804 | |
| 1805 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1806 GURL("wss://www.example.com"), | |
| 1807 "https://www.example.com", | |
| 1808 "test-cookie", | |
| 1809 "Set-Cookie: test-cookie\r\n"), | |
| 1810 | |
| 1811 // cookies for ws (sharing domain) | |
| 1812 WebSocketStreamUseCookieTestParameter( | |
| 1813 GURL("ws://www.example.com"), | |
| 1814 GURL("http://www2.example.com"), | |
| 1815 "http://www.example.com", | |
| 1816 "test-cookie", | |
| 1817 "Set-Cookie: test-cookie; Domain=example.com\r\n"), | |
| 1818 | |
| 1819 WebSocketStreamUseCookieTestParameter( | |
| 1820 GURL("ws://www.example.com"), | |
| 1821 GURL("https://www2.example.com"), | |
| 1822 "http://www.example.com", | |
| 1823 "test-cookie", | |
| 1824 "Set-Cookie: test-cookie; Domain=example.com\r\n"), | |
| 1825 | |
| 1826 WebSocketStreamUseCookieTestParameter( | |
| 1827 GURL("ws://www.example.com"), | |
| 1828 GURL("ws://www2.example.com"), | |
| 1829 "http://www.example.com", | |
| 1830 "test-cookie", | |
| 1831 "Set-Cookie: test-cookie; Domain=example.com\r\n"), | |
| 1832 | |
| 1833 WebSocketStreamUseCookieTestParameter( | |
| 1834 GURL("ws://www.example.com"), | |
| 1835 GURL("wss://www2.example.com"), | |
| 1836 "http://www.example.com", | |
| 1837 "test-cookie", | |
| 1838 "Set-Cookie: test-cookie; Domain=example.com\r\n"), | |
| 1839 | |
| 1840 // cookies for wss (sharing domain) | |
| 1841 WebSocketStreamUseCookieTestParameter( | |
| 1842 GURL("wss://www.example.com"), | |
| 1843 GURL("http://www2.example.com"), | |
| 1844 "https://www.example.com", | |
| 1845 "test-cookie", | |
| 1846 "Set-Cookie: test-cookie; Domain=example.com\r\n"), | |
| 1847 | |
| 1848 WebSocketStreamUseCookieTestParameter( | |
| 1849 GURL("wss://www.example.com"), | |
| 1850 GURL("https://www2.example.com"), | |
| 1851 "https://www.example.com", | |
| 1852 "test-cookie", | |
| 1853 "Set-Cookie: test-cookie; Domain=example.com\r\n"), | |
| 1854 | |
| 1855 WebSocketStreamUseCookieTestParameter( | |
| 1856 GURL("wss://www.example.com"), | |
| 1857 GURL("ws://www2.example.com"), | |
| 1858 "https://www.example.com", | |
| 1859 "test-cookie", | |
| 1860 "Set-Cookie: test-cookie; Domain=example.com\r\n"), | |
| 1861 | |
| 1862 WebSocketStreamUseCookieTestParameter( | |
| 1863 GURL("wss://www.example.com"), | |
| 1864 GURL("wss://www2.example.com"), | |
| 1865 "https://www.example.com", | |
| 1866 "test-cookie", | |
| 1867 "Set-Cookie: test-cookie; Domain=example.com\r\n"), | |
| 1868 | |
| 1869 // Non-matching cookies for ws | |
| 1870 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1871 GURL("http://www2.example.com"), | |
| 1872 "http://www.example.com", | |
| 1873 "", | |
| 1874 "Set-Cookie: test-cookie\r\n"), | |
| 1875 | |
| 1876 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1877 GURL("https://www2.example.com"), | |
| 1878 "http://www.example.com", | |
| 1879 "", | |
| 1880 "Set-Cookie: test-cookie\r\n"), | |
| 1881 | |
| 1882 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1883 GURL("ws://www2.example.com"), | |
| 1884 "http://www.example.com", | |
| 1885 "", | |
| 1886 "Set-Cookie: test-cookie\r\n"), | |
| 1887 | |
| 1888 WebSocketStreamUseCookieTestParameter(GURL("ws://www.example.com"), | |
| 1889 GURL("wss://www2.example.com"), | |
| 1890 "http://www.example.com", | |
| 1891 "", | |
| 1892 "Set-Cookie: test-cookie\r\n"), | |
| 1893 | |
| 1894 // Non-matching cookies for wss | |
| 1895 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1896 GURL("http://www2.example.com"), | |
| 1897 "https://www.example.com", | |
| 1898 "", | |
| 1899 "Set-Cookie: test-cookie\r\n"), | |
| 1900 | |
| 1901 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1902 GURL("https://www2.example.com"), | |
| 1903 "https://www.example.com", | |
| 1904 "", | |
| 1905 "Set-Cookie: test-cookie\r\n"), | |
| 1906 | |
| 1907 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1908 GURL("ws://www2.example.com"), | |
| 1909 "https://www.example.com", | |
| 1910 "", | |
| 1911 "Set-Cookie: test-cookie\r\n"), | |
| 1912 | |
| 1913 WebSocketStreamUseCookieTestParameter(GURL("wss://www.example.com"), | |
| 1914 GURL("wss://www2.example.com"), | |
| 1915 "https://www.example.com", | |
| 1916 "", | |
| 1917 "Set-Cookie: test-cookie\r\n"))); | |
| 1918 | |
| 1384 } // namespace | 1919 } // namespace |
| 1385 } // namespace net | 1920 } // namespace net |
| OLD | NEW |