Chromium Code Reviews| 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..1911a6ab03d19880c8076bcf2f8354f4e98d987f 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,45 @@ 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())); |
| + |
| + // But not if experimental web features are disabled again. |
| + request->SetLoadFlags(net::LOAD_NORMAL); |
| + command_line.reset(); |
| + EXPECT_FALSE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get())); |
| +} |
| + |
| TEST_F(ClearSiteDataThrottleTest, ParseHeader) { |
|
mmenke
2016/10/21 15:16:21
We don't have any tests of the deferring behavior,
mmenke
2016/10/21 15:16:21
I suggest making all these tests more integration-
msramek
2016/10/31 19:23:36
I disassembled ClearSiteDataThrottle a bit to make
mmenke
2016/11/08 18:23:59
Hrm...That seems a little weird. From a layering
|
| struct TestCase { |
| const char* header; |