| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/metrics/field_trial.h" | 6 #include "base/metrics/field_trial.h" |
| 7 #include "base/metrics/histogram_base.h" | 7 #include "base/metrics/histogram_base.h" |
| 8 #include "base/metrics/histogram_samples.h" | 8 #include "base/metrics/histogram_samples.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 869 | 869 |
| 870 TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) { | 870 TEST_F(IsQueryExtractionEnabledTest, EnabledViaCommandLine) { |
| 871 EnableQueryExtractionForTesting(); | 871 EnableQueryExtractionForTesting(); |
| 872 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 872 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
| 873 "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); | 873 "EmbeddedSearch", "Group1 espv:2 query_extraction:0")); |
| 874 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); | 874 EXPECT_TRUE(IsInstantExtendedAPIEnabled()); |
| 875 EXPECT_TRUE(IsQueryExtractionEnabled()); | 875 EXPECT_TRUE(IsQueryExtractionEnabled()); |
| 876 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); | 876 EXPECT_EQ(2ul, EmbeddedSearchPageVersion()); |
| 877 } | 877 } |
| 878 | 878 |
| 879 typedef SearchTest DisplaySearchButtonTest; | |
| 880 | |
| 881 TEST_F(DisplaySearchButtonTest, NotSet) { | |
| 882 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 883 "EmbeddedSearch", "Group1 espv:2")); | |
| 884 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | |
| 885 } | |
| 886 | |
| 887 TEST_F(DisplaySearchButtonTest, Never) { | |
| 888 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 889 "EmbeddedSearch", "Group1 espv:2 display_search_button:0")); | |
| 890 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | |
| 891 } | |
| 892 | |
| 893 TEST_F(DisplaySearchButtonTest, CommandLineNever) { | |
| 894 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 895 switches::kDisableSearchButtonInOmnibox); | |
| 896 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | |
| 897 | |
| 898 // Command-line disable should override the field trial. | |
| 899 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 900 "EmbeddedSearch", "Group1 espv:2 display_search_button:1")); | |
| 901 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | |
| 902 } | |
| 903 | |
| 904 TEST_F(DisplaySearchButtonTest, ForSearchTermReplacement) { | |
| 905 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 906 "EmbeddedSearch", "Group1 espv:2 display_search_button:1")); | |
| 907 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR, GetDisplaySearchButtonConditions()); | |
| 908 } | |
| 909 | |
| 910 TEST_F(DisplaySearchButtonTest, CommandLineForSearchTermReplacement) { | |
| 911 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 912 switches::kEnableSearchButtonInOmniboxForStr); | |
| 913 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR, GetDisplaySearchButtonConditions()); | |
| 914 } | |
| 915 | |
| 916 TEST_F(DisplaySearchButtonTest, ForSearchTermReplacementOrInputInProgress) { | |
| 917 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 918 "EmbeddedSearch", "Group1 espv:2 display_search_button:2")); | |
| 919 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP, | |
| 920 GetDisplaySearchButtonConditions()); | |
| 921 } | |
| 922 | |
| 923 TEST_F(DisplaySearchButtonTest, | |
| 924 CommandLineForSearchTermReplacementOrInputInProgress) { | |
| 925 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 926 switches::kEnableSearchButtonInOmniboxForStrOrIip); | |
| 927 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP, | |
| 928 GetDisplaySearchButtonConditions()); | |
| 929 } | |
| 930 | |
| 931 TEST_F(DisplaySearchButtonTest, Always) { | |
| 932 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 933 "EmbeddedSearch", "Group1 espv:2 display_search_button:3")); | |
| 934 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_ALWAYS, GetDisplaySearchButtonConditions()); | |
| 935 } | |
| 936 | |
| 937 TEST_F(DisplaySearchButtonTest, CommandLineAlways) { | |
| 938 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 939 switches::kEnableSearchButtonInOmniboxAlways); | |
| 940 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_ALWAYS, GetDisplaySearchButtonConditions()); | |
| 941 } | |
| 942 | |
| 943 TEST_F(DisplaySearchButtonTest, InvalidValue) { | |
| 944 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 945 "EmbeddedSearch", "Group1 espv:2 display_search_button:4")); | |
| 946 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | |
| 947 } | |
| 948 | |
| 949 typedef SearchTest OriginChipTest; | |
| 950 | |
| 951 TEST_F(OriginChipTest, NotSet) { | |
| 952 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 953 "EmbeddedSearch", "Group1 espv:2")); | |
| 954 EXPECT_FALSE(ShouldDisplayOriginChip()); | |
| 955 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); | |
| 956 } | |
| 957 | |
| 958 TEST_F(OriginChipTest, Disabled) { | |
| 959 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 960 "EmbeddedSearch", "Group1 espv:2 origin_chip:0")); | |
| 961 EXPECT_FALSE(ShouldDisplayOriginChip()); | |
| 962 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); | |
| 963 } | |
| 964 | |
| 965 TEST_F(OriginChipTest, Always) { | |
| 966 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 967 "EmbeddedSearch", "Group1 espv:2 origin_chip:1")); | |
| 968 EXPECT_TRUE(ShouldDisplayOriginChip()); | |
| 969 EXPECT_EQ(ORIGIN_CHIP_ALWAYS, GetOriginChipCondition()); | |
| 970 } | |
| 971 | |
| 972 TEST_F(OriginChipTest, OnSrp) { | |
| 973 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 974 "EmbeddedSearch", "Group1 espv:2 origin_chip:2")); | |
| 975 EXPECT_TRUE(ShouldDisplayOriginChip()); | |
| 976 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); | |
| 977 } | |
| 978 | |
| 979 TEST_F(OriginChipTest, InvalidValue) { | |
| 980 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 981 "EmbeddedSearch", "Group1 espv:2 origin_chip:3")); | |
| 982 EXPECT_FALSE(ShouldDisplayOriginChip()); | |
| 983 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); | |
| 984 } | |
| 985 | |
| 986 TEST_F(OriginChipTest, CommandLineDisabled) { | |
| 987 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 988 switches::kDisableOriginChip); | |
| 989 EXPECT_FALSE(ShouldDisplayOriginChip()); | |
| 990 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); | |
| 991 | |
| 992 // Command-line disable should override the field trial. | |
| 993 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | |
| 994 "EmbeddedSearch", "Group1 espv:2 origin_chip:1")); | |
| 995 EXPECT_FALSE(ShouldDisplayOriginChip()); | |
| 996 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); | |
| 997 } | |
| 998 | |
| 999 TEST_F(OriginChipTest, CommandLineAlways) { | |
| 1000 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1001 switches::kEnableOriginChipAlways); | |
| 1002 EXPECT_TRUE(ShouldDisplayOriginChip()); | |
| 1003 EXPECT_EQ(ORIGIN_CHIP_ALWAYS, GetOriginChipCondition()); | |
| 1004 } | |
| 1005 | |
| 1006 TEST_F(OriginChipTest, CommandLineOnSrp) { | |
| 1007 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 1008 switches::kEnableOriginChipOnSrp); | |
| 1009 EXPECT_TRUE(ShouldDisplayOriginChip()); | |
| 1010 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); | |
| 1011 } | |
| 1012 | |
| 1013 } // namespace chrome | 879 } // namespace chrome |
| OLD | NEW |