template_url_scraper_unittest.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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. 4 5#include "chrome/browser/profiles/profile.h" 6#include "chrome/browser/search_engines/template_url_prepopulate_data.h" 7#include "chrome/browser/search_engines/template_url_service.h" 8#include "chrome/browser/search_engines/template_url_service_factory.h" 9#include "chrome/browser/ui/browser.h" 10#include "chrome/common/chrome_notification_types.h" 11#include "chrome/test/base/in_process_browser_test.h" 12#include "chrome/test/base/ui_test_utils.h" 13#include "content/public/browser/notification_registrar.h" 14#include "content/public/browser/notification_source.h" 15#include "net/base/net_util.h" 16#include "net/dns/mock_host_resolver.h" 17 18namespace { 19class TemplateURLScraperTest : public InProcessBrowserTest { 20 public: 21 TemplateURLScraperTest() { 22 } 23 24 private: 25 DISALLOW_COPY_AND_ASSIGN(TemplateURLScraperTest); 26}; 27 28class TemplateURLServiceLoader : public content::NotificationObserver { 29 public: 30 explicit TemplateURLServiceLoader(TemplateURLService* model) : model_(model) { 31 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, 32 content::Source<TemplateURLService>(model)); 33 model_->Load(); 34 content::RunMessageLoop(); 35 } 36 37 virtual void Observe(int type, 38 const content::NotificationSource& source, 39 const content::NotificationDetails& details) { 40 if (type == chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED && 41 content::Source<TemplateURLService>(source).ptr() == model_) { 42 base::MessageLoop::current()->Quit(); 43 } 44 } 45 46 private: 47 content::NotificationRegistrar registrar_; 48 49 TemplateURLService* model_; 50 51 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceLoader); 52}; 53 54} // namespace 55 56/* 57IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) { 58 host_resolver()->AddRule("*.foo.com", "localhost"); 59 60 TemplateURLService* template_urls = 61 TemplateURLServiceFactory::GetInstance(browser()->profile()); 62 TemplateURLServiceLoader loader(template_urls); 63 64 TemplateURLService::TemplateURLVector all_urls = 65 template_urls->GetTemplateURLs(); 66 67 // We need to substract the default pre-populated engines that the profile is 68 // set up with. 69 size_t default_index = 0; 70 std::vector<TemplateURL*> prepopulate_urls; 71 TemplateURLPrepopulateData::GetPrepopulatedEngines( 72 browser()->profile()->GetPrefs(), 73 &prepopulate_urls, 74 &default_index); 75 76 EXPECT_EQ(prepopulate_urls.size(), all_urls.size()); 77 78 scoped_refptr<HTTPTestServer> server( 79 HTTPTestServer::CreateServerWithFileRootURL( 80 L"chrome/test/data/template_url_scraper/submit_handler", L"/", 81 g_browser_process->io_thread()->message_loop())); 82 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( 83 browser(), GURL("http://www.foo.com:1337/"), 2); 84 85 all_urls = template_urls->GetTemplateURLs(); 86 EXPECT_EQ(1, all_urls.size() - prepopulate_urls.size()); 87} 88*/ 89