| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browser.h" | 5 #include "chrome/browser/browser.h" |
| 6 #include "chrome/browser/profile.h" | 6 #include "chrome/browser/profile.h" |
| 7 #include "chrome/browser/search_engines/template_url_model.h" | 7 #include "chrome/browser/search_engines/template_url_model.h" |
| 8 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 8 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 9 #include "chrome/common/notification_registrar.h" | 9 #include "chrome/common/notification_registrar.h" |
| 10 #include "chrome/common/notification_source.h" | 10 #include "chrome/common/notification_source.h" |
| 11 #include "chrome/common/notification_type.h" | 11 #include "chrome/common/notification_type.h" |
| 12 #include "chrome/test/in_process_browser_test.h" | 12 #include "chrome/test/in_process_browser_test.h" |
| 13 #include "chrome/test/ui_test_utils.h" | 13 #include "chrome/test/ui_test_utils.h" |
| 14 #include "net/base/mock_host_resolver.h" | 14 #include "net/base/mock_host_resolver.h" |
| 15 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 class TemplateURLScraperTest : public InProcessBrowserTest { | 18 class TemplateURLScraperTest : public InProcessBrowserTest { |
| 19 public: | 19 public: |
| 20 TemplateURLScraperTest() { | 20 TemplateURLScraperTest() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 protected: | |
| 24 virtual void ConfigureHostResolverProc(net::RuleBasedHostResolverProc* proc) { | |
| 25 InProcessBrowserTest::ConfigureHostResolverProc(proc); | |
| 26 // We use foo.com in our tests. | |
| 27 proc->AddRule("*.foo.com", "localhost"); | |
| 28 } | |
| 29 | |
| 30 private: | 23 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(TemplateURLScraperTest); | 24 DISALLOW_COPY_AND_ASSIGN(TemplateURLScraperTest); |
| 32 }; | 25 }; |
| 33 | 26 |
| 34 class TemplateURLModelLoader : public NotificationObserver { | 27 class TemplateURLModelLoader : public NotificationObserver { |
| 35 public: | 28 public: |
| 36 explicit TemplateURLModelLoader(TemplateURLModel* model) : model_(model) { | 29 explicit TemplateURLModelLoader(TemplateURLModel* model) : model_(model) { |
| 37 registrar_.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED, | 30 registrar_.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED, |
| 38 Source<TemplateURLModel>(model)); | 31 Source<TemplateURLModel>(model)); |
| 39 model_->Load(); | 32 model_->Load(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 54 | 47 |
| 55 TemplateURLModel* model_; | 48 TemplateURLModel* model_; |
| 56 | 49 |
| 57 DISALLOW_COPY_AND_ASSIGN(TemplateURLModelLoader); | 50 DISALLOW_COPY_AND_ASSIGN(TemplateURLModelLoader); |
| 58 }; | 51 }; |
| 59 | 52 |
| 60 } // namespace | 53 } // namespace |
| 61 | 54 |
| 62 /* | 55 /* |
| 63 IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) { | 56 IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) { |
| 57 host_resolver()->AddRule("*.foo.com", "localhost"); |
| 58 |
| 64 TemplateURLModel* template_urls = browser()->profile()->GetTemplateURLModel(); | 59 TemplateURLModel* template_urls = browser()->profile()->GetTemplateURLModel(); |
| 65 TemplateURLModelLoader loader(template_urls); | 60 TemplateURLModelLoader loader(template_urls); |
| 66 | 61 |
| 67 std::vector<const TemplateURL*> all_urls = template_urls->GetTemplateURLs(); | 62 std::vector<const TemplateURL*> all_urls = template_urls->GetTemplateURLs(); |
| 68 | 63 |
| 69 // We need to substract the default pre-populated engines that the profile is | 64 // We need to substract the default pre-populated engines that the profile is |
| 70 // set up with. | 65 // set up with. |
| 71 size_t default_index = 0; | 66 size_t default_index = 0; |
| 72 std::vector<TemplateURL*> prepopulate_urls; | 67 std::vector<TemplateURL*> prepopulate_urls; |
| 73 TemplateURLPrepopulateData::GetPrepopulatedEngines( | 68 TemplateURLPrepopulateData::GetPrepopulatedEngines( |
| 74 browser()->profile()->GetPrefs(), | 69 browser()->profile()->GetPrefs(), |
| 75 &prepopulate_urls, | 70 &prepopulate_urls, |
| 76 &default_index); | 71 &default_index); |
| 77 | 72 |
| 78 EXPECT_EQ(prepopulate_urls.size(), all_urls.size()); | 73 EXPECT_EQ(prepopulate_urls.size(), all_urls.size()); |
| 79 | 74 |
| 80 scoped_refptr<HTTPTestServer> server( | 75 scoped_refptr<HTTPTestServer> server( |
| 81 HTTPTestServer::CreateServerWithFileRootURL( | 76 HTTPTestServer::CreateServerWithFileRootURL( |
| 82 L"chrome/test/data/template_url_scraper/submit_handler", L"/", | 77 L"chrome/test/data/template_url_scraper/submit_handler", L"/", |
| 83 g_browser_process->io_thread()->message_loop())); | 78 g_browser_process->io_thread()->message_loop())); |
| 84 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 79 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 85 browser(), GURL("http://www.foo.com:1337/"), 2); | 80 browser(), GURL("http://www.foo.com:1337/"), 2); |
| 86 | 81 |
| 87 all_urls = template_urls->GetTemplateURLs(); | 82 all_urls = template_urls->GetTemplateURLs(); |
| 88 EXPECT_EQ(1, all_urls.size() - prepopulate_urls.size()); | 83 EXPECT_EQ(1, all_urls.size() - prepopulate_urls.size()); |
| 89 } | 84 } |
| 90 */ | 85 */ |
| OLD | NEW |