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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0f353e0d8a4785120831d8ee5ccdbe55bc82b1cb |
--- /dev/null |
+++ b/content/browser/browsing_data/clear_site_data_throttle_unittest.cc |
@@ -0,0 +1,91 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/browsing_data/clear_site_data_throttle.h" |
+ |
+#include <memory> |
+ |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace content { |
+ |
+class ClearSiteDataThrottleTest : public testing::Test { |
+ public: |
+ void SetUp() override { |
+ throttle_ = ClearSiteDataThrottle::CreateThrottleFor(nullptr); |
+ } |
+ |
+ ClearSiteDataThrottle* GetThrottle() { |
+ return static_cast<ClearSiteDataThrottle*>(throttle_.get()); |
+ } |
+ |
+ void ParseHeaderTestCase( |
+ std::string header, |
+ bool expect_cookies, bool expect_storage, bool expect_cache) { |
+ SCOPED_TRACE("Test failure for " + header); |
+ |
+ bool actual_cookies; |
+ bool actual_storage; |
+ bool actual_cache; |
+ |
+ EXPECT_TRUE(GetThrottle()->ParseHeader( |
+ header, &actual_cookies, &actual_storage, &actual_cache)); |
+ |
+ EXPECT_EQ(expect_cookies, actual_cookies); |
+ EXPECT_EQ(expect_storage, actual_storage); |
+ EXPECT_EQ(expect_cache, actual_cache); |
+ } |
+ |
+ void InvalidParseHeaderTestCase(std::string header) { |
+ SCOPED_TRACE("Test failure for " + header); |
+ |
+ bool actual_cookies; |
+ bool actual_storage; |
+ bool actual_cache; |
+ |
+ EXPECT_FALSE(GetThrottle()->ParseHeader( |
+ header, &actual_cookies, &actual_storage, &actual_cache)); |
+ } |
+ |
+ private: |
+ std::unique_ptr<NavigationThrottle> throttle_; |
+}; |
+ |
+TEST_F(ClearSiteDataThrottleTest, ParseHeader) { |
+ // One data type. |
Mike West
2016/06/02 07:00:08
I think this would be simpler if you did something
msramek
2016/06/14 20:12:08
Done.
|
+ ParseHeaderTestCase("{ \"types\": [\"cookies\"] }", true, false, false); |
+ ParseHeaderTestCase("{ \"types\": [\"storage\"] }", false, true, false); |
+ ParseHeaderTestCase("{ \"types\": [\"cache\"] }", false, false, true); |
+ |
+ // Two data types. |
+ ParseHeaderTestCase("{ \"types\": [\"cookies\", \"cache\"] }", |
+ true, false, true); |
+ |
+ // Three data types. |
+ ParseHeaderTestCase("{ \"types\": [\"storage\", \"cache\", \"cookies\"] }", |
+ true, true, true); |
+ |
+ // Different formatting. |
+ ParseHeaderTestCase(" { \"types\": [\"cookies\" ]}", true, false, false); |
+ |
+ // Other entries in the dictionary. |
+ ParseHeaderTestCase("{ \"types\": [\"storage\"], \"other_params\": {} }", |
+ false, true, false); |
+ |
+ // Unknown types are ignored, but we still proceed with the deletion for |
+ // those that we recognize. |
+ ParseHeaderTestCase("{ \"types\": [\"cache\", \"foo\"] }", |
+ false, false, true); |
+} |
+ |
+TEST_F(ClearSiteDataThrottleTest, InvalidHeader) { |
+ InvalidParseHeaderTestCase(""); |
+ InvalidParseHeaderTestCase("not a dictionary"); |
+ InvalidParseHeaderTestCase("{ \"malformed json"); |
+ InvalidParseHeaderTestCase("{ \"no_field_called_types\" : {} }"); |
+ InvalidParseHeaderTestCase("{ \"types\" : [ \"no_valid_types\" ] }"); |
Mike West
2016/06/02 07:00:08
Can you add checks for the console messages as wel
msramek
2016/06/14 20:12:08
Done.
|
+} |
+ |
+} // namespace content |