summaryrefslogtreecommitdiffstats
path: root/chrome/test/ui/omnibox_uitest.cc
diff options
context:
space:
mode:
authorinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 23:55:29 +0000
committerinitial.commit <initial.commit@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-26 23:55:29 +0000
commit09911bf300f1a419907a9412154760efd0b7abc3 (patch)
treef131325fb4e2ad12c6d3504ab75b16dd92facfed /chrome/test/ui/omnibox_uitest.cc
parent586acc5fe142f498261f52c66862fa417c3d52d2 (diff)
downloadchromium_src-09911bf300f1a419907a9412154760efd0b7abc3.zip
chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.gz
chromium_src-09911bf300f1a419907a9412154760efd0b7abc3.tar.bz2
Add chrome to the repository.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/ui/omnibox_uitest.cc')
-rw-r--r--chrome/test/ui/omnibox_uitest.cc203
1 files changed, 203 insertions, 0 deletions
diff --git a/chrome/test/ui/omnibox_uitest.cc b/chrome/test/ui/omnibox_uitest.cc
new file mode 100644
index 0000000..933810e
--- /dev/null
+++ b/chrome/test/ui/omnibox_uitest.cc
@@ -0,0 +1,203 @@
+// Copyright 2008, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <stdio.h>
+
+#include "base/command_line.h"
+#include "base/file_util.h"
+#include "base/path_service.h"
+#include "base/perftimer.h"
+#include "base/string_util.h"
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/libxml_utils.h"
+#include "chrome/test/automation/autocomplete_edit_proxy.h"
+#include "chrome/test/automation/automation_proxy.h"
+#include "chrome/test/automation/browser_proxy.h"
+#include "chrome/test/automation/window_proxy.h"
+#include "chrome/test/ui/ui_test.h"
+
+const wchar_t kRunOmniboxTest[] = L"run_omnibox_test";
+
+class OmniboxTest : public UITest {
+ public:
+
+ double score_;
+ double max_score_;
+
+ int query_count_;
+ int query_timeouts_;
+ int64 time_squared_;
+ int64 time_sum_;
+ int64 time_min_;
+ int64 time_max_;
+
+ OmniboxTest() : UITest() {
+ show_window_ = true;
+ query_count_ = 0;
+ query_timeouts_ = 0;
+ score_ = 0;
+ max_score_ = 0;
+ time_squared_ = 0;
+ time_sum_ = 0;
+ time_min_ = 0;
+ time_max_ = 0;
+ }
+
+ // Many times a user may enter something like "google.com". If
+ // http://www.google.com/ is suggested that should be considered a match.
+ // This could probably be accomplished with regex as well. Note that this
+ // method is called even when suggestion isn't a URL.
+ bool IsMatch(const std::wstring& input_test, const std::wstring& suggestion);
+ // Runs a query chain. This sends each proper prefix of the input to the
+ // omnibox and scores the autocompelte results returned.
+ void RunQueryChain(const std::wstring& input_text);
+};
+
+bool OmniboxTest::IsMatch(const std::wstring& input_text,
+ const std::wstring& suggestion) {
+ // This prefix list comes from the list used in history_url_provider.cc withiff
+ // the exception of "ftp." and "www.".
+ std::wstring prefixes[] = {L"", L"ftp://", L"http://", L"https://",
+ L"ftp.", L"www.", L"ftp://www.", L"ftp://ftp.",
+ L"http://www.", L"https://www."};
+ std::wstring postfixes[] = {L"", L"/"};
+ for (int i = 0; i < sizeof(prefixes) / sizeof(std::wstring); ++i) {
+ for (int j = 0; j < sizeof(postfixes) / sizeof(std::wstring); ++j) {
+ if (prefixes[i] + input_text + postfixes[j] == suggestion)
+ return true;
+ }
+ }
+ return false;
+}
+
+void OmniboxTest::RunQueryChain(const std::wstring& input_text) {
+ // Get a handle on the omnibox and give it focus.
+ scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
+ scoped_ptr<WindowProxy> window(
+ automation()->GetWindowForBrowser(browser.get()));
+ scoped_ptr<AutocompleteEditProxy> autocomplete_edit(
+ automation()->GetAutocompleteEditForBrowser(browser.get()));
+ ASSERT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION));
+
+ // Try every proper prefix of input_text. There's no use trying
+ // input_text itself since the autocomplete results will always contain it.
+ for (size_t i = 1; i < input_text.size(); ++i) {
+ Matches matches;
+
+ // We're only going to count the time elapsed waiting for autocomplete
+ // matches to be returned to us.
+ ASSERT_TRUE(autocomplete_edit->SetText(input_text.substr(0, i)));
+ PerfTimer timer;
+ if (autocomplete_edit->WaitForQuery(30000)) {
+ ASSERT_TRUE(autocomplete_edit->GetAutocompleteMatches(&matches));
+ int64 time_elapsed = timer.Elapsed().InMilliseconds();
+
+ // Adjust statistic trackers.
+ if (query_count_ == 0)
+ time_min_ = time_max_ = time_elapsed;
+ ++query_count_;
+ time_squared_ += time_elapsed * time_elapsed;
+ time_sum_ += time_elapsed;
+ if (time_elapsed < time_min_)
+ time_min_ = time_elapsed;
+ if (time_elapsed > time_max_)
+ time_max_ = time_elapsed;
+ } else {
+ ++query_timeouts_;
+ }
+ wprintf(L"query: %d\n", query_count_);
+
+ // Check if any suggestions match the input text. Stop if a match is
+ // found.
+ for (Matches::const_iterator j(matches.begin()); j != matches.end(); ++j) {
+ if (IsMatch(input_text, j->fill_into_edit)) {
+ score_ += i;
+ break;
+ }
+ }
+ max_score_ += i;
+ }
+}
+
+// This test reads in the omnibox_tests.xml file and performs the tests
+// within. The current format of xml is fairly simple. Nothing is currently
+// done with the provider information.
+// <omnibox_tests>
+// Zero or more test elements.
+// <test query='%query%'>
+// Zero or more provider elements.
+// <provider name='%expected_provider_name%'/>
+// </test>
+// </omnibox_tests>
+
+TEST_F(OmniboxTest, Measure) {
+ if (!CommandLine().HasSwitch(kRunOmniboxTest)) return;
+
+ std::wstring omnibox_tests_path;
+ PathService::Get(chrome::DIR_TEST_DATA, &omnibox_tests_path);
+ file_util::AppendToPath(&omnibox_tests_path, L"omnibox_tests.xml");
+
+ XmlReader reader;
+ ASSERT_TRUE(reader.LoadFile(WideToASCII(omnibox_tests_path)));
+ while (reader.SkipToElement()) {
+ ASSERT_EQ("omnibox_tests", reader.NodeName());
+ reader.Read();
+ while (reader.SkipToElement()) {
+ ASSERT_EQ("test", reader.NodeName());
+ std::string query;
+ std::vector<std::string> expected_providers;
+ ASSERT_TRUE(reader.NodeAttribute("query", &query));
+ reader.Read();
+ while (reader.SkipToElement()) {
+ ASSERT_EQ("provider", reader.NodeName());
+ std::string provider;
+ ASSERT_TRUE(reader.NodeAttribute("provider", &provider));
+ expected_providers.push_back(provider);
+ reader.Read();
+ }
+ RunQueryChain(ASCIIToWide(query));
+ reader.Read();
+ }
+ reader.Read();
+ }
+
+ // Output results.
+ ASSERT_GT(query_count_, 0);
+ int64 mean = time_sum_ / query_count_;
+ wprintf(L"__om_query_count = %d\n", query_count_);
+ wprintf(L"__om_query_timeouts = %d\n", query_timeouts_);
+ wprintf(L"__om_time_per_query_avg = %d\n", mean);
+ // Use the equation stddev = sqrt(Sum(x_i^2)/N - mean^2).
+ wprintf(L"__om_time_per_query_stddev = %d\n", static_cast<int64>(
+ sqrt(1.0 * time_squared_ / query_count_ - mean * mean)));
+ wprintf(L"__om_time_per_query_max = %d\n", time_max_);
+ wprintf(L"__om_time_per_query_min = %d\n", time_min_);
+ wprintf(L"__om_score = %.4f\n", 100.0 * score_ / max_score_);
+}