OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <math.h> | 5 #include <math.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 time_squared_ = 0; | 45 time_squared_ = 0; |
46 time_sum_ = 0; | 46 time_sum_ = 0; |
47 time_min_ = 0; | 47 time_min_ = 0; |
48 time_max_ = 0; | 48 time_max_ = 0; |
49 } | 49 } |
50 | 50 |
51 // Many times a user may enter something like "google.com". If | 51 // Many times a user may enter something like "google.com". If |
52 // http://www.google.com/ is suggested that should be considered a match. | 52 // http://www.google.com/ is suggested that should be considered a match. |
53 // This could probably be accomplished with regex as well. Note that this | 53 // This could probably be accomplished with regex as well. Note that this |
54 // method is called even when suggestion isn't a URL. | 54 // method is called even when suggestion isn't a URL. |
55 bool IsMatch(const string16& input_test, const string16& suggestion); | 55 bool IsMatch(const std::wstring& input_test, const std::wstring& suggestion); |
56 // Runs a query chain. This sends each proper prefix of the input to the | 56 // Runs a query chain. This sends each proper prefix of the input to the |
57 // omnibox and scores the autocompelte results returned. | 57 // omnibox and scores the autocompelte results returned. |
58 void RunQueryChain(const string16& input_text); | 58 void RunQueryChain(const std::wstring& input_text); |
59 }; | 59 }; |
60 | 60 |
61 bool OmniboxTest::IsMatch(const string16& input_text, | 61 bool OmniboxTest::IsMatch(const std::wstring& input_text, |
62 const string16& suggestion) { | 62 const std::wstring& suggestion) { |
63 // This prefix list comes from the list used in history_url_provider.cc | 63 // This prefix list comes from the list used in history_url_provider.cc |
64 // with the exception of "ftp." and "www.". | 64 // with the exception of "ftp." and "www.". |
65 string16 prefixes[] = {ASCIIToUTF16(""), ASCIIToUTF16("ftp://"), | 65 std::wstring prefixes[] = {L"", L"ftp://", L"http://", L"https://", |
66 ASCIIToUTF16("http://"), ASCIIToUTF16("https://"), ASCIIToUTF16("ftp."), | 66 L"ftp.", L"www.", L"ftp://www.", L"ftp://ftp.", |
67 ASCIIToUTF16("www."), ASCIIToUTF16("ftp://www."), | 67 L"http://www.", L"https://www."}; |
68 ASCIIToUTF16("ftp://ftp."), ASCIIToUTF16("http://www."), | 68 std::wstring postfixes[] = {L"", L"/"}; |
69 ASCIIToUTF16("https://www.")}; | |
70 string16 postfixes[] = {ASCIIToUTF16(""), ASCIIToUTF16("/")}; | |
71 for (size_t i = 0; i < arraysize(prefixes); ++i) { | 69 for (size_t i = 0; i < arraysize(prefixes); ++i) { |
72 for (size_t j = 0; j < arraysize(postfixes); ++j) { | 70 for (size_t j = 0; j < arraysize(postfixes); ++j) { |
73 if (prefixes[i] + input_text + postfixes[j] == suggestion) | 71 if (prefixes[i] + input_text + postfixes[j] == suggestion) |
74 return true; | 72 return true; |
75 } | 73 } |
76 } | 74 } |
77 return false; | 75 return false; |
78 } | 76 } |
79 | 77 |
80 void OmniboxTest::RunQueryChain(const string16& input_text) { | 78 void OmniboxTest::RunQueryChain(const std::wstring& input_text) { |
81 // Get a handle on the omnibox and give it focus. | 79 // Get a handle on the omnibox and give it focus. |
82 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 80 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
83 ASSERT_TRUE(browser.get()); | 81 ASSERT_TRUE(browser.get()); |
84 scoped_refptr<WindowProxy> window(browser->GetWindow()); | 82 scoped_refptr<WindowProxy> window(browser->GetWindow()); |
85 ASSERT_TRUE(window.get()); | 83 ASSERT_TRUE(window.get()); |
86 scoped_refptr<AutocompleteEditProxy> autocomplete_edit( | 84 scoped_refptr<AutocompleteEditProxy> autocomplete_edit( |
87 browser->GetAutocompleteEdit()); | 85 browser->GetAutocompleteEdit()); |
88 ASSERT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); | 86 ASSERT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); |
89 | 87 |
90 // Try every proper prefix of input_text. There's no use trying | 88 // Try every proper prefix of input_text. There's no use trying |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 std::vector<std::string> expected_providers; | 156 std::vector<std::string> expected_providers; |
159 ASSERT_TRUE(reader.NodeAttribute("query", &query)); | 157 ASSERT_TRUE(reader.NodeAttribute("query", &query)); |
160 reader.Read(); | 158 reader.Read(); |
161 while (reader.SkipToElement()) { | 159 while (reader.SkipToElement()) { |
162 ASSERT_EQ("provider", reader.NodeName()); | 160 ASSERT_EQ("provider", reader.NodeName()); |
163 std::string provider; | 161 std::string provider; |
164 ASSERT_TRUE(reader.NodeAttribute("provider", &provider)); | 162 ASSERT_TRUE(reader.NodeAttribute("provider", &provider)); |
165 expected_providers.push_back(provider); | 163 expected_providers.push_back(provider); |
166 reader.Read(); | 164 reader.Read(); |
167 } | 165 } |
168 RunQueryChain(ASCIIToUTF16(query)); | 166 RunQueryChain(ASCIIToWide(query)); |
169 reader.Read(); | 167 reader.Read(); |
170 } | 168 } |
171 reader.Read(); | 169 reader.Read(); |
172 } | 170 } |
173 | 171 |
174 // Output results. | 172 // Output results. |
175 ASSERT_GT(query_count_, 0); | 173 ASSERT_GT(query_count_, 0); |
176 int64 mean = time_sum_ / query_count_; | 174 int64 mean = time_sum_ / query_count_; |
177 wprintf(L"__om_query_count = %d\n", query_count_); | 175 wprintf(L"__om_query_count = %d\n", query_count_); |
178 wprintf(L"__om_query_timeouts = %d\n", query_timeouts_); | 176 wprintf(L"__om_query_timeouts = %d\n", query_timeouts_); |
179 wprintf(L"__om_time_per_query_avg = %d\n", mean); | 177 wprintf(L"__om_time_per_query_avg = %d\n", mean); |
180 // Use the equation stddev = sqrt(Sum(x_i^2)/N - mean^2). | 178 // Use the equation stddev = sqrt(Sum(x_i^2)/N - mean^2). |
181 wprintf(L"__om_time_per_query_stddev = %d\n", static_cast<int64>( | 179 wprintf(L"__om_time_per_query_stddev = %d\n", static_cast<int64>( |
182 sqrt(1.0 * time_squared_ / query_count_ - mean * mean))); | 180 sqrt(1.0 * time_squared_ / query_count_ - mean * mean))); |
183 wprintf(L"__om_time_per_query_max = %d\n", time_max_); | 181 wprintf(L"__om_time_per_query_max = %d\n", time_max_); |
184 wprintf(L"__om_time_per_query_min = %d\n", time_min_); | 182 wprintf(L"__om_time_per_query_min = %d\n", time_min_); |
185 wprintf(L"__om_score = %.4f\n", 100.0 * score_ / max_score_); | 183 wprintf(L"__om_score = %.4f\n", 100.0 * score_ / max_score_); |
186 } | 184 } |
OLD | NEW |