| 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 "components/search_engines/detect_desktop_search_win.h" | 5 #include "components/search_engines/desktop_search_win.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "components/search_engines/testing_search_terms_data.h" | 9 #include "components/search_engines/testing_search_terms_data.h" |
| 10 #include "components/syncable_prefs/testing_pref_service_syncable.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 struct DetectWindowsDesktopSearchTestData { | 15 struct DetectWindowsDesktopSearchTestData { |
| 15 const char* url; | 16 const char* url; |
| 16 const wchar_t* expected_search_terms; | 17 const wchar_t* expected_search_terms; |
| 17 }; | 18 }; |
| 18 } // namespace | 19 } // namespace |
| 19 | 20 |
| 20 TEST(DetectWindowsDesktopSearch, DetectWindowsDesktopSearch) { | 21 TEST(WindowsDesktopSearch, Prefs) { |
| 22 const char kWindowsDesktopSearchRedirectionPref[] = |
| 23 "windows_desktop_search_redirection"; |
| 24 |
| 25 syncable_prefs::TestingPrefServiceSyncable prefs; |
| 26 RegisterWindowsDesktopSearchRedirectionPref(prefs.registry()); |
| 27 |
| 28 EXPECT_EQ(WindowsDesktopSearchRedirectionPref::UNSET, |
| 29 GetWindowsDesktopSearchRedirectionPref(&prefs)); |
| 30 prefs.SetBoolean(kWindowsDesktopSearchRedirectionPref, true); |
| 31 EXPECT_EQ(WindowsDesktopSearchRedirectionPref::ENABLED, |
| 32 GetWindowsDesktopSearchRedirectionPref(&prefs)); |
| 33 prefs.SetBoolean(kWindowsDesktopSearchRedirectionPref, false); |
| 34 EXPECT_EQ(WindowsDesktopSearchRedirectionPref::DISABLED, |
| 35 GetWindowsDesktopSearchRedirectionPref(&prefs)); |
| 36 } |
| 37 |
| 38 TEST(WindowsDesktopSearch, DetectWindowsDesktopSearch) { |
| 21 const DetectWindowsDesktopSearchTestData test_data[] = { | 39 const DetectWindowsDesktopSearchTestData test_data[] = { |
| 22 {"https://www.google.com", L""}, | 40 {"https://www.google.com", L""}, |
| 23 {"https://www.bing.com/search", L""}, | 41 {"https://www.bing.com/search", L""}, |
| 24 {"https://www.bing.com/search?q=keyword&form=QBLH", L""}, | 42 {"https://www.bing.com/search?q=keyword&form=QBLH", L""}, |
| 25 {"https://www.bing.com/search?q=keyword&form=WNSGPH", L"keyword"}, | 43 {"https://www.bing.com/search?q=keyword&form=WNSGPH", L"keyword"}, |
| 26 {"https://www.bing.com/search?q=keyword&form=WNSBOX", L"keyword"}, | 44 {"https://www.bing.com/search?q=keyword&form=WNSBOX", L"keyword"}, |
| 27 {"https://www.bing.com/search?q=keyword&FORM=WNSGPH", L"keyword"}, | 45 {"https://www.bing.com/search?q=keyword&FORM=WNSGPH", L"keyword"}, |
| 28 {"https://www.bing.com/search?q=keyword&FORM=WNSBOX", L"keyword"}, | 46 {"https://www.bing.com/search?q=keyword&FORM=WNSBOX", L"keyword"}, |
| 29 {"https://www.bing.com/search?form=WNSGPH&q=keyword", L"keyword"}, | 47 {"https://www.bing.com/search?form=WNSGPH&q=keyword", L"keyword"}, |
| 30 {"https://www.bing.com/search?q=keyword&form=WNSGPH&other=stuff", | 48 {"https://www.bing.com/search?q=keyword&form=WNSGPH&other=stuff", |
| 31 L"keyword"}, | 49 L"keyword"}, |
| 32 {"https://www.bing.com/search?q=%C3%A8+%C3%A9&form=WNSGPH", L"\xE8 \xE9"}, | 50 {"https://www.bing.com/search?q=%C3%A8+%C3%A9&form=WNSGPH", L"\xE8 \xE9"}, |
| 33 }; | 51 }; |
| 34 | 52 |
| 35 for (size_t i = 0; i < arraysize(test_data); ++i) { | 53 for (size_t i = 0; i < arraysize(test_data); ++i) { |
| 36 TestingSearchTermsData search_terms_data("https://www.google.com"); | 54 TestingSearchTermsData search_terms_data("https://www.google.com"); |
| 37 base::string16 search_terms; | 55 base::string16 search_terms; |
| 38 bool is_desktop_search = DetectWindowsDesktopSearch( | 56 bool is_desktop_search = DetectWindowsDesktopSearch( |
| 39 GURL(test_data[i].url), search_terms_data, &search_terms); | 57 GURL(test_data[i].url), search_terms_data, &search_terms); |
| 40 const base::string16 expected_search_terms( | 58 const base::string16 expected_search_terms( |
| 41 test_data[i].expected_search_terms); | 59 test_data[i].expected_search_terms); |
| 42 EXPECT_EQ(!expected_search_terms.empty(), is_desktop_search); | 60 EXPECT_EQ(!expected_search_terms.empty(), is_desktop_search); |
| 43 EXPECT_EQ(expected_search_terms, search_terms); | 61 EXPECT_EQ(expected_search_terms, search_terms); |
| 44 } | 62 } |
| 45 } | 63 } |
| OLD | NEW |