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 <stddef.h> | 5 #include <stddef.h> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
20 #include "components/search_engines/template_url_prepopulate_data.h" | 20 #include "components/search_engines/template_url_prepopulate_data.h" |
21 #include "components/search_engines/template_url_service.h" | 21 #include "components/search_engines/template_url_service.h" |
22 #include "content/public/test/browser_test_utils.h" | 22 #include "content/public/test/browser_test_utils.h" |
23 #include "content/public/test/test_navigation_observer.h" | 23 #include "content/public/test/test_navigation_observer.h" |
24 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
25 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
26 #include "net/test/embedded_test_server/http_response.h" | 26 #include "net/test/embedded_test_server/http_response.h" |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 using TemplateURLScraperTest = InProcessBrowserTest; | 30 class TemplateURLScraperTest : public InProcessBrowserTest { |
| 31 public: |
| 32 void SetUpOnMainThread() override { |
| 33 host_resolver()->AddRule("*", "localhost"); |
| 34 } |
| 35 }; |
31 | 36 |
32 class TemplateURLServiceLoader { | 37 class TemplateURLServiceLoader { |
33 public: | 38 public: |
34 explicit TemplateURLServiceLoader(TemplateURLService* model) : model_(model) { | 39 explicit TemplateURLServiceLoader(TemplateURLService* model) : model_(model) { |
35 if (model_->loaded()) | 40 if (model_->loaded()) |
36 return; | 41 return; |
37 | 42 |
38 scoped_refptr<content::MessageLoopRunner> message_loop_runner = | 43 scoped_refptr<content::MessageLoopRunner> message_loop_runner = |
39 new content::MessageLoopRunner; | 44 new content::MessageLoopRunner; |
40 std::unique_ptr<TemplateURLService::Subscription> subscription = | 45 std::unique_ptr<TemplateURLService::Subscription> subscription = |
(...skipping 19 matching lines...) Expand all Loading... |
60 EXPECT_TRUE(base::ReadFileToString(index_file, &file_contents)); | 65 EXPECT_TRUE(base::ReadFileToString(index_file, &file_contents)); |
61 std::unique_ptr<net::test_server::BasicHttpResponse> response( | 66 std::unique_ptr<net::test_server::BasicHttpResponse> response( |
62 new net::test_server::BasicHttpResponse); | 67 new net::test_server::BasicHttpResponse); |
63 response->set_content(file_contents); | 68 response->set_content(file_contents); |
64 return std::move(response); | 69 return std::move(response); |
65 } | 70 } |
66 | 71 |
67 } // namespace | 72 } // namespace |
68 | 73 |
69 IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) { | 74 IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) { |
70 host_resolver()->AddRule("*.foo.com", "localhost"); | |
71 embedded_test_server()->RegisterRequestHandler(base::Bind(&SendResponse)); | 75 embedded_test_server()->RegisterRequestHandler(base::Bind(&SendResponse)); |
72 ASSERT_TRUE(embedded_test_server()->Start()); | 76 ASSERT_TRUE(embedded_test_server()->Start()); |
73 | 77 |
74 TemplateURLService* template_urls = | 78 TemplateURLService* template_urls = |
75 TemplateURLServiceFactory::GetInstance()->GetForProfile( | 79 TemplateURLServiceFactory::GetInstance()->GetForProfile( |
76 browser()->profile()); | 80 browser()->profile()); |
77 TemplateURLServiceLoader loader(template_urls); | 81 TemplateURLServiceLoader loader(template_urls); |
78 | 82 |
79 TemplateURLService::TemplateURLVector all_urls = | 83 TemplateURLService::TemplateURLVector all_urls = |
80 template_urls->GetTemplateURLs(); | 84 template_urls->GetTemplateURLs(); |
(...skipping 17 matching lines...) Expand all Loading... |
98 | 102 |
99 content::WebContents* web_contents = | 103 content::WebContents* web_contents = |
100 browser()->tab_strip_model()->GetActiveWebContents(); | 104 browser()->tab_strip_model()->GetActiveWebContents(); |
101 content::TestNavigationObserver observer(web_contents); | 105 content::TestNavigationObserver observer(web_contents); |
102 EXPECT_TRUE(content::ExecuteScript(web_contents, "submit_form()")); | 106 EXPECT_TRUE(content::ExecuteScript(web_contents, "submit_form()")); |
103 observer.Wait(); | 107 observer.Wait(); |
104 | 108 |
105 all_urls = template_urls->GetTemplateURLs(); | 109 all_urls = template_urls->GetTemplateURLs(); |
106 EXPECT_EQ(prepopulate_urls.size() + 1, all_urls.size()); | 110 EXPECT_EQ(prepopulate_urls.size() + 1, all_urls.size()); |
107 } | 111 } |
OLD | NEW |