OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/browsing_data/clear_site_data_throttle.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "testing/gmock/include/gmock/gmock.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace content { | |
13 | |
14 class ClearSiteDataThrottleTest : public testing::Test { | |
15 public: | |
16 void SetUp() override { | |
17 throttle_ = ClearSiteDataThrottle::CreateThrottleFor(nullptr); | |
18 } | |
19 | |
20 ClearSiteDataThrottle* GetThrottle() { | |
21 return static_cast<ClearSiteDataThrottle*>(throttle_.get()); | |
22 } | |
23 | |
24 void ParseHeaderTestCase( | |
25 std::string header, | |
26 bool expect_cookies, bool expect_storage, bool expect_cache) { | |
27 SCOPED_TRACE("Test failure for " + header); | |
28 | |
29 bool actual_cookies; | |
30 bool actual_storage; | |
31 bool actual_cache; | |
32 | |
33 EXPECT_TRUE(GetThrottle()->ParseHeader( | |
34 header, &actual_cookies, &actual_storage, &actual_cache)); | |
35 | |
36 EXPECT_EQ(expect_cookies, actual_cookies); | |
37 EXPECT_EQ(expect_storage, actual_storage); | |
38 EXPECT_EQ(expect_cache, actual_cache); | |
39 } | |
40 | |
41 void InvalidParseHeaderTestCase(std::string header) { | |
42 SCOPED_TRACE("Test failure for " + header); | |
43 | |
44 bool actual_cookies; | |
45 bool actual_storage; | |
46 bool actual_cache; | |
47 | |
48 EXPECT_FALSE(GetThrottle()->ParseHeader( | |
49 header, &actual_cookies, &actual_storage, &actual_cache)); | |
50 } | |
51 | |
52 private: | |
53 std::unique_ptr<NavigationThrottle> throttle_; | |
54 }; | |
55 | |
56 TEST_F(ClearSiteDataThrottleTest, ParseHeader) { | |
57 // 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.
| |
58 ParseHeaderTestCase("{ \"types\": [\"cookies\"] }", true, false, false); | |
59 ParseHeaderTestCase("{ \"types\": [\"storage\"] }", false, true, false); | |
60 ParseHeaderTestCase("{ \"types\": [\"cache\"] }", false, false, true); | |
61 | |
62 // Two data types. | |
63 ParseHeaderTestCase("{ \"types\": [\"cookies\", \"cache\"] }", | |
64 true, false, true); | |
65 | |
66 // Three data types. | |
67 ParseHeaderTestCase("{ \"types\": [\"storage\", \"cache\", \"cookies\"] }", | |
68 true, true, true); | |
69 | |
70 // Different formatting. | |
71 ParseHeaderTestCase(" { \"types\": [\"cookies\" ]}", true, false, false); | |
72 | |
73 // Other entries in the dictionary. | |
74 ParseHeaderTestCase("{ \"types\": [\"storage\"], \"other_params\": {} }", | |
75 false, true, false); | |
76 | |
77 // Unknown types are ignored, but we still proceed with the deletion for | |
78 // those that we recognize. | |
79 ParseHeaderTestCase("{ \"types\": [\"cache\", \"foo\"] }", | |
80 false, false, true); | |
81 } | |
82 | |
83 TEST_F(ClearSiteDataThrottleTest, InvalidHeader) { | |
84 InvalidParseHeaderTestCase(""); | |
85 InvalidParseHeaderTestCase("not a dictionary"); | |
86 InvalidParseHeaderTestCase("{ \"malformed json"); | |
87 InvalidParseHeaderTestCase("{ \"no_field_called_types\" : {} }"); | |
88 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.
| |
89 } | |
90 | |
91 } // namespace content | |
OLD | NEW |