| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/message_loop.h" | 5 #include "base/message_loop.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "chrome/browser/autocomplete/autocomplete.h" | 7 #include "chrome/browser/autocomplete/autocomplete.h" |
| 8 #include "chrome/common/notification_registrar.h" | 8 #include "chrome/common/notification_registrar.h" |
| 9 #include "chrome/common/notification_service.h" | 9 #include "chrome/common/notification_service.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 AutocompleteMatch m2(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); | 271 AutocompleteMatch m2(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); |
| 272 | 272 |
| 273 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 273 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 274 m1.relevance = cases[i].r1; | 274 m1.relevance = cases[i].r1; |
| 275 m2.relevance = cases[i].r2; | 275 m2.relevance = cases[i].r2; |
| 276 EXPECT_EQ(cases[i].expected_result, | 276 EXPECT_EQ(cases[i].expected_result, |
| 277 AutocompleteMatch::MoreRelevant(m1, m2)); | 277 AutocompleteMatch::MoreRelevant(m1, m2)); |
| 278 } | 278 } |
| 279 } | 279 } |
| 280 | 280 |
| 281 TEST(AutocompleteInput, ParseForEmphasizeComponent) { |
| 282 using url_parse::Component; |
| 283 Component kInvalidComponent(0, -1); |
| 284 struct test_data { |
| 285 const wchar_t* input; |
| 286 const Component scheme; |
| 287 const Component host; |
| 288 } input_cases[] = { |
| 289 { L"", kInvalidComponent, kInvalidComponent }, |
| 290 { L"?", kInvalidComponent, kInvalidComponent }, |
| 291 { L"?http://foo.com/bar", kInvalidComponent, kInvalidComponent }, |
| 292 { L"foo/bar baz", kInvalidComponent, Component(0, 3) }, |
| 293 { L"http://foo/bar baz", Component(0, 4), Component(7, 3) }, |
| 294 { L"link:foo.com", Component(0, 4), kInvalidComponent }, |
| 295 { L"www.foo.com:81", kInvalidComponent, Component(0, 11) }, |
| 296 { L"\u6d4b\u8bd5", kInvalidComponent, Component(0, 2) }, |
| 297 { L"view-source:http://www.foo.com/", Component(12, 4), Component(19, 11) }, |
| 298 { L"view-source:https://example.com/", |
| 299 Component(12, 5), Component(20, 11) }, |
| 300 { L"view-source:", Component(0, 11), kInvalidComponent }, |
| 301 { L"view-source:garbage", kInvalidComponent, Component(12, 7) }, |
| 302 { L"view-source:http://http://foo", Component(12, 4), Component(19, 4) }, |
| 303 { L"view-source:view-source:http://example.com/", |
| 304 Component(12, 11), kInvalidComponent } |
| 305 }; |
| 306 |
| 307 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { |
| 308 Component scheme, host; |
| 309 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, |
| 310 std::wstring(), |
| 311 &scheme, |
| 312 &host); |
| 313 AutocompleteInput input(input_cases[i].input, std::wstring(), true, false, |
| 314 false); |
| 315 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin) << "Input: " << |
| 316 input_cases[i].input; |
| 317 EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " << |
| 318 input_cases[i].input; |
| 319 EXPECT_EQ(input_cases[i].host.begin, host.begin) << "Input: " << |
| 320 input_cases[i].input; |
| 321 EXPECT_EQ(input_cases[i].host.len, host.len) << "Input: " << |
| 322 input_cases[i].input; |
| 323 } |
| 324 } |
| 325 |
| 281 } // namespace | 326 } // namespace |
| OLD | NEW |