OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_
observer.h" | 5 #include "chrome/browser/page_load_metrics/observers/from_gws_page_load_metrics_
observer.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" | 9 #include "chrome/browser/page_load_metrics/observers/page_load_metrics_observer_
test_harness.h" |
10 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" | 10 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h" |
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 725 |
726 TEST_F(FromGWSPageLoadMetricsObserverTest, ProvisionalIntent) { | 726 TEST_F(FromGWSPageLoadMetricsObserverTest, ProvisionalIntent) { |
727 NavigateAndCommit(GURL(kGoogleSearchResultsUrl)); | 727 NavigateAndCommit(GURL(kGoogleSearchResultsUrl)); |
728 StartNavigation(GURL("intent://en.m.wikipedia.org/wiki/Test")); | 728 StartNavigation(GURL("intent://en.m.wikipedia.org/wiki/Test")); |
729 // Simulate closing the tab. | 729 // Simulate closing the tab. |
730 DeleteContents(); | 730 DeleteContents(); |
731 histogram_tester().ExpectTotalCount( | 731 histogram_tester().ExpectTotalCount( |
732 internal::kHistogramFromGWSAbortCloseBeforeCommit, 0); | 732 internal::kHistogramFromGWSAbortCloseBeforeCommit, 0); |
733 } | 733 } |
734 | 734 |
735 TEST_F(FromGWSPageLoadMetricsLoggerTest, IsGoogleSearchHostname) { | |
736 struct { | |
737 bool expected_result; | |
738 const char* url; | |
739 } test_cases[] = { | |
740 {true, "https://www.google.com/"}, | |
741 {true, "https://www.google.co.uk/"}, | |
742 {true, "https://www.google.co.in/"}, | |
743 {false, "https://other.google.com/"}, | |
744 {false, "https://other.www.google.com/"}, | |
745 {false, "https://www.other.google.com/"}, | |
746 {false, "https://www.www.google.com/"}, | |
747 {false, "https://www.google.appspot.com/"}, | |
748 {false, "https://www.google.example.com/"}, | |
749 // Search results are not served from the bare google.com domain. | |
750 {false, "https://google.com/"}, | |
751 }; | |
752 for (const auto& test : test_cases) { | |
753 EXPECT_EQ( | |
754 test.expected_result, | |
755 FromGWSPageLoadMetricsLogger::IsGoogleSearchHostname(GURL(test.url))) | |
756 << "for URL: " << test.url; | |
757 } | |
758 } | |
759 | |
760 TEST_F(FromGWSPageLoadMetricsLoggerTest, IsGoogleSearchResultUrl) { | |
761 struct { | |
762 bool expected_result; | |
763 const char* url; | |
764 } test_cases[] = { | |
765 {true, "https://www.google.com/#q=test"}, | |
766 {true, "https://www.google.com/search#q=test"}, | |
767 {true, "https://www.google.com/search?q=test"}, | |
768 {true, "https://www.google.com/webhp#q=test"}, | |
769 {true, "https://www.google.com/webhp?q=test"}, | |
770 {true, "https://www.google.com/webhp?a=b&q=test"}, | |
771 {true, "https://www.google.com/webhp?a=b&q=test&c=d"}, | |
772 {true, "https://www.google.com/webhp#a=b&q=test&c=d"}, | |
773 {true, "https://www.google.com/webhp?#a=b&q=test&c=d"}, | |
774 {false, "https://www.google.com/"}, | |
775 {false, "https://www.google.com/about/"}, | |
776 {false, "https://other.google.com/"}, | |
777 {false, "https://other.google.com/webhp?q=test"}, | |
778 {false, kExampleUrl}, | |
779 {false, "https://www.example.com/webhp?q=test"}, | |
780 {false, "https://google.com/#q=test"}, | |
781 }; | |
782 for (const auto& test : test_cases) { | |
783 EXPECT_EQ( | |
784 test.expected_result, | |
785 FromGWSPageLoadMetricsLogger::IsGoogleSearchResultUrl(GURL(test.url))) | |
786 << "for URL: " << test.url; | |
787 } | |
788 } | |
789 | |
790 TEST_F(FromGWSPageLoadMetricsLoggerTest, IsGoogleSearchRedirectorUrl) { | |
791 struct { | |
792 bool expected_result; | |
793 const char* url; | |
794 } test_cases[] = { | |
795 {true, "https://www.google.com/url?source=web"}, | |
796 {true, "https://www.google.com/url?source=web#foo"}, | |
797 {true, "https://www.google.com/searchurl/r.html#foo"}, | |
798 {true, "https://www.google.com/url?a=b&source=web&c=d"}, | |
799 {false, "https://www.google.com/?"}, | |
800 {false, "https://www.google.com/?url"}, | |
801 {false, "https://www.example.com/url?source=web"}, | |
802 {false, "https://google.com/url?"}, | |
803 {false, "https://www.google.com/?source=web"}, | |
804 {false, "https://www.google.com/source=web"}, | |
805 {false, "https://www.example.com/url?source=web"}, | |
806 {false, "https://www.google.com/url?"}, | |
807 {false, "https://www.google.com/url?a=b"}, | |
808 }; | |
809 for (const auto& test : test_cases) { | |
810 EXPECT_EQ(test.expected_result, | |
811 FromGWSPageLoadMetricsLogger::IsGoogleSearchRedirectorUrl( | |
812 GURL(test.url))) | |
813 << "for URL: " << test.url; | |
814 } | |
815 } | |
816 | |
817 TEST_F(FromGWSPageLoadMetricsLoggerTest, QueryContainsComponent) { | |
818 struct { | |
819 bool expected_result; | |
820 const char* query; | |
821 const char* component; | |
822 } test_cases[] = { | |
823 {true, "a=b", "a=b"}, | |
824 {true, "a=b&c=d", "a=b"}, | |
825 {true, "a=b&c=d", "c=d"}, | |
826 {true, "a=b&c=d&e=f", "c=d"}, | |
827 {true, "za=b&a=b", "a=b"}, | |
828 {true, "a=bz&a=b", "a=b"}, | |
829 {true, "a=ba=b&a=b", "a=b"}, | |
830 {true, "a=a=a&a=a", "a=a"}, | |
831 {true, "source=web", "source=web"}, | |
832 {true, "a=b&source=web", "source=web"}, | |
833 {true, "a=b&source=web&c=d", "source=web"}, | |
834 {false, "a=a=a", "a=a"}, | |
835 {false, "", ""}, | |
836 {false, "a=b", ""}, | |
837 {false, "", "a=b"}, | |
838 {false, "za=b", "a=b"}, | |
839 {false, "za=bz", "a=b"}, | |
840 {false, "a=bz", "a=b"}, | |
841 {false, "za=b&c=d", "a=b"}, | |
842 {false, "a=b&c=dz", "c=d"}, | |
843 {false, "a=b&zc=d&e=f", "c=d"}, | |
844 {false, "a=b&c=dz&e=f", "c=d"}, | |
845 {false, "a=b&zc=dz&e=f", "c=d"}, | |
846 {false, "a=b&foosource=web&c=d", "source=web"}, | |
847 {false, "a=b&source=webbar&c=d", "source=web"}, | |
848 {false, "a=b&foosource=webbar&c=d", "source=web"}, | |
849 }; | |
850 for (const auto& test : test_cases) { | |
851 EXPECT_EQ(test.expected_result, | |
852 FromGWSPageLoadMetricsLogger::QueryContainsComponent( | |
853 test.query, test.component)) | |
854 << "For query: " << test.query << " with component: " << test.component; | |
855 } | |
856 } | |
857 | |
858 TEST_F(FromGWSPageLoadMetricsLoggerTest, QueryContainsComponentPrefix) { | |
859 struct { | |
860 bool expected_result; | |
861 const char* query; | |
862 const char* component; | |
863 } test_cases[] = { | |
864 {true, "a=b", "a="}, | |
865 {true, "a=b&c=d", "a="}, | |
866 {true, "a=b&c=d", "c="}, | |
867 {true, "a=b&c=d&e=f", "c="}, | |
868 {true, "za=b&a=b", "a="}, | |
869 {true, "ba=a=b&a=b", "a="}, | |
870 {true, "q=test", "q="}, | |
871 {true, "a=b&q=test", "q="}, | |
872 {true, "q=test&c=d", "q="}, | |
873 {true, "a=b&q=test&c=d", "q="}, | |
874 {false, "", ""}, | |
875 {false, "za=b", "a="}, | |
876 {false, "za=b&c=d", "a="}, | |
877 {false, "a=b&zc=d", "c="}, | |
878 {false, "a=b&zc=d&e=f", "c="}, | |
879 {false, "a=b&zq=test&c=d", "q="}, | |
880 {false, "ba=a=b", "a="}, | |
881 }; | |
882 for (const auto& test : test_cases) { | |
883 EXPECT_EQ(test.expected_result, | |
884 FromGWSPageLoadMetricsLogger::QueryContainsComponentPrefix( | |
885 test.query, test.component)) | |
886 << "For query: " << test.query << " with component: " << test.component; | |
887 } | |
888 } | |
889 | |
890 TEST_F(FromGWSPageLoadMetricsLoggerTest, Basic) { | 735 TEST_F(FromGWSPageLoadMetricsLoggerTest, Basic) { |
891 FromGWSPageLoadMetricsLogger logger; | 736 FromGWSPageLoadMetricsLogger logger; |
892 ASSERT_FALSE(logger.ShouldLogPostCommitMetrics(GURL(kExampleUrl))); | 737 ASSERT_FALSE(logger.ShouldLogPostCommitMetrics(GURL(kExampleUrl))); |
893 } | 738 } |
894 | 739 |
895 TEST_F(FromGWSPageLoadMetricsLoggerTest, NoPreviousPage) { | 740 TEST_F(FromGWSPageLoadMetricsLoggerTest, NoPreviousPage) { |
896 FromGWSPageLoadMetricsLogger logger; | 741 FromGWSPageLoadMetricsLogger logger; |
897 logger.SetPreviouslyCommittedUrl(GURL()); | 742 logger.SetPreviouslyCommittedUrl(GURL()); |
898 logger.set_navigation_initiated_via_link(true); | 743 logger.set_navigation_initiated_via_link(true); |
899 ASSERT_FALSE(logger.ShouldLogPostCommitMetrics(GURL(kExampleUrl))); | 744 ASSERT_FALSE(logger.ShouldLogPostCommitMetrics(GURL(kExampleUrl))); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 logger.ShouldLogPostCommitMetrics(GURL("https://www.google.com/about/"))); | 797 logger.ShouldLogPostCommitMetrics(GURL("https://www.google.com/about/"))); |
953 } | 798 } |
954 | 799 |
955 TEST_F(FromGWSPageLoadMetricsLoggerTest, NavigationFromSearchRedirector) { | 800 TEST_F(FromGWSPageLoadMetricsLoggerTest, NavigationFromSearchRedirector) { |
956 FromGWSPageLoadMetricsLogger logger; | 801 FromGWSPageLoadMetricsLogger logger; |
957 logger.SetPreviouslyCommittedUrl( | 802 logger.SetPreviouslyCommittedUrl( |
958 GURL("https://www.google.com/url?source=web")); | 803 GURL("https://www.google.com/url?source=web")); |
959 logger.set_navigation_initiated_via_link(true); | 804 logger.set_navigation_initiated_via_link(true); |
960 ASSERT_TRUE(logger.ShouldLogPostCommitMetrics(GURL(kExampleUrl))); | 805 ASSERT_TRUE(logger.ShouldLogPostCommitMetrics(GURL(kExampleUrl))); |
961 } | 806 } |
OLD | NEW |