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

Unified Diff: chrome/browser/omnibox/omnibox_field_trial_unittest.cc

Issue 22698002: Omnibox: Allow Bundled Omnibox Field Trial to Examine Instant Extended (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test for android Created 7 years, 4 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
« no previous file with comments | « chrome/browser/omnibox/omnibox_field_trial.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/omnibox/omnibox_field_trial_unittest.cc
diff --git a/chrome/browser/omnibox/omnibox_field_trial_unittest.cc b/chrome/browser/omnibox/omnibox_field_trial_unittest.cc
index 1d49801b5a7dd5dcdae8d04a90651ce6fa74f50d..9e113a5d728c0def6290d734cd7f2051ed23625c 100644
--- a/chrome/browser/omnibox/omnibox_field_trial_unittest.cc
+++ b/chrome/browser/omnibox/omnibox_field_trial_unittest.cc
@@ -5,9 +5,12 @@
#include "chrome/browser/omnibox/omnibox_field_trial.h"
#include "base/basictypes.h"
+#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string16.h"
+#include "chrome/browser/search/search.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/metrics/entropy_provider.h"
#include "chrome/common/metrics/variations/variations_util.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -43,6 +46,13 @@ class OmniboxFieldTrialTest : public testing::Test {
AutocompleteMatchType::Type match_type,
float expected_value);
+ // EXPECT()s that OmniboxFieldTrial::GetValueForRuleInContext(|rule|,
+ // |page_classification|) returns |rule_value|.
+ static void ExpectRuleValue(
+ const std::string& rule_value,
+ const std::string& rule,
+ AutocompleteInput::PageClassification page_classification);
+
private:
scoped_ptr<base::FieldTrialList> field_trial_list_;
@@ -60,6 +70,16 @@ void OmniboxFieldTrialTest::VerifyDemotion(
EXPECT_FLOAT_EQ(expected_value, demotion_it->second);
}
+// static
+void OmniboxFieldTrialTest::ExpectRuleValue(
+ const std::string& rule_value,
+ const std::string& rule,
+ AutocompleteInput::PageClassification page_classification) {
+ EXPECT_EQ(rule_value,
+ OmniboxFieldTrial::GetValueForRuleInContext(
+ rule, page_classification));
+}
+
// Test if GetDisabledProviderTypes() properly parses various field trial
// group names.
TEST_F(OmniboxFieldTrialTest, GetDisabledProviderTypes) {
@@ -147,9 +167,9 @@ TEST_F(OmniboxFieldTrialTest, GetDemotionsByTypeWithFallback) {
const std::string kRuleName = "DemoteByType";
{
std::map<std::string, std::string> params;
- params[kRuleName + ":1"] = "1:50,2:0";
- params[kRuleName + ":3"] = "5:100";
- params[kRuleName + ":*"] = "1:25";
+ params[kRuleName + ":1:*"] = "1:50,2:0";
+ params[kRuleName + ":3:*"] = "5:100";
+ params[kRuleName + ":*:*"] = "1:25";
ASSERT_TRUE(chrome_variations::AssociateVariationParams(
kTrialName, "A", params));
}
@@ -171,19 +191,29 @@ TEST_F(OmniboxFieldTrialTest, GetDemotionsByTypeWithFallback) {
}
TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) {
+ // This test starts with Instant Extended off (the default state), then
+ // enables Instant Extended and tests again on the same rules.
+
// Must be the same as kBundledExperimentFieldTrialName
// defined in omnibox_field_trial.cc.
const std::string kTrialName = "OmniboxBundledExperimentV1";
{
std::map<std::string, std::string> params;
- // Rule 1 has some exact matches and a global fallback.
- params["rule1:1"] = "rule1-1-value"; // NEW_TAB_PAGE
- params["rule1:3"] = "rule1-3-value"; // HOMEPAGE
- params["rule1:*"] = "rule1-*-value"; // global
- // Rule 2 has no exact matches but has a global fallback.
- params["rule2:*"] = "rule2-*-value"; // global
- // Rule 3 has an exact match but no global fallback.
- params["rule3:4"] = "rule3-4-value"; // OTHER
+ // Rule 1 has some exact matches and fallbacks at every level.
+ params["rule1:1:0"] = "rule1-1-0-value"; // NEW_TAB_PAGE
+ params["rule1:3:0"] = "rule1-3-0-value"; // HOMEPAGE
+ params["rule1:4:1"] = "rule1-4-1-value"; // OTHER
+ params["rule1:4:*"] = "rule1-4-*-value"; // OTHER
+ params["rule1:*:1"] = "rule1-*-1-value"; // global
+ params["rule1:*:*"] = "rule1-*-*-value"; // global
+ // Rule 2 has no exact matches but has fallbacks.
+ params["rule2:*:0"] = "rule2-*-0-value"; // global
+ params["rule2:1:*"] = "rule2-1-*-value"; // NEW_TAB_PAGE
+ params["rule2:*:*"] = "rule2-*-*-value"; // global
+ // Rule 3 has only a global fallback.
+ params["rule3:*:*"] = "rule3-*-*-value"; // global
+ // Rule 4 has an exact match but no fallbacks.
+ params["rule4:4:0"] = "rule4-4-0-value"; // OTHER
// Add a malformed rule to make sure it doesn't screw things up.
params["unrecognized"] = "unrecognized-value";
ASSERT_TRUE(chrome_variations::AssociateVariationParams(
@@ -192,51 +222,84 @@ TEST_F(OmniboxFieldTrialTest, GetValueForRuleInContext) {
base::FieldTrialList::CreateFieldTrial(kTrialName, "A");
+ // Tests with Instant Extended disabled.
// Tests for rule 1.
- EXPECT_EQ(
- "rule1-1-value",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule1", AutocompleteInput::NEW_TAB_PAGE)); // exact match
- EXPECT_EQ(
- "rule1-*-value",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule1", AutocompleteInput::BLANK)); // fallback to global
- EXPECT_EQ(
- "rule1-3-value",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule1", AutocompleteInput::HOMEPAGE)); // exact match
- EXPECT_EQ(
- "rule1-*-value",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule1", AutocompleteInput::OTHER)); // fallback to global
+ ExpectRuleValue("rule1-1-0-value",
+ "rule1", AutocompleteInput::NEW_TAB_PAGE); // exact match
+ ExpectRuleValue("rule1-1-0-value",
+ "rule1", AutocompleteInput::NEW_TAB_PAGE); // exact match
+ ExpectRuleValue("rule1-*-*-value",
+ "rule1", AutocompleteInput::BLANK); // fallback to global
+ ExpectRuleValue("rule1-3-0-value",
+ "rule1", AutocompleteInput::HOMEPAGE); // exact match
+ ExpectRuleValue("rule1-4-*-value",
+ "rule1", AutocompleteInput::OTHER); // partial fallback
+ ExpectRuleValue("rule1-*-*-value",
+ "rule1",
+ AutocompleteInput:: // fallback to global
+ SEARCH_RESULT_PAGE_DOING_SEARCH_TERM_REPLACEMENT);
+ // Tests for rule 2.
+ ExpectRuleValue("rule2-*-0-value",
+ "rule2", AutocompleteInput::HOMEPAGE); // partial fallback
+ ExpectRuleValue("rule2-*-0-value",
+ "rule2", AutocompleteInput::OTHER); // partial fallback
+
+ // Tests for rule 3.
+ ExpectRuleValue("rule3-*-*-value",
+ "rule3", AutocompleteInput::HOMEPAGE); // fallback to global
+ ExpectRuleValue("rule3-*-*-value",
+ "rule3", AutocompleteInput::OTHER); // fallback to global
+
+ // Tests for rule 4.
+ ExpectRuleValue("",
+ "rule4", AutocompleteInput::BLANK); // no global fallback
+ ExpectRuleValue("",
+ "rule4", AutocompleteInput::HOMEPAGE); // no global fallback
+ ExpectRuleValue("rule4-4-0-value",
+ "rule4", AutocompleteInput::OTHER); // exact match
+
+ // Tests for rule 5 (a missing rule).
+ ExpectRuleValue("",
+ "rule5", AutocompleteInput::OTHER); // no rule at all
+
+ // Now change the Instant Extended state and run analogous tests.
+ // Instant Extended only works on non-mobile platforms.
+#if !defined(OS_IOS) && !defined(OS_ANDROID)
+ chrome::ResetInstantExtendedOptInStateGateForTest();
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableInstantExtendedAPI);
+
+ // Tests with Instant Extended enabled.
+ // Tests for rule 1.
+ ExpectRuleValue("rule1-4-1-value",
+ "rule1", AutocompleteInput::OTHER); // exact match
+ ExpectRuleValue("rule1-*-1-value",
+ "rule1", AutocompleteInput::BLANK); // partial fallback
+ ExpectRuleValue("rule1-*-1-value",
+ "rule1",
+ AutocompleteInput::NEW_TAB_PAGE); // partial fallback
// Tests for rule 2.
- EXPECT_EQ(
- "rule2-*-value",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule2", AutocompleteInput::HOMEPAGE)); // fallback to global
- EXPECT_EQ(
- "rule2-*-value",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule2", AutocompleteInput::OTHER)); // fallback to global
+ ExpectRuleValue("rule2-1-*-value",
+ "rule2",
+ AutocompleteInput::NEW_TAB_PAGE); // partial fallback
+ ExpectRuleValue("rule2-*-*-value",
+ "rule2", AutocompleteInput::OTHER); // global fallback
// Tests for rule 3.
- EXPECT_EQ(
- "",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule3", AutocompleteInput::BLANK)); // no global fallback
- EXPECT_EQ(
- "",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule3", AutocompleteInput::HOMEPAGE)); // no global fallback
- EXPECT_EQ(
- "rule3-4-value",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule3", AutocompleteInput::OTHER)); // exact match
-
- // Tests for rule 4 (a missing rule).
- EXPECT_EQ(
- "",
- OmniboxFieldTrial::GetValueForRuleInContext(
- "rule4", AutocompleteInput::OTHER)); // no rule at all
+ ExpectRuleValue("rule3-*-*-value",
+ "rule3", AutocompleteInput::HOMEPAGE); // global fallback
+ ExpectRuleValue("rule3-*-*-value",
+ "rule3", AutocompleteInput::OTHER); // global fallback
+
+ // Tests for rule 4.
+ ExpectRuleValue("",
+ "rule4", AutocompleteInput::BLANK); // no global fallback
+ ExpectRuleValue("",
+ "rule4", AutocompleteInput::HOMEPAGE); // no global fallback
+
+ // Tests for rule 5 (a missing rule).
+ ExpectRuleValue("",
+ "rule5", AutocompleteInput::OTHER); // no rule at all
+#endif // !defined(OS_IOS) && !defined(OS_ANDROID)
}
« no previous file with comments | « chrome/browser/omnibox/omnibox_field_trial.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698