| 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 "chrome/browser/ui/toolbar/toolbar_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 12 #include "chrome/browser/search/instant_service.h" | 12 #include "chrome/browser/search/instant_service.h" |
| 13 #include "chrome/browser/search/instant_service_factory.h" | 13 #include "chrome/browser/search/instant_service_factory.h" |
| 14 #include "chrome/browser/search/search.h" | 14 #include "chrome/browser/search/search.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | 15 #include "chrome/browser/search_engines/template_url.h" |
| 16 #include "chrome/browser/search_engines/template_url_service.h" | 16 #include "chrome/browser/search_engines/template_url_service.h" |
| 17 #include "chrome/browser/search_engines/template_url_service_factory.h" | 17 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 19 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 20 #include "chrome/browser/ui/toolbar/toolbar_model.h" | 20 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/test/base/browser_with_test_window_test.h" | 22 #include "chrome/test/base/browser_with_test_window_test.h" |
| 23 #include "content/public/browser/navigation_entry.h" |
| 23 #include "content/public/browser/render_process_host.h" | 24 #include "content/public/browser/render_process_host.h" |
| 24 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/common/ssl_status.h" |
| 25 #include "content/public/common/url_constants.h" | 27 #include "content/public/common/url_constants.h" |
| 26 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 27 | 29 |
| 28 using content::OpenURLParams; | 30 using content::OpenURLParams; |
| 29 using content::Referrer; | 31 using content::Referrer; |
| 30 using content::WebContents; | 32 using content::WebContents; |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 struct TestItem { | 36 struct TestItem { |
| 35 GURL url; | 37 GURL url; |
| 36 string16 expected_text; | 38 string16 expected_text; |
| 37 // The expected text to display when query extraction is inactive. | 39 // The expected text to display when query extraction is inactive. |
| 38 string16 expected_replace_text_inactive; | 40 string16 expected_replace_text_inactive; |
| 39 // The expected text to display when query extraction is active. | 41 // The expected text to display when query extraction is active. |
| 40 string16 expected_replace_text_active; | 42 string16 expected_replace_text_active; |
| 41 bool would_replace; | 43 ToolbarModel::SearchTermsType search_terms_type; |
| 42 bool should_display; | 44 bool should_display; |
| 43 } test_items[] = { | 45 } test_items[] = { |
| 44 { | 46 { |
| 45 GURL("view-source:http://www.google.com"), | 47 GURL("view-source:http://www.google.com"), |
| 46 ASCIIToUTF16("view-source:www.google.com"), | 48 ASCIIToUTF16("view-source:www.google.com"), |
| 47 ASCIIToUTF16("view-source:www.google.com"), | 49 ASCIIToUTF16("view-source:www.google.com"), |
| 48 ASCIIToUTF16("view-source:www.google.com"), | 50 ASCIIToUTF16("view-source:www.google.com"), |
| 49 false, | 51 ToolbarModel::NO_SEARCH_TERMS, |
| 50 true | 52 true |
| 51 }, | 53 }, |
| 52 { | 54 { |
| 53 GURL("view-source:chrome://newtab/"), | 55 GURL("view-source:chrome://newtab/"), |
| 54 ASCIIToUTF16("view-source:chrome://newtab"), | 56 ASCIIToUTF16("view-source:chrome://newtab"), |
| 55 ASCIIToUTF16("view-source:chrome://newtab"), | 57 ASCIIToUTF16("view-source:chrome://newtab"), |
| 56 ASCIIToUTF16("view-source:chrome://newtab"), | 58 ASCIIToUTF16("view-source:chrome://newtab"), |
| 57 false, | 59 ToolbarModel::NO_SEARCH_TERMS, |
| 58 true | 60 true |
| 59 }, | 61 }, |
| 60 { | 62 { |
| 61 GURL("chrome-extension://monkey/balls.html"), | 63 GURL("chrome-extension://monkey/balls.html"), |
| 62 ASCIIToUTF16("chrome-extension://monkey/balls.html"), | 64 ASCIIToUTF16("chrome-extension://monkey/balls.html"), |
| 63 ASCIIToUTF16("chrome-extension://monkey/balls.html"), | 65 ASCIIToUTF16("chrome-extension://monkey/balls.html"), |
| 64 ASCIIToUTF16("chrome-extension://monkey/balls.html"), | 66 ASCIIToUTF16("chrome-extension://monkey/balls.html"), |
| 65 false, | 67 ToolbarModel::NO_SEARCH_TERMS, |
| 66 true | 68 true |
| 67 }, | 69 }, |
| 68 { | 70 { |
| 69 GURL("chrome://newtab/"), | 71 GURL("chrome://newtab/"), |
| 70 string16(), | 72 string16(), |
| 71 string16(), | 73 string16(), |
| 72 string16(), | 74 string16(), |
| 73 false, | 75 ToolbarModel::NO_SEARCH_TERMS, |
| 74 false | 76 false |
| 75 }, | 77 }, |
| 76 { | 78 { |
| 77 GURL(chrome::kAboutBlankURL), | 79 GURL(chrome::kAboutBlankURL), |
| 78 ASCIIToUTF16(chrome::kAboutBlankURL), | 80 ASCIIToUTF16(chrome::kAboutBlankURL), |
| 79 ASCIIToUTF16(chrome::kAboutBlankURL), | 81 ASCIIToUTF16(chrome::kAboutBlankURL), |
| 80 ASCIIToUTF16(chrome::kAboutBlankURL), | 82 ASCIIToUTF16(chrome::kAboutBlankURL), |
| 81 false, | 83 ToolbarModel::NO_SEARCH_TERMS, |
| 82 true | 84 true |
| 83 }, | 85 }, |
| 84 { | 86 { |
| 85 GURL("http://searchurl/?q=tractor+supply"), | 87 GURL("http://searchurl/?q=tractor+supply"), |
| 86 ASCIIToUTF16("searchurl/?q=tractor+supply"), | 88 ASCIIToUTF16("searchurl/?q=tractor+supply"), |
| 87 ASCIIToUTF16("searchurl/?q=tractor+supply"), | 89 ASCIIToUTF16("searchurl/?q=tractor+supply"), |
| 88 ASCIIToUTF16("searchurl/?q=tractor+supply"), | 90 ASCIIToUTF16("searchurl/?q=tractor+supply"), |
| 89 false, | 91 ToolbarModel::NO_SEARCH_TERMS, |
| 90 true | 92 true |
| 91 }, | 93 }, |
| 92 { | 94 { |
| 93 GURL("https://google.ca/search?q=tractor+supply"), | 95 GURL("https://google.ca/search?q=tractor+supply"), |
| 94 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), | 96 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), |
| 95 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), | 97 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), |
| 96 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), | 98 ASCIIToUTF16("https://google.ca/search?q=tractor+supply"), |
| 97 false, | 99 ToolbarModel::NO_SEARCH_TERMS, |
| 98 true | 100 true |
| 99 }, | 101 }, |
| 100 { | 102 { |
| 101 GURL("https://google.com/search?q=tractor+supply"), | 103 GURL("https://google.com/search?q=tractor+supply"), |
| 102 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), | 104 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), |
| 103 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), | 105 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), |
| 104 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), | 106 ASCIIToUTF16("https://google.com/search?q=tractor+supply"), |
| 105 false, | 107 ToolbarModel::NO_SEARCH_TERMS, |
| 106 true | 108 true |
| 107 }, | 109 }, |
| 108 { | 110 { |
| 109 GURL("https://google.com/search?q=tractor+supply&espv=1"), | 111 GURL("https://google.com/search?q=tractor+supply&espv=1"), |
| 110 ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), | 112 ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), |
| 111 ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), | 113 ASCIIToUTF16("https://google.com/search?q=tractor+supply&espv=1"), |
| 112 ASCIIToUTF16("tractor supply"), | 114 ASCIIToUTF16("tractor supply"), |
| 113 true, | 115 ToolbarModel::NORMAL_SEARCH_TERMS, |
| 114 true | 116 true |
| 115 }, | 117 }, |
| 116 { | 118 { |
| 117 GURL("https://google.com/search?q=tractorsupply.com&espv=1"), | 119 GURL("https://google.com/search?q=tractorsupply.com&espv=1"), |
| 118 ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), | 120 ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), |
| 119 ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), | 121 ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), |
| 120 ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), | 122 ASCIIToUTF16("https://google.com/search?q=tractorsupply.com&espv=1"), |
| 121 false, | 123 ToolbarModel::NO_SEARCH_TERMS, |
| 122 true | 124 true |
| 123 }, | 125 }, |
| 124 { | 126 { |
| 125 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 127 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 126 ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 128 ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 127 ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 129 ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 128 ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), | 130 ASCIIToUTF16("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), |
| 129 false, | 131 ToolbarModel::NO_SEARCH_TERMS, |
| 130 true | 132 true |
| 131 }, | 133 }, |
| 132 }; | 134 }; |
| 133 | 135 |
| 134 } // end namespace | 136 } // end namespace |
| 135 | 137 |
| 136 class ToolbarModelTest : public BrowserWithTestWindowTest { | 138 class ToolbarModelTest : public BrowserWithTestWindowTest { |
| 137 public: | 139 public: |
| 138 ToolbarModelTest() {} | 140 ToolbarModelTest() {} |
| 139 | 141 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 158 TemplateURLServiceFactory::GetForProfile(profile()); | 160 TemplateURLServiceFactory::GetForProfile(profile()); |
| 159 template_url_service->Add(search_template_url); | 161 template_url_service->Add(search_template_url); |
| 160 template_url_service->SetDefaultSearchProvider(search_template_url); | 162 template_url_service->SetDefaultSearchProvider(search_template_url); |
| 161 ASSERT_NE(0, search_template_url->id()); | 163 ASSERT_NE(0, search_template_url->id()); |
| 162 template_url_service->Load(); | 164 template_url_service->Load(); |
| 163 } | 165 } |
| 164 | 166 |
| 165 void NavigateAndCheckText(const GURL& url, | 167 void NavigateAndCheckText(const GURL& url, |
| 166 const string16& expected_text, | 168 const string16& expected_text, |
| 167 const string16& expected_replace_text, | 169 const string16& expected_replace_text, |
| 168 bool would_replace, | 170 ToolbarModel::SearchTermsType search_terms_type, |
| 169 bool should_display) { | 171 bool should_display) { |
| 170 NavigateAndCheckTextImpl(url, false, expected_text, would_replace, | 172 NavigateAndCheckTextImpl(url, false, expected_text, search_terms_type, |
| 171 should_display); | 173 should_display); |
| 172 NavigateAndCheckTextImpl(url, true, expected_replace_text, would_replace, | 174 NavigateAndCheckTextImpl(url, true, expected_replace_text, |
| 173 should_display); | 175 search_terms_type, should_display); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void NavigateAndCheckQueries(const std::vector<const char*>& queries, | 178 void NavigateAndCheckQueries( |
| 177 bool would_replace) { | 179 const std::vector<const char*>& queries, |
| 180 ToolbarModel::SearchTermsType search_terms_type) { |
| 178 const std::string kInstantExtendedPrefix( | 181 const std::string kInstantExtendedPrefix( |
| 179 "https://google.com/search?espv=1&q="); | 182 "https://google.com/search?espv=1&q="); |
| 180 | 183 |
| 181 chrome::EnableInstantExtendedAPIForTesting(); | 184 chrome::EnableInstantExtendedAPIForTesting(); |
| 182 | 185 |
| 183 ResetDefaultTemplateURL(); | 186 ResetDefaultTemplateURL(); |
| 184 AddTab(browser(), GURL(chrome::kAboutBlankURL)); | 187 AddTab(browser(), GURL(chrome::kAboutBlankURL)); |
| 185 for (size_t i = 0; i < queries.size(); ++i) { | 188 for (size_t i = 0; i < queries.size(); ++i) { |
| 186 std::string url_string = kInstantExtendedPrefix + | 189 std::string url_string = kInstantExtendedPrefix + |
| 187 net::EscapeQueryParamValue(queries[i], true); | 190 net::EscapeQueryParamValue(queries[i], true); |
| 191 std::string expected_text; |
| 192 if (search_terms_type == ToolbarModel::NO_SEARCH_TERMS) |
| 193 expected_text = url_string; |
| 194 else |
| 195 expected_text = std::string(queries[i]); |
| 188 NavigateAndCheckTextImpl(GURL(url_string), true, | 196 NavigateAndCheckTextImpl(GURL(url_string), true, |
| 189 ASCIIToUTF16(would_replace ? | 197 ASCIIToUTF16(expected_text), |
| 190 std::string(queries[i]) : | 198 search_terms_type, true); |
| 191 url_string), | |
| 192 would_replace, true); | |
| 193 } | 199 } |
| 194 } | 200 } |
| 195 | 201 |
| 196 private: | 202 private: |
| 197 void NavigateAndCheckTextImpl(const GURL& url, | 203 void NavigateAndCheckTextImpl(const GURL& url, |
| 198 bool can_replace, | 204 bool can_replace, |
| 199 const string16 expected_text, | 205 const string16 expected_text, |
| 200 bool would_replace, | 206 ToolbarModel::SearchTermsType search_terms_type, |
| 201 bool should_display) { | 207 bool should_display) { |
| 202 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); | 208 WebContents* contents = browser()->tab_strip_model()->GetWebContentsAt(0); |
| 203 browser()->OpenURL(OpenURLParams( | 209 browser()->OpenURL(OpenURLParams( |
| 204 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, | 210 url, Referrer(), CURRENT_TAB, content::PAGE_TRANSITION_TYPED, |
| 205 false)); | 211 false)); |
| 206 | 212 |
| 207 // Query terms replacement requires that the renderer process be a | 213 // Query terms replacement requires that the renderer process be a |
| 208 // recognized Instant renderer. Fake it. | 214 // recognized Instant renderer. Fake it. |
| 209 InstantService* instant_service = | 215 InstantService* instant_service = |
| 210 InstantServiceFactory::GetForProfile(profile()); | 216 InstantServiceFactory::GetForProfile(profile()); |
| 211 int process_id = contents->GetRenderProcessHost()->GetID(); | 217 int process_id = contents->GetRenderProcessHost()->GetID(); |
| 212 instant_service->AddInstantProcess(process_id); | 218 instant_service->AddInstantProcess(process_id); |
| 213 | 219 |
| 214 ToolbarModel* toolbar_model = browser()->toolbar_model(); | 220 ToolbarModel* toolbar_model = browser()->toolbar_model(); |
| 215 | 221 |
| 216 // Check while loading. | 222 // Check while loading. |
| 223 contents->GetController().GetVisibleEntry()->GetSSL().security_style = |
| 224 content::SECURITY_STYLE_AUTHENTICATED; |
| 217 EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL()); | 225 EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL()); |
| 218 EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace)); | 226 EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace)); |
| 219 EXPECT_EQ(would_replace, | 227 EXPECT_EQ(search_terms_type, toolbar_model->GetSearchTermsType()); |
| 220 toolbar_model->WouldReplaceSearchURLWithSearchTerms()); | |
| 221 | 228 |
| 222 // Check after commit. | 229 // Check after commit. |
| 223 CommitPendingLoad(&contents->GetController()); | 230 CommitPendingLoad(&contents->GetController()); |
| 231 contents->GetController().GetVisibleEntry()->GetSSL().security_style = |
| 232 content::SECURITY_STYLE_AUTHENTICATED; |
| 224 EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL()); | 233 EXPECT_EQ(should_display, toolbar_model->ShouldDisplayURL()); |
| 225 EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace)); | 234 EXPECT_EQ(expected_text, toolbar_model->GetText(can_replace)); |
| 226 EXPECT_EQ(would_replace, | 235 EXPECT_EQ(search_terms_type, toolbar_model->GetSearchTermsType()); |
| 227 toolbar_model->WouldReplaceSearchURLWithSearchTerms()); | |
| 228 } | 236 } |
| 229 }; | 237 }; |
| 230 | 238 |
| 231 // Test that we don't replace any URLs when the query extraction is disabled. | 239 // Test that we don't replace any URLs when the query extraction is disabled. |
| 232 TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionDisabled) { | 240 TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionDisabled) { |
| 233 ASSERT_FALSE(chrome::IsQueryExtractionEnabled()) | 241 ASSERT_FALSE(chrome::IsQueryExtractionEnabled()) |
| 234 << "This test expects query extraction to be disabled."; | 242 << "This test expects query extraction to be disabled."; |
| 235 | 243 |
| 236 ResetDefaultTemplateURL(); | 244 ResetDefaultTemplateURL(); |
| 237 AddTab(browser(), GURL(chrome::kAboutBlankURL)); | 245 AddTab(browser(), GURL(chrome::kAboutBlankURL)); |
| 238 for (size_t i = 0; i < arraysize(test_items); ++i) { | 246 for (size_t i = 0; i < arraysize(test_items); ++i) { |
| 239 const TestItem& test_item = test_items[i]; | 247 const TestItem& test_item = test_items[i]; |
| 240 NavigateAndCheckText(test_item.url, | 248 NavigateAndCheckText(test_item.url, |
| 241 test_item.expected_text, | 249 test_item.expected_text, |
| 242 test_item.expected_replace_text_inactive, | 250 test_item.expected_replace_text_inactive, |
| 243 false, | 251 ToolbarModel::NO_SEARCH_TERMS, |
| 244 test_item.should_display); | 252 test_item.should_display); |
| 245 } | 253 } |
| 246 } | 254 } |
| 247 | 255 |
| 248 // Test that we replace URLs when the query extraction API is enabled. | 256 // Test that we replace URLs when the query extraction API is enabled. |
| 249 TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionEnabled) { | 257 TEST_F(ToolbarModelTest, ShouldDisplayURLQueryExtractionEnabled) { |
| 250 chrome::EnableInstantExtendedAPIForTesting(); | 258 chrome::EnableInstantExtendedAPIForTesting(); |
| 251 | 259 |
| 252 ResetDefaultTemplateURL(); | 260 ResetDefaultTemplateURL(); |
| 253 AddTab(browser(), GURL(chrome::kAboutBlankURL)); | 261 AddTab(browser(), GURL(chrome::kAboutBlankURL)); |
| 254 for (size_t i = 0; i < arraysize(test_items); ++i) { | 262 for (size_t i = 0; i < arraysize(test_items); ++i) { |
| 255 const TestItem& test_item = test_items[i]; | 263 const TestItem& test_item = test_items[i]; |
| 256 NavigateAndCheckText(test_item.url, | 264 NavigateAndCheckText(test_item.url, |
| 257 test_item.expected_text, | 265 test_item.expected_text, |
| 258 test_item.expected_replace_text_active, | 266 test_item.expected_replace_text_active, |
| 259 test_item.would_replace, | 267 test_item.search_terms_type, |
| 260 test_item.should_display); | 268 test_item.should_display); |
| 261 } | 269 } |
| 262 } | 270 } |
| 263 | 271 |
| 264 // Test that replacement doesn't happen for URLs. | 272 // Test that replacement doesn't happen for URLs. |
| 265 TEST_F(ToolbarModelTest, DoNotExtractUrls) { | 273 TEST_F(ToolbarModelTest, DoNotExtractUrls) { |
| 266 static const char* const kQueries[] = { | 274 static const char* const kQueries[] = { |
| 267 "www.google.com ", | 275 "www.google.com ", |
| 268 "www.google.ca", // Oh, Canada! | 276 "www.google.ca", // Oh, Canada! |
| 269 "www.google.ca.", | 277 "www.google.ca.", |
| 270 "www.google.ca ", | 278 "www.google.ca ", |
| 271 "www.google.ca. ", | 279 "www.google.ca. ", |
| 272 "something.xxx", | 280 "something.xxx", |
| 273 "something.travel", | 281 "something.travel", |
| 274 "bankofamerica.com/", | 282 "bankofamerica.com/", |
| 275 "bankofamerica.com/foo", | 283 "bankofamerica.com/foo", |
| 276 "bankofamerica.com/foo bla", | 284 "bankofamerica.com/foo bla", |
| 277 "BankOfAmerica.BIZ/foo bla", | 285 "BankOfAmerica.BIZ/foo bla", |
| 278 " http:/monkeys", | 286 " http:/monkeys", |
| 279 "http://monkeys", | 287 "http://monkeys", |
| 280 "javascript:alert(1)", | 288 "javascript:alert(1)", |
| 281 "JavaScript:alert(1)", | 289 "JavaScript:alert(1)", |
| 282 "localhost", | 290 "localhost", |
| 283 }; | 291 }; |
| 284 | 292 |
| 285 NavigateAndCheckQueries( | 293 NavigateAndCheckQueries( |
| 286 std::vector<const char*>(&kQueries[0], | 294 std::vector<const char*>(&kQueries[0], &kQueries[arraysize(kQueries)]), |
| 287 &kQueries[arraysize(kQueries)]), false); | 295 ToolbarModel::NO_SEARCH_TERMS); |
| 288 } | 296 } |
| 289 | 297 |
| 290 // Test that replacement does happen for non-URLs. | 298 // Test that replacement does happen for non-URLs. |
| 291 TEST_F(ToolbarModelTest, ExtractNonUrls) { | 299 TEST_F(ToolbarModelTest, ExtractNonUrls) { |
| 292 static const char* const kQueries[] = { | 300 static const char* const kQueries[] = { |
| 293 "facebook.com login", | 301 "facebook.com login", |
| 294 "site:amazon.com", | 302 "site:amazon.com", |
| 295 "e.coli", | 303 "e.coli", |
| 296 "info:http://www.google.com/", | 304 "info:http://www.google.com/", |
| 297 "cache:http://www.apple.com/", | 305 "cache:http://www.apple.com/", |
| 298 "9/11", | 306 "9/11", |
| 299 "<nomatch/>", | 307 "<nomatch/>", |
| 300 "ac/dc", | 308 "ac/dc", |
| 301 "ps/2", | 309 "ps/2", |
| 302 }; | 310 }; |
| 303 | 311 |
| 304 NavigateAndCheckQueries( | 312 NavigateAndCheckQueries( |
| 305 std::vector<const char*>(&kQueries[0], | 313 std::vector<const char*>(&kQueries[0], &kQueries[arraysize(kQueries)]), |
| 306 &kQueries[arraysize(kQueries)]), true); | 314 ToolbarModel::NORMAL_SEARCH_TERMS); |
| 307 } | 315 } |
| 316 |
| 317 // Verify that URL search terms are correctly identified. |
| 318 TEST_F(ToolbarModelTest, ProminentSearchTerm) { |
| 319 static const char* const kQueries[] = { |
| 320 "example.com" |
| 321 }; |
| 322 browser()->toolbar_model()->SetSupportsExtractionOfURLLikeSearchTerms(true); |
| 323 NavigateAndCheckQueries( |
| 324 std::vector<const char*>(&kQueries[0], &kQueries[arraysize(kQueries)]), |
| 325 ToolbarModel::URL_LIKE_SEARCH_TERMS); |
| 326 } |
| OLD | NEW |