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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 6 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
7 #include "chrome/browser/search_engines/template_url_service_factory.h" | 7 #include "chrome/browser/search_engines/template_url_service_factory.h" |
8 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 8 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
9 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 9 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
10 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 10 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
11 #include "chrome/browser/ui/toolbar/test_toolbar_model.h" | 11 #include "chrome/browser/ui/toolbar/test_toolbar_model.h" |
12 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/test/test_browser_thread_bundle.h" | |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "ui/gfx/font.h" | 15 #include "ui/gfx/font.h" |
17 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
18 | 17 |
19 using content::WebContents; | 18 using content::WebContents; |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 class TestingOmniboxView : public OmniboxView { | 22 class TestingOmniboxView : public OmniboxView { |
24 public: | 23 public: |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 174 |
176 // Verifies a search term 'foo' doesn't end up with http. | 175 // Verifies a search term 'foo' doesn't end up with http. |
177 { "www.google.com/search?", 0, false, "foo", "foo", false, "", false }, | 176 { "www.google.com/search?", 0, false, "foo", "foo", false, "", false }, |
178 | 177 |
179 // Makes sure extracted search terms are not modified. | 178 // Makes sure extracted search terms are not modified. |
180 { "www.google.com/webhp?", 0, true, "hello world", "hello world", false, | 179 { "www.google.com/webhp?", 0, true, "hello world", "hello world", false, |
181 "", true }, | 180 "", true }, |
182 }; | 181 }; |
183 TestingOmniboxEditController controller(toolbar_model()); | 182 TestingOmniboxEditController controller(toolbar_model()); |
184 TestingOmniboxView view(&controller); | 183 TestingOmniboxView view(&controller); |
185 content::TestBrowserThreadBundle thread_bundle; | |
186 TestingProfile profile; | 184 TestingProfile profile; |
187 // NOTE: The TemplateURLService must be created before the | 185 // NOTE: The TemplateURLService must be created before the |
188 // AutocompleteClassifier so that the SearchProvider gets a non-NULL | 186 // AutocompleteClassifier so that the SearchProvider gets a non-NULL |
189 // TemplateURLService at construction time. | 187 // TemplateURLService at construction time. |
190 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 188 TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
191 &profile, &TemplateURLServiceFactory::BuildInstanceFor); | 189 &profile, &TemplateURLServiceFactory::BuildInstanceFor); |
192 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( | 190 AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( |
193 &profile, &AutocompleteClassifierFactory::BuildInstanceFor); | 191 &profile, &AutocompleteClassifierFactory::BuildInstanceFor); |
194 OmniboxEditModel model(&view, &controller, &profile); | 192 OmniboxEditModel model(&view, &controller, &profile); |
195 | 193 |
196 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input); ++i) { | 194 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input); ++i) { |
197 model.UpdatePermanentText(ASCIIToUTF16(input[i].perm_text)); | 195 model.UpdatePermanentText(ASCIIToUTF16(input[i].perm_text)); |
198 | 196 |
199 toolbar_model()->set_replace_search_url_with_search_terms( | 197 toolbar_model()->set_replace_search_url_with_search_terms( |
200 input[i].extracted_search_terms); | 198 input[i].extracted_search_terms); |
201 | 199 |
202 string16 result = ASCIIToUTF16(input[i].input); | 200 string16 result = ASCIIToUTF16(input[i].input); |
203 GURL url; | 201 GURL url; |
204 bool write_url; | 202 bool write_url; |
205 model.AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected, | 203 model.AdjustTextForCopy(input[i].sel_start, input[i].is_all_selected, |
206 &result, &url, &write_url); | 204 &result, &url, &write_url); |
207 EXPECT_EQ(ASCIIToUTF16(input[i].expected_output), result) << "@: " << i; | 205 EXPECT_EQ(ASCIIToUTF16(input[i].expected_output), result) << "@: " << i; |
208 EXPECT_EQ(input[i].write_url, write_url) << " @" << i; | 206 EXPECT_EQ(input[i].write_url, write_url) << " @" << i; |
209 if (write_url) | 207 if (write_url) |
210 EXPECT_EQ(input[i].expected_url, url.spec()) << " @" << i; | 208 EXPECT_EQ(input[i].expected_url, url.spec()) << " @" << i; |
211 } | 209 } |
212 } | 210 } |
OLD | NEW |