summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-10 02:37:22 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-10 02:37:22 +0000
commitdeb27ae20cd7d59fba58ad530a72b2dbf8a099ee (patch)
tree7c751a2197b767521e89849abd2cb35e874238d0 /chrome/browser/search_engines
parentce7c39483b5e113ec862a231580684f35268c227 (diff)
downloadchromium_src-deb27ae20cd7d59fba58ad530a72b2dbf8a099ee.zip
chromium_src-deb27ae20cd7d59fba58ad530a72b2dbf8a099ee.tar.gz
chromium_src-deb27ae20cd7d59fba58ad530a72b2dbf8a099ee.tar.bz2
Scrape search definitions from forms that have onsubmit handlers. The scraping is done after submit events are handled by the page DOM so doing this is safe.
Adds test infrastructure for determining that scraping occurs on submit: - allow testserver to be configured to serve pages from / on the server - provide a ui test util that navigates and waits for N subsequent redirections/navigations before returning control to the test to handle automated submission Eric, please review the test server changes. Scott, please look over everything else. Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=13444 Review URL: http://codereview.chromium.org/62145 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13491 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines')
-rw-r--r--chrome/browser/search_engines/template_url_scraper_unittest.cc90
1 files changed, 90 insertions, 0 deletions
diff --git a/chrome/browser/search_engines/template_url_scraper_unittest.cc b/chrome/browser/search_engines/template_url_scraper_unittest.cc
new file mode 100644
index 0000000..71aace7
--- /dev/null
+++ b/chrome/browser/search_engines/template_url_scraper_unittest.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
+// source code is governed by a BSD-style license that can be found in the
+// LICENSE file.
+
+#include "chrome/browser/browser.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/search_engines/template_url_model.h"
+#include "chrome/browser/search_engines/template_url_prepopulate_data.h"
+#include "chrome/common/notification_registrar.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/notification_type.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+#include "net/base/host_resolver_unittest.h"
+#include "net/base/net_util.h"
+
+namespace {
+class TemplateURLScraperTest : public InProcessBrowserTest {
+ public:
+ TemplateURLScraperTest() {
+ }
+
+ protected:
+ virtual void ConfigureHostMapper(net::RuleBasedHostMapper* host_mapper) {
+ InProcessBrowserTest::ConfigureHostMapper(host_mapper);
+ // We use foo.com in our tests.
+ host_mapper->AddRule("*.foo.com", "localhost");
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TemplateURLScraperTest);
+};
+
+class TemplateURLModelLoader : public NotificationObserver {
+ public:
+ explicit TemplateURLModelLoader(TemplateURLModel* model) : model_(model) {
+ registrar_.Add(this, NotificationType::TEMPLATE_URL_MODEL_LOADED,
+ Source<TemplateURLModel>(model));
+ model_->Load();
+ ui_test_utils::RunMessageLoop();
+ }
+
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ if (type == NotificationType::TEMPLATE_URL_MODEL_LOADED &&
+ Source<TemplateURLModel>(source).ptr() == model_) {
+ MessageLoop::current()->Quit();
+ }
+ }
+
+ private:
+ NotificationRegistrar registrar_;
+
+ TemplateURLModel* model_;
+
+ DISALLOW_COPY_AND_ASSIGN(TemplateURLModelLoader);
+};
+
+} // namespace
+
+/*
+IN_PROC_BROWSER_TEST_F(TemplateURLScraperTest, ScrapeWithOnSubmit) {
+ TemplateURLModel* template_urls = browser()->profile()->GetTemplateURLModel();
+ TemplateURLModelLoader loader(template_urls);
+
+ std::vector<const TemplateURL*> all_urls = template_urls->GetTemplateURLs();
+
+ // We need to substract the default pre-populated engines that the profile is
+ // set up with.
+ size_t default_index = 0;
+ std::vector<TemplateURL*> prepopulate_urls;
+ TemplateURLPrepopulateData::GetPrepopulatedEngines(
+ browser()->profile()->GetPrefs(),
+ &prepopulate_urls,
+ &default_index);
+
+ EXPECT_EQ(prepopulate_urls.size(), all_urls.size());
+
+ scoped_refptr<HTTPTestServer> server(
+ HTTPTestServer::CreateServerWithFileRootURL(
+ L"chrome/test/data/template_url_scraper/submit_handler", L"/",
+ g_browser_process->io_thread()->message_loop()));
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
+ browser(), GURL("http://www.foo.com:1337/"), 2);
+
+ all_urls = template_urls->GetTemplateURLs();
+ EXPECT_EQ(1, all_urls.size() - prepopulate_urls.size());
+}
+*/