| Index: content/browser/browsing_data/clear_site_data_throttle_unittest.cc
|
| diff --git a/content/browser/browsing_data/clear_site_data_throttle_unittest.cc b/content/browser/browsing_data/clear_site_data_throttle_unittest.cc
|
| index bdfa8fad3d519996800691f6526b3e3ad320f0f1..1cd5ff7a4b8a05f70c011a30574876be174e7d93 100644
|
| --- a/content/browser/browsing_data/clear_site_data_throttle_unittest.cc
|
| +++ b/content/browser/browsing_data/clear_site_data_throttle_unittest.cc
|
| @@ -7,7 +7,12 @@
|
| #include <memory>
|
|
|
| #include "base/command_line.h"
|
| +#include "base/message_loop/message_loop.h"
|
| +#include "base/test/scoped_command_line.h"
|
| +#include "content/common/net/url_request_service_worker_data.h"
|
| #include "content/public/common/content_switches.h"
|
| +#include "net/base/load_flags.h"
|
| +#include "net/url_request/url_request_test_util.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -15,20 +20,55 @@ namespace content {
|
|
|
| class ClearSiteDataThrottleTest : public testing::Test {
|
| public:
|
| - void SetUp() override {
|
| - base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kEnableExperimentalWebPlatformFeatures);
|
| - throttle_ = ClearSiteDataThrottle::CreateThrottleForNavigation(nullptr);
|
| - }
|
| + void SetUp() override { throttle_.reset(new ClearSiteDataThrottle(nullptr)); }
|
|
|
| ClearSiteDataThrottle* GetThrottle() {
|
| return static_cast<ClearSiteDataThrottle*>(throttle_.get());
|
| }
|
|
|
| private:
|
| - std::unique_ptr<NavigationThrottle> throttle_;
|
| + base::MessageLoop message_loop_;
|
| + std::unique_ptr<ResourceThrottle> throttle_;
|
| };
|
|
|
| +TEST_F(ClearSiteDataThrottleTest, CreateThrottleForRequest) {
|
| + // Enable experimental features.
|
| + std::unique_ptr<base::test::ScopedCommandLine> command_line(
|
| + new base::test::ScopedCommandLine());
|
| + command_line->GetProcessCommandLine()->AppendSwitch(
|
| + switches::kEnableExperimentalWebPlatformFeatures);
|
| +
|
| + // Create a URL request.
|
| + GURL url("https://www.example.com");
|
| + net::TestURLRequestContext context;
|
| + std::unique_ptr<net::URLRequest> request(
|
| + context.CreateRequest(url, net::DEFAULT_PRIORITY, nullptr));
|
| +
|
| + // We will not create the throttle for an empty ResourceRequestInfo.
|
| + EXPECT_FALSE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get()));
|
| +
|
| + // We can create the throttle for a valid ResourceRequestInfo.
|
| + ResourceRequestInfo::AllocateForTesting(request.get(), RESOURCE_TYPE_IMAGE,
|
| + nullptr, 0, 0, 0, false, true, true,
|
| + true, false);
|
| + EXPECT_TRUE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get()));
|
| +
|
| + // We won't create the throttle for service worker requests.
|
| + request->SetUserData(URLRequestServiceWorkerData::kUserDataKey,
|
| + new URLRequestServiceWorkerData());
|
| + EXPECT_FALSE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get()));
|
| +
|
| + // Nor will we for LOAD_DO_NOT_SAVE_COOKIES requests.
|
| + request->RemoveUserData(URLRequestServiceWorkerData::kUserDataKey);
|
| + request->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES);
|
| + EXPECT_FALSE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get()));
|
| +
|
| + // Nor if experimental web features are disabled.
|
| + request->SetLoadFlags(net::LOAD_NORMAL);
|
| + command_line.reset();
|
| + EXPECT_FALSE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get()));
|
| +}
|
| +
|
| TEST_F(ClearSiteDataThrottleTest, ParseHeader) {
|
| struct TestCase {
|
| const char* header;
|
|
|