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