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 "chrome/browser/chrome_notification_types.h" | |
| 6 #include "chrome/browser/profiles/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
| 7 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" | 6 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" |
| 8 #include "chrome/browser/search_engines/template_url_service.h" | 7 #include "chrome/browser/search_engines/template_url_service.h" |
| 9 #include "chrome/browser/search_engines/template_url_service_factory.h" | 8 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 10 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "chrome/test/base/ui_test_utils.h" | 11 #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" | 12 #include "net/base/net_util.h" |
| 16 #include "net/dns/mock_host_resolver.h" | 13 #include "net/dns/mock_host_resolver.h" |
| 17 | 14 |
| 18 namespace { | 15 namespace { |
| 19 class TemplateURLScraperTest : public InProcessBrowserTest { | 16 class TemplateURLScraperTest : public InProcessBrowserTest { |
| 20 public: | 17 public: |
| 21 TemplateURLScraperTest() { | 18 TemplateURLScraperTest() { |
| 22 } | 19 } |
| 23 | 20 |
| 24 private: | 21 private: |
| 25 DISALLOW_COPY_AND_ASSIGN(TemplateURLScraperTest); | 22 DISALLOW_COPY_AND_ASSIGN(TemplateURLScraperTest); |
| 26 }; | 23 }; |
| 27 | 24 |
| 28 class TemplateURLServiceLoader : public content::NotificationObserver { | 25 scoped_refptr<content::MessageLoopRunner> message_loop_runner = new |
| 26 content::MessageLoopRunner; | |
| 27 scoped_ptr<TemplateURLService::Subscription> subscription = | |
| 28 model_->RegisterOnLoadedCallback( | |
| 29 message_loop_runner->QuitClosure()); | |
| 30 model_->Load(); | |
| 31 message_loop_runner->Run(); | |
|
Avi (use Gerrit)
2013/10/03 17:53:51
Er... this block of code is outside any function.
Cait (Slow)
2013/10/03 20:39:15
oops.
| |
| 32 | |
| 33 class TemplateURLServiceLoader { | |
| 29 public: | 34 public: |
| 30 explicit TemplateURLServiceLoader(TemplateURLService* model) : model_(model) { | 35 explicit TemplateURLServiceLoader(TemplateURLService* model) : model_(model) { |
| 31 registrar_.Add(this, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 36 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
| 32 content::Source<TemplateURLService>(model)); | 37 new content::MessageLoopRunner; |
| 38 scoped_ptr<TemplateURLService::Subscription> subscription = | |
| 39 model_->RegisterOnLoadedCallback( | |
| 40 message_loop_runner->QuitClosure()); | |
| 33 model_->Load(); | 41 model_->Load(); |
| 34 content::RunMessageLoop(); | 42 message_loop_runner->Run(); |
| 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 } | 43 } |
| 45 | 44 |
| 46 private: | 45 private: |
| 47 content::NotificationRegistrar registrar_; | |
| 48 | |
| 49 TemplateURLService* model_; | 46 TemplateURLService* model_; |
| 50 | 47 |
| 51 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceLoader); | 48 DISALLOW_COPY_AND_ASSIGN(TemplateURLServiceLoader); |
| 52 }; | 49 }; |
| 53 | 50 |
| 54 } // namespace | 51 } // namespace |
| 55 | 52 |
| 56 /* | 53 /* |
| 57 IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) { | 54 IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) { |
| 58 host_resolver()->AddRule("*.foo.com", "localhost"); | 55 host_resolver()->AddRule("*.foo.com", "localhost"); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 79 HTTPTestServer::CreateServerWithFileRootURL( | 76 HTTPTestServer::CreateServerWithFileRootURL( |
| 80 L"chrome/test/data/template_url_scraper/submit_handler", L"/", | 77 L"chrome/test/data/template_url_scraper/submit_handler", L"/", |
| 81 g_browser_process->io_thread()->message_loop())); | 78 g_browser_process->io_thread()->message_loop())); |
| 82 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 79 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 83 browser(), GURL("http://www.foo.com:1337/"), 2); | 80 browser(), GURL("http://www.foo.com:1337/"), 2); |
| 84 | 81 |
| 85 all_urls = template_urls->GetTemplateURLs(); | 82 all_urls = template_urls->GetTemplateURLs(); |
| 86 EXPECT_EQ(1, all_urls.size() - prepopulate_urls.size()); | 83 EXPECT_EQ(1, all_urls.size() - prepopulate_urls.size()); |
| 87 } | 84 } |
| 88 */ | 85 */ |
| OLD | NEW |