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 27 matching lines...) Expand all Loading... |
38 | 38 |
39 void InstantTestBase::SetupInstant(Browser* browser) { | 39 void InstantTestBase::SetupInstant(Browser* browser) { |
40 browser_ = browser; | 40 browser_ = browser; |
41 TemplateURLService* service = | 41 TemplateURLService* service = |
42 TemplateURLServiceFactory::GetForProfile(browser_->profile()); | 42 TemplateURLServiceFactory::GetForProfile(browser_->profile()); |
43 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 43 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
44 | 44 |
45 TemplateURLData data; | 45 TemplateURLData data; |
46 // Necessary to use exact URL for both the main URL and the alternate URL for | 46 // Necessary to use exact URL for both the main URL and the alternate URL for |
47 // search term extraction to work in InstantExtended. | 47 // search term extraction to work in InstantExtended. |
| 48 data.short_name = ASCIIToUTF16("name"); |
48 data.SetURL(instant_url_.spec() + | 49 data.SetURL(instant_url_.spec() + |
49 "q={searchTerms}&is_search&{google:omniboxStartMarginParameter}"); | 50 "q={searchTerms}&is_search&{google:omniboxStartMarginParameter}"); |
50 data.instant_url = instant_url_.spec(); | 51 data.instant_url = instant_url_.spec(); |
51 if (init_suggestions_url_) | 52 if (init_suggestions_url_) |
52 data.suggestions_url = instant_url_.spec() + "#q={searchTerms}"; | 53 data.suggestions_url = instant_url_.spec() + "#q={searchTerms}"; |
53 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); | 54 data.alternate_urls.push_back(instant_url_.spec() + "#q={searchTerms}"); |
54 data.search_terms_replacement_key = "strk"; | 55 data.search_terms_replacement_key = "strk"; |
55 | 56 |
56 TemplateURL* template_url = new TemplateURL(browser_->profile(), data); | 57 TemplateURL* template_url = new TemplateURL(browser_->profile(), data); |
57 service->Add(template_url); // Takes ownership of |template_url|. | 58 service->Add(template_url); // Takes ownership of |template_url|. |
58 service->SetDefaultSearchProvider(template_url); | 59 service->SetDefaultSearchProvider(template_url); |
59 | 60 |
60 InstantService* instant_service = | 61 InstantService* instant_service = |
61 InstantServiceFactory::GetForProfile(browser_->profile()); | 62 InstantServiceFactory::GetForProfile(browser_->profile()); |
62 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); | 63 ASSERT_NE(static_cast<InstantService*>(NULL), instant_service); |
63 instant_service->ntp_prerenderer()->ReloadStaleNTP(); | 64 instant_service->ntp_prerenderer()->ReloadStaleNTP(); |
64 } | 65 } |
65 | 66 |
66 void InstantTestBase::SetInstantURL(const std::string& url) { | 67 void InstantTestBase::SetInstantURL(const std::string& url) { |
67 TemplateURLService* service = | 68 TemplateURLService* service = |
68 TemplateURLServiceFactory::GetForProfile(browser_->profile()); | 69 TemplateURLServiceFactory::GetForProfile(browser_->profile()); |
69 ui_test_utils::WaitForTemplateURLServiceToLoad(service); | 70 ui_test_utils::WaitForTemplateURLServiceToLoad(service); |
70 | 71 |
71 TemplateURLData data; | 72 TemplateURLData data; |
| 73 data.short_name = ASCIIToUTF16("name"); |
72 data.SetURL(url); | 74 data.SetURL(url); |
73 data.instant_url = url; | 75 data.instant_url = url; |
74 | 76 |
75 TemplateURL* template_url = new TemplateURL(browser_->profile(), data); | 77 TemplateURL* template_url = new TemplateURL(browser_->profile(), data); |
76 service->Add(template_url); // Takes ownership of |template_url|. | 78 service->Add(template_url); // Takes ownership of |template_url|. |
77 service->SetDefaultSearchProvider(template_url); | 79 service->SetDefaultSearchProvider(template_url); |
78 } | 80 } |
79 | 81 |
80 void InstantTestBase::Init(const GURL& instant_url, bool init_suggestions_url) { | 82 void InstantTestBase::Init(const GURL& instant_url, bool init_suggestions_url) { |
81 instant_url_ = instant_url; | 83 instant_url_ = instant_url; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded); | 174 return content::ExecuteScriptAndExtractBool(rvh, js_chrome, loaded); |
173 } | 175 } |
174 | 176 |
175 string16 InstantTestBase::GetBlueText() { | 177 string16 InstantTestBase::GetBlueText() { |
176 size_t start = 0, end = 0; | 178 size_t start = 0, end = 0; |
177 omnibox()->GetSelectionBounds(&start, &end); | 179 omnibox()->GetSelectionBounds(&start, &end); |
178 if (start > end) | 180 if (start > end) |
179 std::swap(start, end); | 181 std::swap(start, end); |
180 return omnibox()->GetText().substr(start, end - start); | 182 return omnibox()->GetText().substr(start, end - start); |
181 } | 183 } |
OLD | NEW |