Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / search_engines / template_url_scraper_unittest.cc
blob719a2960357d5330b70f96f54cc39798ccc7f55d
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
3 // found in the LICENSE file.
5 #include "chrome/browser/profiles/profile.h"
6 #include "chrome/browser/search_engines/template_url_service_factory.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/test/base/in_process_browser_test.h"
9 #include "chrome/test/base/ui_test_utils.h"
10 #include "components/search_engines/template_url_prepopulate_data.h"
11 #include "components/search_engines/template_url_service.h"
12 #include "net/base/net_util.h"
13 #include "net/dns/mock_host_resolver.h"
15 namespace {
16 class TemplateURLScraperTest : public InProcessBrowserTest {
17 public:
18 TemplateURLScraperTest() {
21 private:
22 DISALLOW_COPY_AND_ASSIGN(TemplateURLScraperTest);
25 class TemplateURLServiceLoader {
26 public:
27 explicit TemplateURLServiceLoader(TemplateURLService* model) : model_(model) {
28 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
29 new content::MessageLoopRunner;
30 scoped_ptr<TemplateURLService::Subscription> subscription =
31 model_->RegisterOnLoadedCallback(
32 message_loop_runner->QuitClosure());
33 model_->Load();
34 message_loop_runner->Run();
37 private:
38 TemplateURLService* model_;
40 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceLoader);
43 } // namespace
46 IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) {
47 host_resolver()->AddRule("*.foo.com", "localhost");
49 TemplateURLService* template_urls =
50 TemplateURLServiceFactory::GetInstance(browser()->profile());
51 TemplateURLServiceLoader loader(template_urls);
53 TemplateURLService::TemplateURLVector all_urls =
54 template_urls->GetTemplateURLs();
56 // We need to substract the default pre-populated engines that the profile is
57 // set up with.
58 size_t default_index = 0;
59 std::vector<TemplateURL*> prepopulate_urls;
60 TemplateURLPrepopulateData::GetPrepopulatedEngines(
61 browser()->profile()->GetPrefs(),
62 &prepopulate_urls,
63 &default_index);
65 EXPECT_EQ(prepopulate_urls.size(), all_urls.size());
67 scoped_refptr<HTTPTestServer> server(
68 HTTPTestServer::CreateServerWithFileRootURL(
69 L"chrome/test/data/template_url_scraper/submit_handler", L"/",
70 g_browser_process->io_thread()->message_loop()));
71 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
72 browser(), GURL("http://www.foo.com:1337/"), 2);
74 all_urls = template_urls->GetTemplateURLs();
75 EXPECT_EQ(1, all_urls.size() - prepopulate_urls.size());