| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/search/instant_test_utils.h" | 5 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 void InstantTestBase::SetupInstant(Browser* browser) { | 47 void InstantTestBase::SetupInstant(Browser* browser) { |
| 48 browser_ = browser; | 48 browser_ = browser; |
| 49 | 49 |
| 50 TemplateURLService* service = | 50 TemplateURLService* service = |
| 51 TemplateURLServiceFactory::GetForProfile(browser_->profile()); | 51 TemplateURLServiceFactory::GetForProfile(browser_->profile()); |
| 52 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 52 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
| 53 | 53 |
| 54 TemplateURLData data; | 54 TemplateURLData data; |
| 55 // Necessary to use exact URL for both the main URL and the alternate URL for | 55 // Necessary to use exact URL for both the main URL and the alternate URL for |
| 56 // search term extraction to work in InstantExtended. | 56 // search term extraction to work in InstantExtended. |
| 57 data.short_name = base::ASCIIToUTF16("name"); | 57 data.SetShortName(base::ASCIIToUTF16("name")); |
| 58 data.SetURL(instant_url_.spec() + | 58 data.SetURL(instant_url_.spec() + |
| 59 "q={searchTerms}&is_search&{google:omniboxStartMarginParameter}"); | 59 "q={searchTerms}&is_search&{google:omniboxStartMarginParameter}"); |
| 60 data.instant_url = instant_url_.spec(); | 60 data.instant_url = instant_url_.spec(); |
| 61 data.new_tab_url = ntp_url_.spec(); | 61 data.new_tab_url = ntp_url_.spec(); |
| 62 if (init_suggestions_url_) | 62 if (init_suggestions_url_) |
| 63 data.suggestions_url = instant_url_.spec() + "#q={searchTerms}"; | 63 data.suggestions_url = instant_url_.spec() + "#q={searchTerms}"; |
| 64 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); | 64 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); |
| 65 data.search_terms_replacement_key = "strk"; | 65 data.search_terms_replacement_key = "strk"; |
| 66 | 66 |
| 67 TemplateURL* template_url = new TemplateURL(data); | 67 TemplateURL* template_url = new TemplateURL(data); |
| 68 service->Add(template_url); // Takes ownership of |template_url|. | 68 service->Add(template_url); // Takes ownership of |template_url|. |
| 69 service->SetUserSelectedDefaultSearchProvider(template_url); | 69 service->SetUserSelectedDefaultSearchProvider(template_url); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void InstantTestBase::SetInstantURL(const std::string& url) { | 72 void InstantTestBase::SetInstantURL(const std::string& url) { |
| 73 TemplateURLService* service = | 73 TemplateURLService* service = |
| 74 TemplateURLServiceFactory::GetForProfile(browser_->profile()); | 74 TemplateURLServiceFactory::GetForProfile(browser_->profile()); |
| 75 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 75 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
| 76 | 76 |
| 77 TemplateURLData data; | 77 TemplateURLData data; |
| 78 data.short_name = base::ASCIIToUTF16("name"); | 78 data.SetShortName(base::ASCIIToUTF16("name")); |
| 79 data.SetURL(url); | 79 data.SetURL(url); |
| 80 data.instant_url = url; | 80 data.instant_url = url; |
| 81 | 81 |
| 82 TemplateURL* template_url = new TemplateURL(data); | 82 TemplateURL* template_url = new TemplateURL(data); |
| 83 service->Add(template_url); // Takes ownership of |template_url|. | 83 service->Add(template_url); // Takes ownership of |template_url|. |
| 84 service->SetUserSelectedDefaultSearchProvider(template_url); | 84 service->SetUserSelectedDefaultSearchProvider(template_url); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void InstantTestBase::Init(const GURL& instant_url, | 87 void InstantTestBase::Init(const GURL& instant_url, |
| 88 const GURL& ntp_url, | 88 const GURL& ntp_url, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded); | 170 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded); |
| 171 } | 171 } |
| 172 | 172 |
| 173 base::string16 InstantTestBase::GetBlueText() { | 173 base::string16 InstantTestBase::GetBlueText() { |
| 174 size_t start = 0, end = 0; | 174 size_t start = 0, end = 0; |
| 175 omnibox()->GetSelectionBounds(&start, &end); | 175 omnibox()->GetSelectionBounds(&start, &end); |
| 176 if (start > end) | 176 if (start > end) |
| 177 std::swap(start, end); | 177 std::swap(start, end); |
| 178 return omnibox()->GetText().substr(start, end - start); | 178 return omnibox()->GetText().substr(start, end - start); |
| 179 } | 179 } |
| OLD | NEW |