| 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_match.h" | 8 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 9 #include "chrome/browser/autocomplete/extension_app_provider.h" | 9 #include "chrome/browser/autocomplete/extension_app_provider.h" |
| 10 #include "chrome/browser/history/history_service.h" | 10 #include "chrome/browser/history/history_service.h" |
| 11 #include "chrome/browser/history/history_service_factory.h" | 11 #include "chrome/browser/history/history_service_factory.h" |
| 12 #include "chrome/browser/history/url_database.h" | 12 #include "chrome/browser/history/url_database.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.h" | 14 #include "content/public/test/test_browser_thread.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 class ExtensionAppProviderTest : public testing::Test { | 17 class ExtensionAppProviderTest : public testing::Test { |
| 18 protected: | 18 protected: |
| 19 struct test_data { | 19 struct test_data { |
| 20 const string16 input; | 20 const base::string16 input; |
| 21 const size_t num_results; | 21 const size_t num_results; |
| 22 const GURL output[3]; | 22 const GURL output[3]; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 ExtensionAppProviderTest() | 25 ExtensionAppProviderTest() |
| 26 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 26 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 27 history_service_(NULL) { } | 27 history_service_(NULL) { } |
| 28 virtual ~ExtensionAppProviderTest() { } | 28 virtual ~ExtensionAppProviderTest() { } |
| 29 | 29 |
| 30 virtual void SetUp() OVERRIDE; | 30 virtual void SetUp() OVERRIDE; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 info.set_typed_count(kExtensionApps[i].typed_count); | 79 info.set_typed_count(kExtensionApps[i].typed_count); |
| 80 url_db->AddURL(info); | 80 url_db->AddURL(info); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 void ExtensionAppProviderTest::RunTest( | 84 void ExtensionAppProviderTest::RunTest( |
| 85 test_data* keyword_cases, | 85 test_data* keyword_cases, |
| 86 int num_cases) { | 86 int num_cases) { |
| 87 ACMatches matches; | 87 ACMatches matches; |
| 88 for (int i = 0; i < num_cases; ++i) { | 88 for (int i = 0; i < num_cases; ++i) { |
| 89 AutocompleteInput input(keyword_cases[i].input, string16::npos, string16(), | 89 AutocompleteInput input(keyword_cases[i].input, base::string16::npos, |
| 90 GURL(), AutocompleteInput::INVALID_SPEC, true, | 90 base::string16(), GURL(), |
| 91 AutocompleteInput::INVALID_SPEC, true, |
| 91 false, true, AutocompleteInput::ALL_MATCHES); | 92 false, true, AutocompleteInput::ALL_MATCHES); |
| 92 app_provider_->Start(input, false); | 93 app_provider_->Start(input, false); |
| 93 EXPECT_TRUE(app_provider_->done()); | 94 EXPECT_TRUE(app_provider_->done()); |
| 94 matches = app_provider_->matches(); | 95 matches = app_provider_->matches(); |
| 95 EXPECT_EQ(keyword_cases[i].num_results, matches.size()) | 96 EXPECT_EQ(keyword_cases[i].num_results, matches.size()) |
| 96 << ASCIIToUTF16("Input was: ") + keyword_cases[i].input; | 97 << ASCIIToUTF16("Input was: ") + keyword_cases[i].input; |
| 97 if (matches.size() == keyword_cases[i].num_results) { | 98 if (matches.size() == keyword_cases[i].num_results) { |
| 98 for (size_t j = 0; j < keyword_cases[i].num_results; ++j) | 99 for (size_t j = 0; j < keyword_cases[i].num_results; ++j) |
| 99 EXPECT_EQ(keyword_cases[i].output[j], matches[j].destination_url); | 100 EXPECT_EQ(keyword_cases[i].output[j], matches[j].destination_url); |
| 100 } | 101 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 129 TEST_F(ExtensionAppProviderTest, CreateMatchSanitize) { | 130 TEST_F(ExtensionAppProviderTest, CreateMatchSanitize) { |
| 130 struct TestData { | 131 struct TestData { |
| 131 const char* name; | 132 const char* name; |
| 132 const char* match_contents; | 133 const char* match_contents; |
| 133 } cases[] = { | 134 } cases[] = { |
| 134 { "Test", "Test" }, | 135 { "Test", "Test" }, |
| 135 { "Test \n Test", "Test Test" }, | 136 { "Test \n Test", "Test Test" }, |
| 136 { "Test\r\t\nTest", "TestTest" }, | 137 { "Test\r\t\nTest", "TestTest" }, |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 AutocompleteInput input(ASCIIToUTF16("Test"), string16::npos, string16(), | 140 AutocompleteInput input(ASCIIToUTF16("Test"), base::string16::npos, |
| 140 GURL(), AutocompleteInput::INVALID_SPEC, true, true, | 141 base::string16(), GURL(), |
| 142 AutocompleteInput::INVALID_SPEC, true, true, |
| 141 true, AutocompleteInput::BEST_MATCH); | 143 true, AutocompleteInput::BEST_MATCH); |
| 142 string16 url(ASCIIToUTF16("http://example.com")); | 144 base::string16 url(ASCIIToUTF16("http://example.com")); |
| 143 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 145 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 144 ExtensionAppProvider::ExtensionApp extension_app = | 146 ExtensionAppProvider::ExtensionApp extension_app = |
| 145 {ASCIIToUTF16(cases[i].name), url, true}; | 147 {ASCIIToUTF16(cases[i].name), url, true}; |
| 146 AutocompleteMatch match = | 148 AutocompleteMatch match = |
| 147 app_provider_->CreateAutocompleteMatch(input, | 149 app_provider_->CreateAutocompleteMatch(input, |
| 148 extension_app, | 150 extension_app, |
| 149 0, | 151 0, |
| 150 string16::npos); | 152 base::string16::npos); |
| 151 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents), match.contents); | 153 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents), match.contents); |
| 152 } | 154 } |
| 153 } | 155 } |
| OLD | NEW |