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 "components/metrics/proto/omnibox_event.pb.h" |
14 #include "content/public/test/test_browser_thread.h" | 15 #include "content/public/test/test_browser_thread.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using base::ASCIIToUTF16; | 18 using base::ASCIIToUTF16; |
18 | 19 |
19 class ExtensionAppProviderTest : public testing::Test { | 20 class ExtensionAppProviderTest : public testing::Test { |
20 protected: | 21 protected: |
21 struct test_data { | 22 struct test_data { |
22 const base::string16 input; | 23 const base::string16 input; |
23 const size_t num_results; | 24 const size_t num_results; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 void ExtensionAppProviderTest::RunTest( | 87 void ExtensionAppProviderTest::RunTest( |
87 test_data* keyword_cases, | 88 test_data* keyword_cases, |
88 int num_cases) { | 89 int num_cases) { |
89 ACMatches matches; | 90 ACMatches matches; |
90 for (int i = 0; i < num_cases; ++i) { | 91 for (int i = 0; i < num_cases; ++i) { |
91 AutocompleteInput input(keyword_cases[i].input, base::string16::npos, | 92 AutocompleteInput input(keyword_cases[i].input, base::string16::npos, |
92 base::string16(), GURL(), | 93 base::string16(), GURL(), |
93 AutocompleteInput::INVALID_SPEC, true, | 94 metrics::OmniboxEventProto::INVALID_SPEC, true, |
94 false, true, true); | 95 false, true, true); |
95 app_provider_->Start(input, false); | 96 app_provider_->Start(input, false); |
96 EXPECT_TRUE(app_provider_->done()); | 97 EXPECT_TRUE(app_provider_->done()); |
97 matches = app_provider_->matches(); | 98 matches = app_provider_->matches(); |
98 EXPECT_EQ(keyword_cases[i].num_results, matches.size()) | 99 EXPECT_EQ(keyword_cases[i].num_results, matches.size()) |
99 << ASCIIToUTF16("Input was: ") + keyword_cases[i].input; | 100 << ASCIIToUTF16("Input was: ") + keyword_cases[i].input; |
100 if (matches.size() == keyword_cases[i].num_results) { | 101 if (matches.size() == keyword_cases[i].num_results) { |
101 for (size_t j = 0; j < keyword_cases[i].num_results; ++j) | 102 for (size_t j = 0; j < keyword_cases[i].num_results; ++j) |
102 EXPECT_EQ(keyword_cases[i].output[j], matches[j].destination_url); | 103 EXPECT_EQ(keyword_cases[i].output[j], matches[j].destination_url); |
103 } | 104 } |
(...skipping 30 matching lines...) Expand all Loading... |
134 const char* name; | 135 const char* name; |
135 const char* match_contents; | 136 const char* match_contents; |
136 } cases[] = { | 137 } cases[] = { |
137 { "Test", "Test" }, | 138 { "Test", "Test" }, |
138 { "Test \n Test", "Test Test" }, | 139 { "Test \n Test", "Test Test" }, |
139 { "Test\r\t\nTest", "TestTest" }, | 140 { "Test\r\t\nTest", "TestTest" }, |
140 }; | 141 }; |
141 | 142 |
142 AutocompleteInput input(ASCIIToUTF16("Test"), base::string16::npos, | 143 AutocompleteInput input(ASCIIToUTF16("Test"), base::string16::npos, |
143 base::string16(), GURL(), | 144 base::string16(), GURL(), |
144 AutocompleteInput::INVALID_SPEC, true, true, | 145 metrics::OmniboxEventProto::INVALID_SPEC, true, true, |
145 true, false); | 146 true, false); |
146 base::string16 url(ASCIIToUTF16("http://example.com")); | 147 base::string16 url(ASCIIToUTF16("http://example.com")); |
147 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 148 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
148 ExtensionAppProvider::ExtensionApp extension_app = | 149 ExtensionAppProvider::ExtensionApp extension_app = |
149 {ASCIIToUTF16(cases[i].name), url, true}; | 150 {ASCIIToUTF16(cases[i].name), url, true}; |
150 AutocompleteMatch match = | 151 AutocompleteMatch match = |
151 app_provider_->CreateAutocompleteMatch(input, | 152 app_provider_->CreateAutocompleteMatch(input, |
152 extension_app, | 153 extension_app, |
153 0, | 154 0, |
154 base::string16::npos); | 155 base::string16::npos); |
155 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents), match.contents); | 156 EXPECT_EQ(ASCIIToUTF16(cases[i].match_contents), match.contents); |
156 } | 157 } |
157 } | 158 } |
OLD | NEW |