summaryrefslogtreecommitdiffstats
path: root/chrome/browser/search_engines
diff options
context:
space:
mode:
authorlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 06:23:57 +0000
committerlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 06:23:57 +0000
commit6506f2aee4619a49f4ac32e729f7a01e34b9d8e8 (patch)
tree60904021b970035586afd0fbe47ae18c652d396d /chrome/browser/search_engines
parent33bb14c339d53c34ca1da327f983d7abb8b6fd5a (diff)
downloadchromium_src-6506f2aee4619a49f4ac32e729f7a01e34b9d8e8.zip
chromium_src-6506f2aee4619a49f4ac32e729f7a01e34b9d8e8.tar.gz
chromium_src-6506f2aee4619a49f4ac32e729f7a01e34b9d8e8.tar.bz2
Need to ensure that the autogenerated keyword is generated on the UI thread.
This was broken by r57563. BUG=53557 TEST=unit_test --gtest_filter=TemplateURLModelTest.LoadDoesAutoKeywordUpdate Review URL: http://codereview.chromium.org/3243001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57641 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/search_engines')
-rw-r--r--chrome/browser/search_engines/template_url.cc17
-rw-r--r--chrome/browser/search_engines/template_url_model_unittest.cc58
2 files changed, 65 insertions, 10 deletions
diff --git a/chrome/browser/search_engines/template_url.cc b/chrome/browser/search_engines/template_url.cc
index 29276a6..4c32797 100644
--- a/chrome/browser/search_engines/template_url.cc
+++ b/chrome/browser/search_engines/template_url.cc
@@ -11,6 +11,7 @@
#include "base/string_number_conversions.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/google_url_tracker.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/common/url_constants.h"
@@ -246,6 +247,12 @@ std::string TemplateURLRef::ReplaceSearchTerms(
const std::wstring& terms,
int accepted_suggestion,
const std::wstring& original_query_for_suggestion) const {
+ // GoogleBaseURLValue() enforces this, but this assert helps us catch bad
+ // behavior more frequently (instead of only when there is a GoogleBaseURL
+ // component in the passed in host).
+ DCHECK(!ChromeThread::IsWellKnownThread(ChromeThread::UI) ||
+ ChromeThread::CurrentlyOn(ChromeThread::UI));
+
ParseIfNecessary();
if (!valid_)
return std::string();
@@ -481,6 +488,11 @@ void TemplateURLRef::InvalidateCachedValues() const {
// Returns the value to use for replacements of type GOOGLE_BASE_URL.
// static
std::string TemplateURLRef::GoogleBaseURLValue() {
+ // Normally GoogleURLTracker::GoogleURL() enforces this, but this
+ // assert helps us catch bad behavior at unit tests time.
+ DCHECK(!ChromeThread::IsWellKnownThread(ChromeThread::UI) ||
+ ChromeThread::CurrentlyOn(ChromeThread::UI));
+
return google_base_url_ ?
(*google_base_url_) : GoogleURLTracker::GoogleURL().spec();
}
@@ -488,6 +500,11 @@ std::string TemplateURLRef::GoogleBaseURLValue() {
// Returns the value to use for replacements of type GOOGLE_BASE_SUGGEST_URL.
// static
std::string TemplateURLRef::GoogleBaseSuggestURLValue() {
+ // Normally GoogleURLTracker::GoogleURL() enforces this, but this
+ // assert helps us catch bad behavior at unit tests time.
+ DCHECK(!ChromeThread::IsWellKnownThread(ChromeThread::UI) ||
+ ChromeThread::CurrentlyOn(ChromeThread::UI));
+
// The suggest base URL we want at the end is something like
// "http://clients1.google.TLD/complete/". The key bit we want from the
// original Google base URL is the TLD.
diff --git a/chrome/browser/search_engines/template_url_model_unittest.cc b/chrome/browser/search_engines/template_url_model_unittest.cc
index a60e0ba..a4805be 100644
--- a/chrome/browser/search_engines/template_url_model_unittest.cc
+++ b/chrome/browser/search_engines/template_url_model_unittest.cc
@@ -230,6 +230,13 @@ class TemplateURLModelTest : public testing::Test,
TemplateURLRef::google_base_url_ = new std::string(base_url);
}
+ // Creates a TemplateURL with the same prepopluated id as a real prepopulated
+ // item. The input number determines which prepopulated item. The caller is
+ // responsible for owning the returned TemplateURL*.
+ TemplateURL* CreateReplaceablePreloadedTemplateURL(
+ size_t index_offset_from_default,
+ std::wstring* prepopulated_display_url);
+
// Verifies the behavior of when a preloaded url later gets changed.
// Since the input is the offset from the default, when one passes in
// 0, it tests the default. Passing in a number > 0 will verify what
@@ -245,32 +252,40 @@ class TemplateURLModelTest : public testing::Test,
int changed_count_;
};
-void TemplateURLModelTest::TestLoadUpdatingPreloadedUrl(
- size_t index_offset_from_default) {
- // Create a TemplateURL with the same prepopulated id as
- // a real prepopulated item.
+TemplateURL* TemplateURLModelTest::CreateReplaceablePreloadedTemplateURL(
+ size_t index_offset_from_default,
+ std::wstring* prepopulated_display_url) {
TemplateURL* t_url = CreatePreloadedTemplateURL();
- t_url->set_safe_for_autoreplace(false);
std::vector<TemplateURL*> prepopulated_urls;
size_t default_search_provider_index = 0;
TemplateURLPrepopulateData::GetPrepopulatedEngines(
profile_->GetPrefs(),
&prepopulated_urls,
&default_search_provider_index);
- ASSERT_LT(index_offset_from_default, prepopulated_urls.size());
+ EXPECT_LT(index_offset_from_default, prepopulated_urls.size());
size_t prepopulated_index =
(default_search_provider_index + index_offset_from_default) %
prepopulated_urls.size();
t_url->set_prepopulate_id(
prepopulated_urls[prepopulated_index]->prepopulate_id());
-
- std::wstring original_url = t_url->url()->DisplayURL();
- std::wstring prepopulated_url =
+ *prepopulated_display_url =
prepopulated_urls[prepopulated_index]->url()->DisplayURL();
- ASSERT_STRNE(prepopulated_url.c_str(), original_url.c_str());
STLDeleteElements(&prepopulated_urls);
prepopulated_urls.clear();
+ return t_url;
+}
+
+void TemplateURLModelTest::TestLoadUpdatingPreloadedUrl(
+ size_t index_offset_from_default) {
+ std::wstring prepopulated_url;
+ TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL(
+ index_offset_from_default, &prepopulated_url);
+ t_url->set_safe_for_autoreplace(false);
+
+ std::wstring original_url = t_url->url()->DisplayURL();
+ ASSERT_STRNE(prepopulated_url.c_str(), original_url.c_str());
+
// Then add it to the model and save it all.
ChangeModelToLoadState();
model_->Add(t_url);
@@ -924,6 +939,29 @@ TEST_F(TemplateURLModelTest, LoadUpdatesSearchUrl) {
TestLoadUpdatingPreloadedUrl(1);
}
+// Make sure that the load does update of auto-keywords correctly.
+// This test basically verifies that no asserts or crashes occur
+// during this operation.
+TEST_F(TemplateURLModelTest, LoadDoesAutoKeywordUpdate) {
+ std::wstring prepopulated_url;
+ TemplateURL* t_url = CreateReplaceablePreloadedTemplateURL(
+ 0, &prepopulated_url);
+ t_url->set_safe_for_autoreplace(false);
+ t_url->SetURL("{google:baseURL}?q={searchTerms}", 0, 0);
+ t_url->set_autogenerate_keyword(true);
+
+ // Then add it to the model and save it all.
+ ChangeModelToLoadState();
+ model_->Add(t_url);
+ BlockTillServiceProcessesRequests();
+
+ // Now reload the model and verify that the merge updates the url.
+ ResetModel(true);
+
+ // Wait for any saves to finish.
+ BlockTillServiceProcessesRequests();
+}
+
// Simulates failing to load the webdb and makes sure the default search
// provider is valid.
TEST_F(TemplateURLModelTest, FailedInit) {