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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/search_engines/template_url.h" | 10 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 }; | 40 }; |
41 | 41 |
42 // Basic set-up for TemplateURLFetcher tests. | 42 // Basic set-up for TemplateURLFetcher tests. |
43 class TemplateURLFetcherTest : public testing::Test { | 43 class TemplateURLFetcherTest : public testing::Test { |
44 public: | 44 public: |
45 TemplateURLFetcherTest(); | 45 TemplateURLFetcherTest(); |
46 | 46 |
47 virtual void SetUp() OVERRIDE { | 47 virtual void SetUp() OVERRIDE { |
48 test_util_.SetUp(); | 48 test_util_.SetUp(); |
49 test_util_.StartIOThread(); | 49 test_util_.StartIOThread(); |
50 ASSERT_TRUE(test_util_.profile()); | 50 TestingProfile* profile = test_util_.profile(); |
51 ASSERT_TRUE( | 51 ASSERT_TRUE(profile); |
52 TemplateURLFetcherFactory::GetForProfile(test_util_.profile())); | 52 ASSERT_TRUE(TemplateURLFetcherFactory::GetForProfile(profile)); |
53 | 53 |
54 test_util_.profile()->CreateRequestContext(); | 54 profile->CreateRequestContext(); |
55 ASSERT_TRUE(test_util_.profile()->GetRequestContext()); | 55 ASSERT_TRUE(profile->GetRequestContext()); |
56 ASSERT_TRUE(test_server_.Start()); | 56 ASSERT_TRUE(test_server_.Start()); |
57 } | 57 } |
58 | 58 |
59 virtual void TearDown() OVERRIDE { | 59 virtual void TearDown() OVERRIDE { |
60 test_util_.TearDown(); | 60 test_util_.TearDown(); |
61 } | 61 } |
62 | 62 |
63 // Called by ~TemplateURLFetcherTestCallbacks. | 63 // Called by ~TemplateURLFetcherTestCallbacks. |
64 void DestroyedCallback(TemplateURLFetcherTestCallbacks* callbacks); | 64 void DestroyedCallback(TemplateURLFetcherTestCallbacks* callbacks); |
65 | 65 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 last_callback_template_url_->keyword()); | 284 last_callback_template_url_->keyword()); |
285 EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); | 285 EXPECT_FALSE(last_callback_template_url_->safe_for_autoreplace()); |
286 } | 286 } |
287 | 287 |
288 TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) { | 288 TEST_F(TemplateURLFetcherTest, DuplicateKeywordsTest) { |
289 string16 keyword(ASCIIToUTF16("test")); | 289 string16 keyword(ASCIIToUTF16("test")); |
290 TemplateURLData data; | 290 TemplateURLData data; |
291 data.short_name = keyword; | 291 data.short_name = keyword; |
292 data.SetKeyword(keyword); | 292 data.SetKeyword(keyword); |
293 data.SetURL("http://example.com/"); | 293 data.SetURL("http://example.com/"); |
294 test_util_.model()->Add(new TemplateURL(data)); | 294 test_util_.model()->Add(new TemplateURL(test_util_.profile(), data)); |
295 test_util_.ChangeModelToLoadState(); | 295 test_util_.ChangeModelToLoadState(); |
296 | 296 |
297 ASSERT_TRUE(test_util_.model()->GetTemplateURLForKeyword(keyword)); | 297 ASSERT_TRUE(test_util_.model()->GetTemplateURLForKeyword(keyword)); |
298 | 298 |
299 // This should bail because the keyword already exists. | 299 // This should bail because the keyword already exists. |
300 std::string osdd_file_name("simple_open_search.xml"); | 300 std::string osdd_file_name("simple_open_search.xml"); |
301 StartDownload(keyword, osdd_file_name, | 301 StartDownload(keyword, osdd_file_name, |
302 TemplateURLFetcher::AUTODETECTED_PROVIDER, true); | 302 TemplateURLFetcher::AUTODETECTED_PROVIDER, true); |
303 ASSERT_EQ(0, add_provider_called_); | 303 ASSERT_EQ(0, add_provider_called_); |
304 ASSERT_EQ(1, callbacks_destroyed_); | 304 ASSERT_EQ(1, callbacks_destroyed_); |
(...skipping 12 matching lines...) Expand all Loading... |
317 StartDownload(keyword, osdd_file_name, | 317 StartDownload(keyword, osdd_file_name, |
318 TemplateURLFetcher::EXPLICIT_PROVIDER, true); | 318 TemplateURLFetcher::EXPLICIT_PROVIDER, true); |
319 ASSERT_EQ(0, add_provider_called_); | 319 ASSERT_EQ(0, add_provider_called_); |
320 ASSERT_EQ(1, callbacks_destroyed_); | 320 ASSERT_EQ(1, callbacks_destroyed_); |
321 | 321 |
322 WaitForDownloadToFinish(); | 322 WaitForDownloadToFinish(); |
323 ASSERT_EQ(1, add_provider_called_); | 323 ASSERT_EQ(1, add_provider_called_); |
324 ASSERT_EQ(2, callbacks_destroyed_); | 324 ASSERT_EQ(2, callbacks_destroyed_); |
325 ASSERT_TRUE(last_callback_template_url_.get()); | 325 ASSERT_TRUE(last_callback_template_url_.get()); |
326 } | 326 } |
OLD | NEW |