Skip to content

Commit

Permalink
Force country ID for SearchEngineProviderP3ATest tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
goodov authored and rillian committed Oct 20, 2021
1 parent 2cebbce commit bd05904
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions browser/search_engines/search_engine_tracker_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,40 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/search_test_utils.h"
#include "components/country_codes/country_codes.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/search_engines/template_url_prepopulate_data.h"
#include "content/public/test/browser_test.h"

class SearchEngineProviderP3ATest : public InProcessBrowserTest {
public:
SearchEngineProviderP3ATest() {
histogram_tester_.reset(new base::HistogramTester);

create_services_subscription_ =
BrowserContextDependencyManager::GetInstance()
->RegisterCreateServicesCallbackForTesting(
base::BindRepeating(&OverrideCountryID, "US"));
}

private:
static void OverrideCountryID(const std::string& country_id,
content::BrowserContext* context) {
const int32_t id = country_codes::CountryCharsToCountryID(country_id.at(0),
country_id.at(1));
Profile::FromBrowserContext(context)->GetPrefs()->SetInteger(
country_codes::kCountryIDAtInstall, id);
}

protected:
std::unique_ptr<base::HistogramTester> histogram_tester_;
base::CallbackListSubscription create_services_subscription_;
};

IN_PROC_BROWSER_TEST_F(SearchEngineProviderP3ATest,
DISABLED_DefaultSearchEngineP3A) {
IN_PROC_BROWSER_TEST_F(SearchEngineProviderP3ATest, DefaultSearchEngineP3A) {
// Check that the metric is reported on startup.
histogram_tester_->ExpectUniqueSample(kDefaultSearchEngineMetric,
SearchEngineP3A::kGoogle, 1);
SearchEngineP3A::kBrave, 1);

auto* service =
TemplateURLServiceFactory::GetForProfile(browser()->profile());
Expand All @@ -56,8 +72,7 @@ IN_PROC_BROWSER_TEST_F(SearchEngineProviderP3ATest,
histogram_tester_->ExpectTotalCount(kDefaultSearchEngineMetric, 2);
}

IN_PROC_BROWSER_TEST_F(SearchEngineProviderP3ATest,
DISABLED_SwitchSearchEngineP3A) {
IN_PROC_BROWSER_TEST_F(SearchEngineProviderP3ATest, SwitchSearchEngineP3A) {
// Check that the metric is reported on startup.
// For some reason we record kNoSwitch twice, even through
// kDefaultSearchEngineMetric is only updated once at this point.
Expand Down

0 comments on commit bd05904

Please sign in to comment.