Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: components/content_settings/core/browser/content_settings_utils_unittest.cc

Issue 1372353004: Making structure for ContentSettings and its corresponding strings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing nits. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/content_settings/core/browser/content_settings_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 i = 0; i < arraysize(kContentSettingNames); ++i) {
69 ContentSetting setting = static_cast<ContentSetting>(i);
70 setting_string = content_settings::ContentSettingToString(setting);
71 EXPECT_EQ(kContentSettingNames[i], setting_string);
72
73 ContentSetting converted_setting;
74 if (i == 0) {
75 EXPECT_FALSE(content_settings::ContentSettingFromString(
76 kContentSettingNames[i], &converted_setting));
77 } else {
78 EXPECT_TRUE(content_settings::ContentSettingFromString(
79 kContentSettingNames[i], &converted_setting));
80 }
81 EXPECT_EQ(setting, converted_setting);
82 }
83 }
OLDNEW
« no previous file with comments | « components/content_settings/core/browser/content_settings_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698