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

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: 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
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 {
Bernhard Bauer 2015/10/07 09:32:04 Empty lines after opening a namespace and before c
Deepak 2015/10/07 11:12:24 Done.
13 const char* const kContentSettingNames[] = {
14 "default",
15 "allow",
16 "block",
17 "ask",
18 "session_only",
19 "detect_important_content"
Bernhard Bauer 2015/10/07 09:32:04 Nit: Add a comma at the end here; it will reduce t
Deepak 2015/10/07 11:12:24 Done.
20 };
21 static_assert(arraysize(kContentSettingNames) <= CONTENT_SETTING_NUM_SETTINGS,
Bernhard Bauer 2015/10/07 09:32:04 You want == here.
Deepak 2015/10/07 11:12:24 Done.
22 "kContentSettingNames has an unexpected number of elements");
23 } // namespace
24
12 TEST(ContentSettingsUtilsTest, ParsePatternString) { 25 TEST(ContentSettingsUtilsTest, ParsePatternString) {
13 content_settings::PatternPair pattern_pair; 26 content_settings::PatternPair pattern_pair;
14 27
15 pattern_pair = content_settings::ParsePatternString(std::string()); 28 pattern_pair = content_settings::ParsePatternString(std::string());
16 EXPECT_FALSE(pattern_pair.first.IsValid()); 29 EXPECT_FALSE(pattern_pair.first.IsValid());
17 EXPECT_FALSE(pattern_pair.second.IsValid()); 30 EXPECT_FALSE(pattern_pair.second.IsValid());
18 31
19 pattern_pair = content_settings::ParsePatternString(","); 32 pattern_pair = content_settings::ParsePatternString(",");
20 EXPECT_FALSE(pattern_pair.first.IsValid()); 33 EXPECT_FALSE(pattern_pair.first.IsValid());
21 EXPECT_FALSE(pattern_pair.second.IsValid()); 34 EXPECT_FALSE(pattern_pair.second.IsValid());
(...skipping 15 matching lines...) Expand all
37 pattern_pair = content_settings::ParsePatternString( 50 pattern_pair = content_settings::ParsePatternString(
38 "http://www.foo.com,http://www.bar.com,"); 51 "http://www.foo.com,http://www.bar.com,");
39 EXPECT_FALSE(pattern_pair.first.IsValid()); 52 EXPECT_FALSE(pattern_pair.first.IsValid());
40 EXPECT_FALSE(pattern_pair.second.IsValid()); 53 EXPECT_FALSE(pattern_pair.second.IsValid());
41 54
42 pattern_pair = content_settings::ParsePatternString( 55 pattern_pair = content_settings::ParsePatternString(
43 "http://www.foo.com,http://www.bar.com,http://www.error.com"); 56 "http://www.foo.com,http://www.bar.com,http://www.error.com");
44 EXPECT_FALSE(pattern_pair.first.IsValid()); 57 EXPECT_FALSE(pattern_pair.first.IsValid());
45 EXPECT_FALSE(pattern_pair.second.IsValid()); 58 EXPECT_FALSE(pattern_pair.second.IsValid());
46 } 59 }
60
61 TEST(ContentSettingsUtilsTest, ContentSettingsStringMap) {
62 ContentSetting setting;
Bernhard Bauer 2015/10/07 09:32:04 Move this into the loop to reduce scope.
Deepak 2015/10/07 11:12:24 Done.
63 for (size_t type = 0; type < arraysize(kContentSettingNames); ++type) {
64 setting = static_cast<ContentSetting>(type);
65 EXPECT_EQ(kContentSettingNames[type],
66 content_settings::ContentSettingToString(setting));
67 }
68 for (size_t type = 0; type < arraysize(kContentSettingNames); ++type) {
Bernhard Bauer 2015/10/07 09:32:04 Just combine this with the previous loop.
Deepak 2015/10/07 11:12:24 Done.
69 ContentSetting index_setting_type = static_cast<ContentSetting>(type);
70 if (type == 0)
Bernhard Bauer 2015/10/07 09:32:04 Braces for multi-line bodies.
Deepak 2015/10/07 11:12:24 Done.
71 EXPECT_FALSE(content_settings::ContentSettingFromString(
72 kContentSettingNames[type], &setting));
73 else
74 EXPECT_TRUE(content_settings::ContentSettingFromString(
75 kContentSettingNames[type], &setting));
76 EXPECT_EQ(index_setting_type, setting);
77 }
78 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698