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 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 // By default, Instant Extended forces the instant URL to be HTTPS, so even if | 522 // By default, Instant Extended forces the instant URL to be HTTPS, so even if |
523 // we set a Google base URL that is HTTP, we should get an HTTPS URL. | 523 // we set a Google base URL that is HTTP, we should get an HTTPS URL. |
524 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); | 524 UIThreadSearchTermsData::SetGoogleBaseURL("http://www.foo.com/"); |
525 GURL instant_url(GetInstantURL(profile(), false)); | 525 GURL instant_url(GetInstantURL(profile(), false)); |
526 ASSERT_TRUE(instant_url.is_valid()); | 526 ASSERT_TRUE(instant_url.is_valid()); |
527 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); | 527 EXPECT_EQ("https://www.foo.com/webhp?strk", instant_url.spec()); |
528 | 528 |
529 // However, if the Google base URL is specified on the command line, the | 529 // However, if the Google base URL is specified on the command line, the |
530 // instant URL should just use it, even if it's HTTP. | 530 // instant URL should just use it, even if it's HTTP. |
531 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); | 531 UIThreadSearchTermsData::SetGoogleBaseURL(std::string()); |
532 CommandLine::ForCurrentProcess()->AppendSwitchASCII(switches::kGoogleBaseURL, | 532 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
533 "http://www.bar.com/"); | 533 switches::kGoogleBaseURL, "http://www.bar.com/"); |
534 instant_url = GetInstantURL(profile(), false); | 534 instant_url = GetInstantURL(profile(), false); |
535 ASSERT_TRUE(instant_url.is_valid()); | 535 ASSERT_TRUE(instant_url.is_valid()); |
536 EXPECT_EQ("http://www.bar.com/webhp?strk", instant_url.spec()); | 536 EXPECT_EQ("http://www.bar.com/webhp?strk", instant_url.spec()); |
537 | 537 |
538 // Similarly, setting a Google base URL on the command line should allow you | 538 // Similarly, setting a Google base URL on the command line should allow you |
539 // to get the Google version of the local NTP, even though search provider's | 539 // to get the Google version of the local NTP, even though search provider's |
540 // URL doesn't contain "google". | 540 // URL doesn't contain "google". |
541 local_instant_url = GetLocalInstantURL(profile()); | 541 local_instant_url = GetLocalInstantURL(profile()); |
542 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); | 542 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), local_instant_url); |
543 | 543 |
544 // If we specify extra search query params, they should be inserted into the | 544 // If we specify extra search query params, they should be inserted into the |
545 // query portion of the instant URL. | 545 // query portion of the instant URL. |
546 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 546 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
547 switches::kExtraSearchQueryParams, "a=b"); | 547 switches::kExtraSearchQueryParams, "a=b"); |
548 instant_url = GetInstantURL(profile(), false); | 548 instant_url = GetInstantURL(profile(), false); |
549 ASSERT_TRUE(instant_url.is_valid()); | 549 ASSERT_TRUE(instant_url.is_valid()); |
550 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); | 550 EXPECT_EQ("http://www.bar.com/webhp?a=b&strk", instant_url.spec()); |
551 } | 551 } |
552 | 552 |
553 TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) { | 553 TEST_F(SearchTest, ShouldPrefetchSearchResults_InstantExtendedAPIEnabled) { |
554 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 554 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
555 "EmbeddedSearch", "Group1 espv:2")); | 555 "EmbeddedSearch", "Group1 espv:2")); |
556 #if defined(OS_IOS) | 556 #if defined(OS_IOS) |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | 884 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); |
885 } | 885 } |
886 | 886 |
887 TEST_F(DisplaySearchButtonTest, Never) { | 887 TEST_F(DisplaySearchButtonTest, Never) { |
888 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 888 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
889 "EmbeddedSearch", "Group1 espv:2 display_search_button:0")); | 889 "EmbeddedSearch", "Group1 espv:2 display_search_button:0")); |
890 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | 890 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); |
891 } | 891 } |
892 | 892 |
893 TEST_F(DisplaySearchButtonTest, CommandLineNever) { | 893 TEST_F(DisplaySearchButtonTest, CommandLineNever) { |
894 CommandLine::ForCurrentProcess()->AppendSwitch( | 894 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
895 switches::kDisableSearchButtonInOmnibox); | 895 switches::kDisableSearchButtonInOmnibox); |
896 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | 896 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); |
897 | 897 |
898 // Command-line disable should override the field trial. | 898 // Command-line disable should override the field trial. |
899 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 899 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
900 "EmbeddedSearch", "Group1 espv:2 display_search_button:1")); | 900 "EmbeddedSearch", "Group1 espv:2 display_search_button:1")); |
901 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | 901 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); |
902 } | 902 } |
903 | 903 |
904 TEST_F(DisplaySearchButtonTest, ForSearchTermReplacement) { | 904 TEST_F(DisplaySearchButtonTest, ForSearchTermReplacement) { |
905 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 905 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
906 "EmbeddedSearch", "Group1 espv:2 display_search_button:1")); | 906 "EmbeddedSearch", "Group1 espv:2 display_search_button:1")); |
907 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR, GetDisplaySearchButtonConditions()); | 907 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR, GetDisplaySearchButtonConditions()); |
908 } | 908 } |
909 | 909 |
910 TEST_F(DisplaySearchButtonTest, CommandLineForSearchTermReplacement) { | 910 TEST_F(DisplaySearchButtonTest, CommandLineForSearchTermReplacement) { |
911 CommandLine::ForCurrentProcess()->AppendSwitch( | 911 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
912 switches::kEnableSearchButtonInOmniboxForStr); | 912 switches::kEnableSearchButtonInOmniboxForStr); |
913 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR, GetDisplaySearchButtonConditions()); | 913 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR, GetDisplaySearchButtonConditions()); |
914 } | 914 } |
915 | 915 |
916 TEST_F(DisplaySearchButtonTest, ForSearchTermReplacementOrInputInProgress) { | 916 TEST_F(DisplaySearchButtonTest, ForSearchTermReplacementOrInputInProgress) { |
917 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 917 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
918 "EmbeddedSearch", "Group1 espv:2 display_search_button:2")); | 918 "EmbeddedSearch", "Group1 espv:2 display_search_button:2")); |
919 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP, | 919 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP, |
920 GetDisplaySearchButtonConditions()); | 920 GetDisplaySearchButtonConditions()); |
921 } | 921 } |
922 | 922 |
923 TEST_F(DisplaySearchButtonTest, | 923 TEST_F(DisplaySearchButtonTest, |
924 CommandLineForSearchTermReplacementOrInputInProgress) { | 924 CommandLineForSearchTermReplacementOrInputInProgress) { |
925 CommandLine::ForCurrentProcess()->AppendSwitch( | 925 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
926 switches::kEnableSearchButtonInOmniboxForStrOrIip); | 926 switches::kEnableSearchButtonInOmniboxForStrOrIip); |
927 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP, | 927 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_FOR_STR_OR_IIP, |
928 GetDisplaySearchButtonConditions()); | 928 GetDisplaySearchButtonConditions()); |
929 } | 929 } |
930 | 930 |
931 TEST_F(DisplaySearchButtonTest, Always) { | 931 TEST_F(DisplaySearchButtonTest, Always) { |
932 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 932 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
933 "EmbeddedSearch", "Group1 espv:2 display_search_button:3")); | 933 "EmbeddedSearch", "Group1 espv:2 display_search_button:3")); |
934 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_ALWAYS, GetDisplaySearchButtonConditions()); | 934 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_ALWAYS, GetDisplaySearchButtonConditions()); |
935 } | 935 } |
936 | 936 |
937 TEST_F(DisplaySearchButtonTest, CommandLineAlways) { | 937 TEST_F(DisplaySearchButtonTest, CommandLineAlways) { |
938 CommandLine::ForCurrentProcess()->AppendSwitch( | 938 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
939 switches::kEnableSearchButtonInOmniboxAlways); | 939 switches::kEnableSearchButtonInOmniboxAlways); |
940 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_ALWAYS, GetDisplaySearchButtonConditions()); | 940 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_ALWAYS, GetDisplaySearchButtonConditions()); |
941 } | 941 } |
942 | 942 |
943 TEST_F(DisplaySearchButtonTest, InvalidValue) { | 943 TEST_F(DisplaySearchButtonTest, InvalidValue) { |
944 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 944 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
945 "EmbeddedSearch", "Group1 espv:2 display_search_button:4")); | 945 "EmbeddedSearch", "Group1 espv:2 display_search_button:4")); |
946 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); | 946 EXPECT_EQ(DISPLAY_SEARCH_BUTTON_NEVER, GetDisplaySearchButtonConditions()); |
947 } | 947 } |
948 | 948 |
(...skipping 28 matching lines...) Expand all Loading... |
977 } | 977 } |
978 | 978 |
979 TEST_F(OriginChipTest, InvalidValue) { | 979 TEST_F(OriginChipTest, InvalidValue) { |
980 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 980 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
981 "EmbeddedSearch", "Group1 espv:2 origin_chip:3")); | 981 "EmbeddedSearch", "Group1 espv:2 origin_chip:3")); |
982 EXPECT_FALSE(ShouldDisplayOriginChip()); | 982 EXPECT_FALSE(ShouldDisplayOriginChip()); |
983 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); | 983 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); |
984 } | 984 } |
985 | 985 |
986 TEST_F(OriginChipTest, CommandLineDisabled) { | 986 TEST_F(OriginChipTest, CommandLineDisabled) { |
987 CommandLine::ForCurrentProcess()->AppendSwitch( | 987 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
988 switches::kDisableOriginChip); | 988 switches::kDisableOriginChip); |
989 EXPECT_FALSE(ShouldDisplayOriginChip()); | 989 EXPECT_FALSE(ShouldDisplayOriginChip()); |
990 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); | 990 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); |
991 | 991 |
992 // Command-line disable should override the field trial. | 992 // Command-line disable should override the field trial. |
993 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( | 993 ASSERT_TRUE(base::FieldTrialList::CreateFieldTrial( |
994 "EmbeddedSearch", "Group1 espv:2 origin_chip:1")); | 994 "EmbeddedSearch", "Group1 espv:2 origin_chip:1")); |
995 EXPECT_FALSE(ShouldDisplayOriginChip()); | 995 EXPECT_FALSE(ShouldDisplayOriginChip()); |
996 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); | 996 EXPECT_EQ(ORIGIN_CHIP_DISABLED, GetOriginChipCondition()); |
997 } | 997 } |
998 | 998 |
999 TEST_F(OriginChipTest, CommandLineAlways) { | 999 TEST_F(OriginChipTest, CommandLineAlways) { |
1000 CommandLine::ForCurrentProcess()->AppendSwitch( | 1000 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1001 switches::kEnableOriginChipAlways); | 1001 switches::kEnableOriginChipAlways); |
1002 EXPECT_TRUE(ShouldDisplayOriginChip()); | 1002 EXPECT_TRUE(ShouldDisplayOriginChip()); |
1003 EXPECT_EQ(ORIGIN_CHIP_ALWAYS, GetOriginChipCondition()); | 1003 EXPECT_EQ(ORIGIN_CHIP_ALWAYS, GetOriginChipCondition()); |
1004 } | 1004 } |
1005 | 1005 |
1006 TEST_F(OriginChipTest, CommandLineOnSrp) { | 1006 TEST_F(OriginChipTest, CommandLineOnSrp) { |
1007 CommandLine::ForCurrentProcess()->AppendSwitch( | 1007 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
1008 switches::kEnableOriginChipOnSrp); | 1008 switches::kEnableOriginChipOnSrp); |
1009 EXPECT_TRUE(ShouldDisplayOriginChip()); | 1009 EXPECT_TRUE(ShouldDisplayOriginChip()); |
1010 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); | 1010 EXPECT_EQ(ORIGIN_CHIP_ON_SRP, GetOriginChipCondition()); |
1011 } | 1011 } |
1012 | 1012 |
1013 } // namespace chrome | 1013 } // namespace chrome |
OLD | NEW |