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

Unified Diff: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config_unittest.cc

Issue 2614773008: Add a config class for the settings reset prompt. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config_unittest.cc
diff --git a/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config_unittest.cc b/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4d9fb40b91765afc63781e9d53f4e3fff67b3304
--- /dev/null
+++ b/chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config_unittest.cc
@@ -0,0 +1,75 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/safe_browsing/settings_reset_prompt/settings_reset_prompt_config.h"
+
+#include <map>
+#include <set>
+
+#include "base/strings/stringprintf.h"
+#include "base/test/scoped_feature_list.h"
+#include "components/variations/variations_params_manager.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+namespace safe_browsing {
+
+const char kTrialName[] = "trial";
+// A SHA256 hash for "mydomain.com".
+const char kDomainHash[] =
+ "0a79eaf6adb7b1e60d3fa548aa63105f525a00448efbb59ee965b9351a90ac31";
+
+// Test class that initializes a ScopedFeatureList so that all tests
+// start off with all features disabled.
+class SettingsResetPromptConfigTest : public ::testing::Test {
+ protected:
+ // Adds a set of valid settings reset prompt feature parameters, which
+ // has the side-effect of also enabling the feature.
+ void AddDefaultFeatureParams() {
+ std::set<std::string> features = {kSettingsResetPrompt.name};
+ std::map<std::string, std::string> params = {
+ {"domain_hashes", base::StringPrintf("{\"%s\": \"1\"}", kDomainHash)}};
+
+ params_manager_.SetVariationParamsWithFeatureAssociations(kTrialName,
+ params, features);
+ }
+
+ variations::testing::VariationParamsManager params_manager_;
+ base::test::ScopedFeatureList scoped_feature_list_;
+};
+
+TEST_F(SettingsResetPromptConfigTest, IsPromptEnabled) {
+ EXPECT_FALSE(SettingsResetPromptConfig::IsPromptEnabled());
+
+ 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.
+ EXPECT_TRUE(SettingsResetPromptConfig::IsPromptEnabled());
+}
+
+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.
+ EXPECT_FALSE(SettingsResetPromptConfig::Create());
+
+ AddDefaultFeatureParams();
+ EXPECT_TRUE(SettingsResetPromptConfig::Create());
+}
+
+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.
+ AddDefaultFeatureParams();
+ auto config = SettingsResetPromptConfig::Create();
+ ASSERT_TRUE(config);
+
+ EXPECT_LT(config->UrlToResetDomainId(GURL("http://www.hello.com")), 0);
+
+ EXPECT_EQ(config->UrlToResetDomainId(GURL("http://www.sub.mydomain.com")), 1);
+ EXPECT_EQ(config->UrlToResetDomainId(GURL("http://www.mydomain.com")), 1);
+ EXPECT_EQ(config->UrlToResetDomainId(GURL("http://mydomain.com")), 1);
+
+ EXPECT_LT(config->UrlToResetDomainId(GURL("http://mydomain")), 0);
+ EXPECT_LT(config->UrlToResetDomainId(GURL("http://mydomain.org")), 0);
+ EXPECT_LT(config->UrlToResetDomainId(GURL("http://prefixmydomain.com")), 0);
+ EXPECT_LT(config->UrlToResetDomainId(GURL("http://mydomain.com.com")), 0);
+ EXPECT_LT(config->UrlToResetDomainId(GURL("http://www.mydomain.com.com")), 0);
+}
+
+} // namespace safe_browsing.

Powered by Google App Engine
This is Rietveld 408576698