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 "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 11 matching lines...) Expand all Loading... | |
22 | 22 |
23 // Handles callbacks from TemplateURLFetcher. | 23 // Handles callbacks from TemplateURLFetcher. |
24 class TemplateURLFetcherTestCallbacks : public TemplateURLFetcherCallbacks { | 24 class TemplateURLFetcherTestCallbacks : public TemplateURLFetcherCallbacks { |
25 public: | 25 public: |
26 explicit TemplateURLFetcherTestCallbacks(TemplateURLFetcherTest* test) | 26 explicit TemplateURLFetcherTestCallbacks(TemplateURLFetcherTest* test) |
27 : test_(test) { | 27 : test_(test) { |
28 } | 28 } |
29 virtual ~TemplateURLFetcherTestCallbacks(); | 29 virtual ~TemplateURLFetcherTestCallbacks(); |
30 | 30 |
31 // TemplateURLFetcherCallbacks implementation. | 31 // TemplateURLFetcherCallbacks implementation. |
32 virtual void ConfirmSetDefaultSearchProvider( | 32 virtual void ConfirmSetDefaultSearchProvider(TemplateURL* template_url, |
33 TemplateURL* template_url, | 33 Profile* profile); |
sky
2011/10/11 14:54:10
Since you're touching this code, how about adding
| |
34 TemplateURLService* template_url_service); | 34 virtual void ConfirmAddSearchProvider(TemplateURL* template_url, |
35 virtual void ConfirmAddSearchProvider( | 35 Profile* profile); |
36 TemplateURL* template_url, | |
37 Profile* profile); | |
38 | 36 |
39 private: | 37 private: |
40 TemplateURLFetcherTest* test_; | 38 TemplateURLFetcherTest* test_; |
41 | 39 |
42 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcherTestCallbacks); | 40 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcherTestCallbacks); |
43 }; | 41 }; |
44 | 42 |
45 // Basic set-up for TemplateURLFetcher tests. | 43 // Basic set-up for TemplateURLFetcher tests. |
46 class TemplateURLFetcherTest : public testing::Test { | 44 class TemplateURLFetcherTest : public testing::Test { |
47 public: | 45 public: |
(...skipping 13 matching lines...) Expand all Loading... | |
61 | 59 |
62 virtual void TearDown() { | 60 virtual void TearDown() { |
63 test_util_.TearDown(); | 61 test_util_.TearDown(); |
64 } | 62 } |
65 | 63 |
66 // Called by ~TemplateURLFetcherTestCallbacks. | 64 // Called by ~TemplateURLFetcherTestCallbacks. |
67 void DestroyedCallback(TemplateURLFetcherTestCallbacks* callbacks); | 65 void DestroyedCallback(TemplateURLFetcherTestCallbacks* callbacks); |
68 | 66 |
69 // TemplateURLFetcherCallbacks implementation. (Although not derived from | 67 // TemplateURLFetcherCallbacks implementation. (Although not derived from |
70 // this class, these methods handle those calls for the test.) | 68 // this class, these methods handle those calls for the test.) |
71 virtual void ConfirmSetDefaultSearchProvider( | 69 virtual void ConfirmSetDefaultSearchProvider(TemplateURL* template_url, |
72 TemplateURL* template_url, | 70 Profile* profile); |
73 TemplateURLService* template_url_service); | 71 virtual void ConfirmAddSearchProvider(TemplateURL* template_url, |
74 virtual void ConfirmAddSearchProvider( | 72 Profile* profile); |
75 TemplateURL* template_url, | |
76 Profile* profile); | |
77 | 73 |
78 protected: | 74 protected: |
79 // Schedules the download of the url. | 75 // Schedules the download of the url. |
80 void StartDownload(const string16& keyword, | 76 void StartDownload(const string16& keyword, |
81 const std::string& osdd_file_name, | 77 const std::string& osdd_file_name, |
82 TemplateURLFetcher::ProviderType provider_type, | 78 TemplateURLFetcher::ProviderType provider_type, |
83 bool check_that_file_exists); | 79 bool check_that_file_exists); |
84 | 80 |
85 // Waits for any downloads to finish. | 81 // Waits for any downloads to finish. |
86 void WaitForDownloadToFinish(); | 82 void WaitForDownloadToFinish(); |
(...skipping 20 matching lines...) Expand all Loading... | |
107 private: | 103 private: |
108 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcherTest); | 104 DISALLOW_COPY_AND_ASSIGN(TemplateURLFetcherTest); |
109 }; | 105 }; |
110 | 106 |
111 TemplateURLFetcherTestCallbacks::~TemplateURLFetcherTestCallbacks() { | 107 TemplateURLFetcherTestCallbacks::~TemplateURLFetcherTestCallbacks() { |
112 test_->DestroyedCallback(this); | 108 test_->DestroyedCallback(this); |
113 } | 109 } |
114 | 110 |
115 void TemplateURLFetcherTestCallbacks::ConfirmSetDefaultSearchProvider( | 111 void TemplateURLFetcherTestCallbacks::ConfirmSetDefaultSearchProvider( |
116 TemplateURL* template_url, | 112 TemplateURL* template_url, |
117 TemplateURLService* template_url_service) { | 113 Profile* profile) { |
118 test_->ConfirmSetDefaultSearchProvider(template_url, template_url_service); | 114 test_->ConfirmSetDefaultSearchProvider(template_url, profile); |
119 } | 115 } |
120 | 116 |
121 void TemplateURLFetcherTestCallbacks::ConfirmAddSearchProvider( | 117 void TemplateURLFetcherTestCallbacks::ConfirmAddSearchProvider( |
122 TemplateURL* template_url, | 118 TemplateURL* template_url, |
123 Profile* profile) { | 119 Profile* profile) { |
124 test_->ConfirmAddSearchProvider(template_url, profile); | 120 test_->ConfirmAddSearchProvider(template_url, profile); |
125 } | 121 } |
126 | 122 |
127 TemplateURLFetcherTest::TemplateURLFetcherTest() | 123 TemplateURLFetcherTest::TemplateURLFetcherTest() |
128 : test_server_(net::TestServer::TYPE_HTTP, | 124 : test_server_(net::TestServer::TYPE_HTTP, |
129 FilePath(FILE_PATH_LITERAL("chrome/test/data"))), | 125 FilePath(FILE_PATH_LITERAL("chrome/test/data"))), |
130 callbacks_destroyed_(0), | 126 callbacks_destroyed_(0), |
131 set_default_called_(0), | 127 set_default_called_(0), |
132 add_provider_called_(0), | 128 add_provider_called_(0), |
133 waiting_for_download_(false) { | 129 waiting_for_download_(false) { |
134 } | 130 } |
135 | 131 |
136 void TemplateURLFetcherTest::DestroyedCallback( | 132 void TemplateURLFetcherTest::DestroyedCallback( |
137 TemplateURLFetcherTestCallbacks* callbacks) { | 133 TemplateURLFetcherTestCallbacks* callbacks) { |
138 callbacks_destroyed_++; | 134 callbacks_destroyed_++; |
139 if (waiting_for_download_) | 135 if (waiting_for_download_) |
140 MessageLoop::current()->Quit(); | 136 MessageLoop::current()->Quit(); |
141 } | 137 } |
142 | 138 |
143 void TemplateURLFetcherTest::ConfirmSetDefaultSearchProvider( | 139 void TemplateURLFetcherTest::ConfirmSetDefaultSearchProvider( |
144 TemplateURL* template_url, | 140 TemplateURL* template_url, |
145 TemplateURLService* template_url_service) { | 141 Profile* profile) { |
146 last_callback_template_url_.reset(template_url); | 142 last_callback_template_url_.reset(template_url); |
147 set_default_called_++; | 143 set_default_called_++; |
148 } | 144 } |
149 | 145 |
150 void TemplateURLFetcherTest::ConfirmAddSearchProvider( | 146 void TemplateURLFetcherTest::ConfirmAddSearchProvider( |
151 TemplateURL* template_url, | 147 TemplateURL* template_url, |
152 Profile* profile) { | 148 Profile* profile) { |
153 last_callback_template_url_.reset(template_url); | 149 last_callback_template_url_.reset(template_url); |
154 add_provider_called_++; | 150 add_provider_called_++; |
155 } | 151 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 ASSERT_EQ(0, add_provider_called_); | 377 ASSERT_EQ(0, add_provider_called_); |
382 ASSERT_EQ(2, callbacks_destroyed_); | 378 ASSERT_EQ(2, callbacks_destroyed_); |
383 | 379 |
384 WaitForDownloadToFinish(); | 380 WaitForDownloadToFinish(); |
385 ASSERT_EQ(1, set_default_called_); | 381 ASSERT_EQ(1, set_default_called_); |
386 ASSERT_EQ(0, add_provider_called_); | 382 ASSERT_EQ(0, add_provider_called_); |
387 ASSERT_EQ(3, callbacks_destroyed_); | 383 ASSERT_EQ(3, callbacks_destroyed_); |
388 ASSERT_TRUE(last_callback_template_url_.get()); | 384 ASSERT_TRUE(last_callback_template_url_.get()); |
389 ASSERT_NE(keyword, last_callback_template_url_->keyword()); | 385 ASSERT_NE(keyword, last_callback_template_url_->keyword()); |
390 } | 386 } |
OLD | NEW |