Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/template_url_service.h" | 5 #include "components/search_engines/template_url_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
| 20 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/task/cancelable_task_tracker.h" | 22 #include "base/task/cancelable_task_tracker.h" |
| 23 #include "base/test/histogram_tester.h" | |
| 23 #include "base/test/simple_test_clock.h" | 24 #include "base/test/simple_test_clock.h" |
| 24 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
| 25 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 26 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
| 27 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 28 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
| 28 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
| 29 #include "components/history/core/browser/history_service.h" | 30 #include "components/history/core/browser/history_service.h" |
| 30 #include "components/search_engines/keyword_web_data_service.h" | 31 #include "components/search_engines/keyword_web_data_service.h" |
| 31 #include "components/search_engines/search_engines_pref_names.h" | 32 #include "components/search_engines/search_engines_pref_names.h" |
| 32 #include "components/search_engines/search_engines_test_util.h" | 33 #include "components/search_engines/search_engines_test_util.h" |
| (...skipping 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1937 TemplateURL* update_url = | 1938 TemplateURL* update_url = |
| 1938 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); | 1939 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); |
| 1939 const Time update_last_modified = update_url->last_modified(); | 1940 const Time update_last_modified = update_url->last_modified(); |
| 1940 model()->SetUserSelectedDefaultSearchProvider(update_url); | 1941 model()->SetUserSelectedDefaultSearchProvider(update_url); |
| 1941 TemplateURL* reloaded_url = | 1942 TemplateURL* reloaded_url = |
| 1942 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); | 1943 model()->GetTemplateURLForKeyword(ASCIIToUTF16("engine_keyword")); |
| 1943 const Time reloaded_last_modified = reloaded_url->last_modified(); | 1944 const Time reloaded_last_modified = reloaded_url->last_modified(); |
| 1944 EXPECT_NE(original_last_modified, reloaded_last_modified); | 1945 EXPECT_NE(original_last_modified, reloaded_last_modified); |
| 1945 EXPECT_EQ(update_last_modified, reloaded_last_modified); | 1946 EXPECT_EQ(update_last_modified, reloaded_last_modified); |
| 1946 } | 1947 } |
| 1948 | |
| 1949 // Tests checks that Search.DefaultSearchChangeOrigin histogram is correctly | |
| 1950 // emitted when TemplateURLService is not yet loaded. | |
|
Peter Kasting
2017/04/14 08:02:00
Another way of testing would be to verify that Tem
| |
| 1951 TEST_F(TemplateURLServiceTest, ChangeDefaultEngineBeforeLoad) { | |
| 1952 TemplateURL* search_engine1 = model()->Add( | |
| 1953 base::MakeUnique<TemplateURL>(*GenerateDummyTemplateURLData("keyword1"))); | |
| 1954 DCHECK(search_engine1); | |
| 1955 TemplateURL* search_engine2 = model()->Add( | |
| 1956 base::MakeUnique<TemplateURL>(*GenerateDummyTemplateURLData("keyword2"))); | |
| 1957 DCHECK(search_engine2); | |
| 1958 | |
| 1959 base::HistogramTester histogram_tester; | |
| 1960 model()->SetUserSelectedDefaultSearchProvider(search_engine1); | |
| 1961 histogram_tester.ExpectTotalCount("Search.DefaultSearchChangeOrigin", 1); | |
| 1962 model()->SetUserSelectedDefaultSearchProvider(search_engine1); | |
| 1963 histogram_tester.ExpectTotalCount("Search.DefaultSearchChangeOrigin", 1); | |
| 1964 model()->SetUserSelectedDefaultSearchProvider(search_engine2); | |
| 1965 histogram_tester.ExpectTotalCount("Search.DefaultSearchChangeOrigin", 2); | |
| 1966 } | |
| OLD | NEW |