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

Side by Side Diff: content/browser/devtools/protocol/devtools_protocol_browsertest.cc

Issue 2554293002: devtools: Make it possible to retrieve all cookies (Closed)
Patch Set: 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 | content/browser/devtools/protocol/network_handler.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 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
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 EXPECT_TRUE(cookies->GetDictionary(0, &cookie));
dgozman 2016/12/07 19:25:05 Bots show that order is unpredictable here :-)
Sami 2016/12/08 10:52:10 So it seems :) Fixed.
1499 EXPECT_TRUE(cookie->GetString("name", &name));
1500 EXPECT_TRUE(cookie->GetString("value", &value));
1501 EXPECT_EQ("cookie_for_this_url", name);
1502 EXPECT_EQ("mendacious", value);
1503
1504 EXPECT_TRUE(cookies->GetDictionary(1, &cookie));
1505 EXPECT_TRUE(cookie->GetString("name", &name));
1506 EXPECT_TRUE(cookie->GetString("value", &value));
1507 EXPECT_EQ("cookie_for_another_url", name);
1508 EXPECT_EQ("polyglottal", value);
1509 }
1510
1451 } // namespace content 1511 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/devtools/protocol/network_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698