Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prom pt_config.h" | |
| 6 | |
| 7 #include <map> | |
| 8 #include <set> | |
| 9 | |
| 10 #include "base/strings/stringprintf.h" | |
| 11 #include "base/test/scoped_feature_list.h" | |
| 12 #include "components/variations/variations_params_manager.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #include "url/gurl.h" | |
| 16 | |
| 17 namespace safe_browsing { | |
| 18 | |
| 19 const char kTrialName[] = "trial"; | |
| 20 // A SHA256 hash for "mydomain.com". | |
| 21 const char kDomainHash[] = | |
| 22 "0a79eaf6adb7b1e60d3fa548aa63105f525a00448efbb59ee965b9351a90ac31"; | |
| 23 | |
| 24 // Test class that initializes a ScopedFeatureList so that all tests | |
| 25 // start off with all features disabled. | |
| 26 class SettingsResetPromptConfigTest : public ::testing::Test { | |
| 27 protected: | |
| 28 // Adds a set of valid settings reset prompt feature parameters, which | |
| 29 // has the side-effect of also enabling the feature. | |
| 30 void AddDefaultFeatureParams() { | |
| 31 std::set<std::string> features = {kSettingsResetPrompt.name}; | |
| 32 std::map<std::string, std::string> params = { | |
| 33 {"domain_hashes", base::StringPrintf("{\"%s\": \"1\"}", kDomainHash)}}; | |
| 34 | |
| 35 params_manager_.SetVariationParamsWithFeatureAssociations(kTrialName, | |
| 36 params, features); | |
| 37 } | |
| 38 | |
| 39 variations::testing::VariationParamsManager params_manager_; | |
| 40 base::test::ScopedFeatureList scoped_feature_list_; | |
| 41 }; | |
| 42 | |
| 43 TEST_F(SettingsResetPromptConfigTest, IsPromptEnabled) { | |
| 44 EXPECT_FALSE(SettingsResetPromptConfig::IsPromptEnabled()); | |
| 45 | |
| 46 scoped_feature_list_.InitAndEnableFeature(kSettingsResetPrompt); | |
|
csharp
2017/01/09 21:54:59
What about just calling AddDefaultFeatureParams he
alito
2017/01/10 00:37:48
Done.
| |
| 47 EXPECT_TRUE(SettingsResetPromptConfig::IsPromptEnabled()); | |
| 48 } | |
| 49 | |
| 50 TEST_F(SettingsResetPromptConfigTest, Create) { | |
|
csharp
2017/01/09 21:54:59
Could you add some tests to ensure that all of the
alito
2017/01/10 00:37:48
Done. Also caught yet another edge case.
| |
| 51 EXPECT_FALSE(SettingsResetPromptConfig::Create()); | |
| 52 | |
| 53 AddDefaultFeatureParams(); | |
| 54 EXPECT_TRUE(SettingsResetPromptConfig::Create()); | |
| 55 } | |
| 56 | |
| 57 TEST_F(SettingsResetPromptConfigTest, UrlToResetDomainId) { | |
|
csharp
2017/01/09 21:54:59
Can you add some test cases where the input url is
alito
2017/01/10 00:37:48
Done.
| |
| 58 AddDefaultFeatureParams(); | |
| 59 auto config = SettingsResetPromptConfig::Create(); | |
| 60 ASSERT_TRUE(config); | |
| 61 | |
| 62 EXPECT_LT(config->UrlToResetDomainId(GURL("http://www.hello.com")), 0); | |
| 63 | |
| 64 EXPECT_EQ(config->UrlToResetDomainId(GURL("http://www.sub.mydomain.com")), 1); | |
| 65 EXPECT_EQ(config->UrlToResetDomainId(GURL("http://www.mydomain.com")), 1); | |
| 66 EXPECT_EQ(config->UrlToResetDomainId(GURL("http://mydomain.com")), 1); | |
| 67 | |
| 68 EXPECT_LT(config->UrlToResetDomainId(GURL("http://mydomain")), 0); | |
| 69 EXPECT_LT(config->UrlToResetDomainId(GURL("http://mydomain.org")), 0); | |
| 70 EXPECT_LT(config->UrlToResetDomainId(GURL("http://prefixmydomain.com")), 0); | |
| 71 EXPECT_LT(config->UrlToResetDomainId(GURL("http://mydomain.com.com")), 0); | |
| 72 EXPECT_LT(config->UrlToResetDomainId(GURL("http://www.mydomain.com.com")), 0); | |
| 73 } | |
| 74 | |
| 75 } // namespace safe_browsing. | |
| OLD | NEW |