OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "components/content_settings/core/browser/content_settings_utils.h" | 5 #include "components/content_settings/core/browser/content_settings_utils.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "components/content_settings/core/test/content_settings_test_utils.h" | 9 #include "components/content_settings/core/test/content_settings_test_utils.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace { | |
13 | |
14 const char* const kContentSettingNames[] = { | |
15 "default", | |
16 "allow", | |
17 "block", | |
18 "ask", | |
19 "session_only", | |
20 "detect_important_content", | |
21 }; | |
22 static_assert(arraysize(kContentSettingNames) == CONTENT_SETTING_NUM_SETTINGS, | |
23 "kContentSettingNames has an unexpected number of elements"); | |
24 | |
25 } // namespace | |
26 | |
12 TEST(ContentSettingsUtilsTest, ParsePatternString) { | 27 TEST(ContentSettingsUtilsTest, ParsePatternString) { |
13 content_settings::PatternPair pattern_pair; | 28 content_settings::PatternPair pattern_pair; |
14 | 29 |
15 pattern_pair = content_settings::ParsePatternString(std::string()); | 30 pattern_pair = content_settings::ParsePatternString(std::string()); |
16 EXPECT_FALSE(pattern_pair.first.IsValid()); | 31 EXPECT_FALSE(pattern_pair.first.IsValid()); |
17 EXPECT_FALSE(pattern_pair.second.IsValid()); | 32 EXPECT_FALSE(pattern_pair.second.IsValid()); |
18 | 33 |
19 pattern_pair = content_settings::ParsePatternString(","); | 34 pattern_pair = content_settings::ParsePatternString(","); |
20 EXPECT_FALSE(pattern_pair.first.IsValid()); | 35 EXPECT_FALSE(pattern_pair.first.IsValid()); |
21 EXPECT_FALSE(pattern_pair.second.IsValid()); | 36 EXPECT_FALSE(pattern_pair.second.IsValid()); |
(...skipping 15 matching lines...) Expand all Loading... | |
37 pattern_pair = content_settings::ParsePatternString( | 52 pattern_pair = content_settings::ParsePatternString( |
38 "http://www.foo.com,http://www.bar.com,"); | 53 "http://www.foo.com,http://www.bar.com,"); |
39 EXPECT_FALSE(pattern_pair.first.IsValid()); | 54 EXPECT_FALSE(pattern_pair.first.IsValid()); |
40 EXPECT_FALSE(pattern_pair.second.IsValid()); | 55 EXPECT_FALSE(pattern_pair.second.IsValid()); |
41 | 56 |
42 pattern_pair = content_settings::ParsePatternString( | 57 pattern_pair = content_settings::ParsePatternString( |
43 "http://www.foo.com,http://www.bar.com,http://www.error.com"); | 58 "http://www.foo.com,http://www.bar.com,http://www.error.com"); |
44 EXPECT_FALSE(pattern_pair.first.IsValid()); | 59 EXPECT_FALSE(pattern_pair.first.IsValid()); |
45 EXPECT_FALSE(pattern_pair.second.IsValid()); | 60 EXPECT_FALSE(pattern_pair.second.IsValid()); |
46 } | 61 } |
62 | |
63 TEST(ContentSettingsUtilsTest, ContentSettingsStringMap) { | |
64 std::string setting_string = | |
65 content_settings::ContentSettingToString(CONTENT_SETTING_NUM_SETTINGS); | |
66 EXPECT_TRUE(setting_string.empty()); | |
67 | |
68 for (size_t type = 0; type < arraysize(kContentSettingNames); ++type) { | |
Bernhard Bauer
2015/10/08 09:32:46
Nit: |type| isn't actually the correct name for th
Deepak
2015/10/08 10:48:15
Done.
| |
69 ContentSetting setting = static_cast<ContentSetting>(type); | |
70 setting_string = content_settings::ContentSettingToString(setting); | |
71 EXPECT_EQ(kContentSettingNames[type], setting_string); | |
72 | |
73 ContentSetting setting_type; | |
Bernhard Bauer
2015/10/08 09:32:46
Similarly, |_type| is incorrect here. |converted_s
Deepak
2015/10/08 10:48:15
Done.
| |
74 if (type == 0) { | |
75 EXPECT_FALSE(content_settings::ContentSettingFromString( | |
76 kContentSettingNames[type], &setting_type)); | |
77 } else { | |
78 EXPECT_TRUE(content_settings::ContentSettingFromString( | |
79 kContentSettingNames[type], &setting_type)); | |
80 } | |
81 EXPECT_EQ(setting, setting_type); | |
82 } | |
83 } | |
OLD | NEW |