| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/browsing_data/clear_site_data_throttle.h" | 5 #include "content/browser/browsing_data/clear_site_data_throttle.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/test/scoped_command_line.h" |
| 12 #include "content/common/net/url_request_service_worker_data.h" |
| 10 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "net/base/load_flags.h" |
| 15 #include "net/url_request/url_request_test_util.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 18 |
| 14 namespace content { | 19 namespace content { |
| 15 | 20 |
| 16 class ClearSiteDataThrottleTest : public testing::Test { | 21 class ClearSiteDataThrottleTest : public testing::Test { |
| 17 public: | 22 public: |
| 18 void SetUp() override { | 23 void SetUp() override { throttle_.reset(new ClearSiteDataThrottle(nullptr)); } |
| 19 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 20 switches::kEnableExperimentalWebPlatformFeatures); | |
| 21 throttle_ = ClearSiteDataThrottle::CreateThrottleForNavigation(nullptr); | |
| 22 } | |
| 23 | 24 |
| 24 ClearSiteDataThrottle* GetThrottle() { | 25 ClearSiteDataThrottle* GetThrottle() { |
| 25 return static_cast<ClearSiteDataThrottle*>(throttle_.get()); | 26 return static_cast<ClearSiteDataThrottle*>(throttle_.get()); |
| 26 } | 27 } |
| 27 | 28 |
| 28 private: | 29 private: |
| 29 std::unique_ptr<NavigationThrottle> throttle_; | 30 base::MessageLoop message_loop_; |
| 31 std::unique_ptr<ResourceThrottle> throttle_; |
| 30 }; | 32 }; |
| 31 | 33 |
| 34 TEST_F(ClearSiteDataThrottleTest, CreateThrottleForRequest) { |
| 35 // Enable experimental features. |
| 36 std::unique_ptr<base::test::ScopedCommandLine> command_line( |
| 37 new base::test::ScopedCommandLine()); |
| 38 command_line->GetProcessCommandLine()->AppendSwitch( |
| 39 switches::kEnableExperimentalWebPlatformFeatures); |
| 40 |
| 41 // Create a URL request. |
| 42 GURL url("https://www.example.com"); |
| 43 net::TestURLRequestContext context; |
| 44 std::unique_ptr<net::URLRequest> request( |
| 45 context.CreateRequest(url, net::DEFAULT_PRIORITY, nullptr)); |
| 46 |
| 47 // We will not create the throttle for an empty ResourceRequestInfo. |
| 48 EXPECT_FALSE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get())); |
| 49 |
| 50 // We can create the throttle for a valid ResourceRequestInfo. |
| 51 ResourceRequestInfo::AllocateForTesting(request.get(), RESOURCE_TYPE_IMAGE, |
| 52 nullptr, 0, 0, 0, false, true, true, |
| 53 true, false); |
| 54 EXPECT_TRUE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get())); |
| 55 |
| 56 // Nor will we for LOAD_DO_NOT_SAVE_COOKIES requests. |
| 57 request->SetLoadFlags(net::LOAD_DO_NOT_SAVE_COOKIES); |
| 58 EXPECT_FALSE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get())); |
| 59 |
| 60 // Nor if experimental web features are disabled. |
| 61 request->SetLoadFlags(net::LOAD_NORMAL); |
| 62 command_line.reset(); |
| 63 EXPECT_FALSE(ClearSiteDataThrottle::CreateThrottleForRequest(request.get())); |
| 64 } |
| 65 |
| 32 TEST_F(ClearSiteDataThrottleTest, ParseHeader) { | 66 TEST_F(ClearSiteDataThrottleTest, ParseHeader) { |
| 33 struct TestCase { | 67 struct TestCase { |
| 34 const char* header; | 68 const char* header; |
| 35 bool cookies; | 69 bool cookies; |
| 36 bool storage; | 70 bool storage; |
| 37 bool cache; | 71 bool cache; |
| 38 } test_cases[] = { | 72 } test_cases[] = { |
| 39 // One data type. | 73 // One data type. |
| 40 {"{ \"types\": [\"cookies\"] }", true, false, false}, | 74 {"{ \"types\": [\"cookies\"] }", true, false, false}, |
| 41 {"{ \"types\": [\"storage\"] }", false, true, false}, | 75 {"{ \"types\": [\"storage\"] }", false, true, false}, |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 for (const auto& message : messages) { | 158 for (const auto& message : messages) { |
| 125 EXPECT_EQ(CONSOLE_MESSAGE_LEVEL_ERROR, message.level); | 159 EXPECT_EQ(CONSOLE_MESSAGE_LEVEL_ERROR, message.level); |
| 126 multiline_message += message.text + "\n"; | 160 multiline_message += message.text + "\n"; |
| 127 } | 161 } |
| 128 | 162 |
| 129 EXPECT_EQ(test_case.console_message, multiline_message); | 163 EXPECT_EQ(test_case.console_message, multiline_message); |
| 130 } | 164 } |
| 131 } | 165 } |
| 132 | 166 |
| 133 } // namespace content | 167 } // namespace content |
| OLD | NEW |