OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" | 5 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom
pt_config.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/test/scoped_feature_list.h" | 11 #include "base/test/scoped_feature_list.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "components/variations/variations_params_manager.h" | 13 #include "components/variations/variations_params_manager.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace safe_browsing { | 18 namespace safe_browsing { |
19 | 19 |
20 const char kTrialName[] = "trial"; | 20 const char kTrialName[] = "trial"; |
21 // A SHA256 hash for "mydomain.com". | 21 // A SHA256 hash for "mydomain.com". |
22 const char kDomainHash[] = | 22 const char kDomainHash[] = |
23 "0a79eaf6adb7b1e60d3fa548aa63105f525a00448efbb59ee965b9351a90ac31"; | 23 "0a79eaf6adb7b1e60d3fa548aa63105f525a00448efbb59ee965b9351a90ac31"; |
24 | 24 |
| 25 bool IsPromptEnabled() { |
| 26 return base::FeatureList::IsEnabled(kSettingsResetPrompt); |
| 27 } |
| 28 |
25 // Test class that initializes a ScopedFeatureList so that all tests | 29 // Test class that initializes a ScopedFeatureList so that all tests |
26 // start off with all features disabled. | 30 // start off with all features disabled. |
27 class SettingsResetPromptConfigTest : public ::testing::Test { | 31 class SettingsResetPromptConfigTest : public ::testing::Test { |
28 protected: | 32 protected: |
29 typedef std::map<std::string, std::string> Parameters; | 33 typedef std::map<std::string, std::string> Parameters; |
30 | 34 |
31 // Sets the settings reset prompt feature parameters, which has the | 35 // Sets the settings reset prompt feature parameters, which has the |
32 // side-effect of also enabling the feature. | 36 // side-effect of also enabling the feature. |
33 void SetFeatureParams(const Parameters& params) { | 37 void SetFeatureParams(const Parameters& params) { |
34 static std::set<std::string> features = {kSettingsResetPrompt.name}; | 38 static std::set<std::string> features = {kSettingsResetPrompt.name}; |
35 | 39 |
36 params_manager_.ClearAllVariationParams(); | 40 params_manager_.ClearAllVariationParams(); |
37 params_manager_.SetVariationParamsWithFeatureAssociations(kTrialName, | 41 params_manager_.SetVariationParamsWithFeatureAssociations(kTrialName, |
38 params, features); | 42 params, features); |
39 } | 43 } |
40 | 44 |
41 Parameters GetDefaultFeatureParams() { | 45 Parameters GetDefaultFeatureParams() { |
42 return { | 46 return { |
43 {"domain_hashes", base::StringPrintf("{\"%s\": \"1\"}", kDomainHash)}, | 47 {"domain_hashes", base::StringPrintf("{\"%s\": \"1\"}", kDomainHash)}, |
44 {"delay_before_prompt_seconds", "42"}, | 48 {"delay_before_prompt_seconds", "42"}, |
45 {"use_modal_dialog", "true"}}; | 49 {"use_modal_dialog", "true"}}; |
46 } | 50 } |
47 | 51 |
48 variations::testing::VariationParamsManager params_manager_; | 52 variations::testing::VariationParamsManager params_manager_; |
49 base::test::ScopedFeatureList scoped_feature_list_; | 53 base::test::ScopedFeatureList scoped_feature_list_; |
50 }; | 54 }; |
51 | 55 |
52 TEST_F(SettingsResetPromptConfigTest, IsPromptEnabled) { | |
53 EXPECT_FALSE(SettingsResetPromptConfig::IsPromptEnabled()); | |
54 | |
55 SetFeatureParams(GetDefaultFeatureParams()); | |
56 EXPECT_TRUE(SettingsResetPromptConfig::IsPromptEnabled()); | |
57 } | |
58 | |
59 TEST_F(SettingsResetPromptConfigTest, Create) { | 56 TEST_F(SettingsResetPromptConfigTest, Create) { |
60 ASSERT_FALSE(SettingsResetPromptConfig::IsPromptEnabled()); | 57 ASSERT_FALSE(IsPromptEnabled()); |
61 | 58 |
62 // |Create()| should return nullptr when feature is not enabled. | 59 // |Create()| should return nullptr when feature is not enabled. |
63 EXPECT_FALSE(SettingsResetPromptConfig::Create()); | 60 EXPECT_FALSE(SettingsResetPromptConfig::Create()); |
64 | 61 |
65 // |Create()| should return false when feature is enabled, but parameters are | 62 // |Create()| should return false when feature is enabled, but parameters are |
66 // |missing. | 63 // |missing. |
67 scoped_feature_list_.InitAndEnableFeature(kSettingsResetPrompt); | 64 scoped_feature_list_.InitAndEnableFeature(kSettingsResetPrompt); |
68 ASSERT_TRUE(SettingsResetPromptConfig::IsPromptEnabled()); | 65 ASSERT_TRUE(IsPromptEnabled()); |
69 EXPECT_FALSE(SettingsResetPromptConfig::Create()); | 66 EXPECT_FALSE(SettingsResetPromptConfig::Create()); |
70 SetFeatureParams(Parameters()); | 67 SetFeatureParams(Parameters()); |
71 EXPECT_FALSE(SettingsResetPromptConfig::Create()); | 68 EXPECT_FALSE(SettingsResetPromptConfig::Create()); |
72 | 69 |
73 // |Create()| should return a config when parameters are all present. | 70 // |Create()| should return a config when parameters are all present. |
74 // Individual parameters are tested separately. | 71 // Individual parameters are tested separately. |
75 SetFeatureParams(GetDefaultFeatureParams()); | 72 SetFeatureParams(GetDefaultFeatureParams()); |
76 EXPECT_TRUE(SettingsResetPromptConfig::Create()); | 73 EXPECT_TRUE(SettingsResetPromptConfig::Create()); |
77 } | 74 } |
78 | 75 |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 params[kModalParam] = "false"; | 281 params[kModalParam] = "false"; |
285 SetFeatureParams(params); | 282 SetFeatureParams(params); |
286 { | 283 { |
287 auto config = SettingsResetPromptConfig::Create(); | 284 auto config = SettingsResetPromptConfig::Create(); |
288 ASSERT_TRUE(config); | 285 ASSERT_TRUE(config); |
289 EXPECT_FALSE(config->use_modal_dialog()); | 286 EXPECT_FALSE(config->use_modal_dialog()); |
290 } | 287 } |
291 } | 288 } |
292 | 289 |
293 } // namespace safe_browsing | 290 } // namespace safe_browsing |
OLD | NEW |