OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
9 #include "chrome/browser/search_engines/template_url_service_factory.h" | 9 #include "chrome/browser/search_engines/template_url_service_factory.h" |
10 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 10 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const GURL& new_tab_url() const { return new_tab_url_; } | 45 const GURL& new_tab_url() const { return new_tab_url_; } |
46 void set_new_tab_url(const GURL& url) { new_tab_url_ = url; } | 46 void set_new_tab_url(const GURL& url) { new_tab_url_ = url; } |
47 | 47 |
48 void ChangeDefaultSearchProvider(const char* new_tab_path) { | 48 void ChangeDefaultSearchProvider(const char* new_tab_path) { |
49 TemplateURLService* template_url_service = | 49 TemplateURLService* template_url_service = |
50 TemplateURLServiceFactory::GetForProfile(browser()->profile()); | 50 TemplateURLServiceFactory::GetForProfile(browser()->profile()); |
51 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); | 51 ui_test_utils::WaitForTemplateURLServiceToLoad(template_url_service); |
52 UIThreadSearchTermsData::SetGoogleBaseURL("https://mock.http/"); | 52 UIThreadSearchTermsData::SetGoogleBaseURL("https://mock.http/"); |
53 std::string base_url("{google:baseURL}"); | 53 std::string base_url("{google:baseURL}"); |
54 TemplateURLData data; | 54 TemplateURLData data; |
| 55 data.SetShortName(base::ASCIIToUTF16("Google")); |
55 data.SetKeyword(base::UTF8ToUTF16(base_url)); | 56 data.SetKeyword(base::UTF8ToUTF16(base_url)); |
56 data.SetURL(base_url + "url?bar={searchTerms}"); | 57 data.SetURL(base_url + "url?bar={searchTerms}"); |
57 data.new_tab_url = base_url + new_tab_path; | 58 data.new_tab_url = base_url + new_tab_path; |
58 TemplateURL* template_url = new TemplateURL(data); | 59 TemplateURL* template_url = new TemplateURL(data); |
59 // Takes ownership of |template_url|. | 60 // Takes ownership of |template_url|. |
60 template_url_service->Add(template_url); | 61 template_url_service->Add(template_url); |
61 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); | 62 template_url_service->SetUserSelectedDefaultSearchProvider(template_url); |
62 } | 63 } |
63 | 64 |
64 static GURL GetMockURL(const base::FilePath::StringType& path) { | 65 static GURL GetMockURL(const base::FilePath::StringType& path) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 ChangeDefaultSearchProvider("notarealfile.html"); | 114 ChangeDefaultSearchProvider("notarealfile.html"); |
114 | 115 |
115 ui_test_utils::NavigateToURL(browser(), new_tab_url()); | 116 ui_test_utils::NavigateToURL(browser(), new_tab_url()); |
116 content::WebContents* contents = | 117 content::WebContents* contents = |
117 browser()->tab_strip_model()->GetWebContentsAt(0); | 118 browser()->tab_strip_model()->GetWebContentsAt(0); |
118 content::NavigationController* controller = &contents->GetController(); | 119 content::NavigationController* controller = &contents->GetController(); |
119 // Failed navigation makes a redirect to the local NTP. | 120 // Failed navigation makes a redirect to the local NTP. |
120 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), | 121 EXPECT_EQ(GURL(chrome::kChromeSearchLocalNtpUrl), |
121 controller->GetLastCommittedEntry()->GetURL()); | 122 controller->GetLastCommittedEntry()->GetURL()); |
122 } | 123 } |
OLD | NEW |