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 <stddef.h> | 5 #include <stddef.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 // Disable auto-attach. | 1441 // Disable auto-attach. |
1442 command_params.reset(new base::DictionaryValue()); | 1442 command_params.reset(new base::DictionaryValue()); |
1443 command_params->SetBoolean("autoAttach", false); | 1443 command_params->SetBoolean("autoAttach", false); |
1444 command_params->SetBoolean("waitForDebuggerOnStart", false); | 1444 command_params->SetBoolean("waitForDebuggerOnStart", false); |
1445 SendCommand("Target.setAutoAttach", std::move(command_params), false); | 1445 SendCommand("Target.setAutoAttach", std::move(command_params), false); |
1446 params = WaitForNotification("Target.detachedFromTarget", true); | 1446 params = WaitForNotification("Target.detachedFromTarget", true); |
1447 EXPECT_TRUE(params->GetString("targetId", &temp)); | 1447 EXPECT_TRUE(params->GetString("targetId", &temp)); |
1448 EXPECT_EQ(target_id, temp); | 1448 EXPECT_EQ(target_id, temp); |
1449 } | 1449 } |
1450 | 1450 |
| 1451 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, SetAndGetCookies) { |
| 1452 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1453 GURL test_url = embedded_test_server()->GetURL("/title1.html"); |
| 1454 NavigateToURLBlockUntilNavigationsComplete(shell(), test_url, 1); |
| 1455 Attach(); |
| 1456 |
| 1457 // Set two cookies, one of which matches the loaded URL and another that |
| 1458 // doesn't. |
| 1459 std::unique_ptr<base::DictionaryValue> command_params; |
| 1460 command_params.reset(new base::DictionaryValue()); |
| 1461 command_params->SetString("url", test_url.spec()); |
| 1462 command_params->SetString("name", "cookie_for_this_url"); |
| 1463 command_params->SetString("value", "mendacious"); |
| 1464 SendCommand("Network.setCookie", std::move(command_params), false); |
| 1465 |
| 1466 command_params.reset(new base::DictionaryValue()); |
| 1467 command_params->SetString("url", "https://www.chromium.org"); |
| 1468 command_params->SetString("name", "cookie_for_another_url"); |
| 1469 command_params->SetString("value", "polyglottal"); |
| 1470 SendCommand("Network.setCookie", std::move(command_params), false); |
| 1471 |
| 1472 // First get the cookies for just the loaded URL. |
| 1473 SendCommand("Network.getCookies", nullptr, true); |
| 1474 |
| 1475 base::ListValue* cookies; |
| 1476 EXPECT_TRUE(result_->HasKey("cookies")); |
| 1477 EXPECT_TRUE(result_->GetList("cookies", &cookies)); |
| 1478 EXPECT_EQ(1u, cookies->GetSize()); |
| 1479 |
| 1480 base::DictionaryValue* cookie; |
| 1481 std::string name; |
| 1482 std::string value; |
| 1483 EXPECT_TRUE(cookies->GetDictionary(0, &cookie)); |
| 1484 EXPECT_TRUE(cookie->GetString("name", &name)); |
| 1485 EXPECT_TRUE(cookie->GetString("value", &value)); |
| 1486 EXPECT_EQ("cookie_for_this_url", name); |
| 1487 EXPECT_EQ("mendacious", value); |
| 1488 |
| 1489 // Then get all the cookies in the cookie jar. |
| 1490 command_params.reset(new base::DictionaryValue()); |
| 1491 command_params->SetBoolean("global", true); |
| 1492 SendCommand("Network.getCookies", std::move(command_params), true); |
| 1493 |
| 1494 EXPECT_TRUE(result_->HasKey("cookies")); |
| 1495 EXPECT_TRUE(result_->GetList("cookies", &cookies)); |
| 1496 EXPECT_EQ(2u, cookies->GetSize()); |
| 1497 |
| 1498 // Note: the cookies will be returned in unspecified order. |
| 1499 size_t found = 0; |
| 1500 for (size_t i = 0; i < cookies->GetSize(); i++) { |
| 1501 EXPECT_TRUE(cookies->GetDictionary(i, &cookie)); |
| 1502 EXPECT_TRUE(cookie->GetString("name", &name)); |
| 1503 if (name == "cookie_for_this_url") { |
| 1504 EXPECT_TRUE(cookie->GetString("value", &value)); |
| 1505 EXPECT_EQ("mendacious", value); |
| 1506 found++; |
| 1507 } else if (name == "cookie_for_another_url") { |
| 1508 EXPECT_TRUE(cookie->GetString("value", &value)); |
| 1509 EXPECT_EQ("polyglottal", value); |
| 1510 found++; |
| 1511 } else { |
| 1512 FAIL(); |
| 1513 } |
| 1514 } |
| 1515 EXPECT_EQ(2u, found); |
| 1516 } |
| 1517 |
1451 } // namespace content | 1518 } // namespace content |
OLD | NEW |