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