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/auto_reset.h" | 5 #include "base/auto_reset.h" |
6 #include "base/files/scoped_temp_dir.h" | 6 #include "base/files/scoped_temp_dir.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/history/download_row.h" | 10 #include "chrome/browser/history/download_row.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 base::DictionaryValue* left_dict = NULL; | 30 base::DictionaryValue* left_dict = NULL; |
31 base::DictionaryValue* right_dict = NULL; | 31 base::DictionaryValue* right_dict = NULL; |
32 CHECK(left_list->GetDictionary(i, &left_dict)); | 32 CHECK(left_list->GetDictionary(i, &left_dict)); |
33 CHECK(right_list->GetDictionary(i, &right_dict)); | 33 CHECK(right_list->GetDictionary(i, &right_dict)); |
34 for (base::DictionaryValue::Iterator iter(*right_dict); | 34 for (base::DictionaryValue::Iterator iter(*right_dict); |
35 !iter.IsAtEnd(); iter.Advance()) { | 35 !iter.IsAtEnd(); iter.Advance()) { |
36 base::Value* left_value = NULL; | 36 base::Value* left_value = NULL; |
37 if (left_dict->HasKey(iter.key()) && | 37 if (left_dict->HasKey(iter.key()) && |
38 left_dict->Get(iter.key(), &left_value) && | 38 left_dict->Get(iter.key(), &left_value) && |
39 !iter.value().Equals(left_value)) { | 39 !iter.value().Equals(left_value)) { |
40 LOG(WARNING) << iter.key(); | 40 LOG(WARNING) << "key \"" << iter.key() << "\" doesn't match (" |
| 41 << iter.value() << " vs. " << *left_value << ")"; |
41 return false; | 42 return false; |
42 } | 43 } |
43 } | 44 } |
44 } | 45 } |
45 return true; | 46 return true; |
46 } | 47 } |
47 | 48 |
48 // A |DownloadsDOMHandler| that doesn't use a real WebUI object, but is real in | 49 // A |DownloadsDOMHandler| that doesn't use a real WebUI object, but is real in |
49 // all other respects. | 50 // all other respects. |
50 class MockDownloadsDOMHandler : public DownloadsDOMHandler { | 51 class MockDownloadsDOMHandler : public DownloadsDOMHandler { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 155 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
155 content::DOWNLOAD_INTERRUPT_REASON_NONE, | 156 content::DOWNLOAD_INTERRUPT_REASON_NONE, |
156 false); | 157 false); |
157 | 158 |
158 mock_handler_->WaitForDownloadsList(); | 159 mock_handler_->WaitForDownloadsList(); |
159 ASSERT_EQ(1, static_cast<int>(mock_handler_->downloads_list()->GetSize())); | 160 ASSERT_EQ(1, static_cast<int>(mock_handler_->downloads_list()->GetSize())); |
160 EXPECT_TRUE(ListMatches( | 161 EXPECT_TRUE(ListMatches( |
161 mock_handler_->downloads_list(), | 162 mock_handler_->downloads_list(), |
162 "[{\"file_externally_removed\": false," | 163 "[{\"file_externally_removed\": false," |
163 " \"file_name\": \"file\"," | 164 " \"file_name\": \"file\"," |
164 " \"id\": 1," | 165 " \"id\": \"1\"," |
165 " \"otr\": false," | 166 " \"otr\": false," |
166 " \"since_string\": \"Today\"," | 167 " \"since_string\": \"Today\"," |
167 " \"state\": \"COMPLETE\"," | 168 " \"state\": \"COMPLETE\"," |
168 " \"total\": 128}]")); | 169 " \"total\": 128}]")); |
169 } | 170 } |
170 | 171 |
171 protected: | 172 protected: |
172 scoped_ptr<MockDownloadsDOMHandler> mock_handler_; | 173 scoped_ptr<MockDownloadsDOMHandler> mock_handler_; |
173 | 174 |
174 private: | 175 private: |
(...skipping 18 matching lines...) Expand all Loading... |
193 prefs::kAllowDeletingBrowserHistory, true); | 194 prefs::kAllowDeletingBrowserHistory, true); |
194 mock_handler_->HandleClearAll(NULL); | 195 mock_handler_->HandleClearAll(NULL); |
195 mock_handler_->WaitForDownloadsList(); | 196 mock_handler_->WaitForDownloadsList(); |
196 EXPECT_EQ(0, static_cast<int>(mock_handler_->downloads_list()->GetSize())); | 197 EXPECT_EQ(0, static_cast<int>(mock_handler_->downloads_list()->GetSize())); |
197 } | 198 } |
198 | 199 |
199 // Tests removing one item, both when prohibited and when allowed. | 200 // Tests removing one item, both when prohibited and when allowed. |
200 IN_PROC_BROWSER_TEST_F(DownloadsDOMHandlerTest, RemoveOneItem) { | 201 IN_PROC_BROWSER_TEST_F(DownloadsDOMHandlerTest, RemoveOneItem) { |
201 DownloadAnItem(); | 202 DownloadAnItem(); |
202 base::ListValue item; | 203 base::ListValue item; |
203 item.AppendInteger(1); | 204 item.AppendString("1"); |
204 | 205 |
205 mock_handler_->reset_downloads_list(); | 206 mock_handler_->reset_downloads_list(); |
206 browser()->profile()->GetPrefs()->SetBoolean( | 207 browser()->profile()->GetPrefs()->SetBoolean( |
207 prefs::kAllowDeletingBrowserHistory, false); | 208 prefs::kAllowDeletingBrowserHistory, false); |
208 mock_handler_->HandleRemove(&item); | 209 mock_handler_->HandleRemove(&item); |
209 // Removing an item only sends the new download list if anything was actually | 210 // Removing an item only sends the new download list if anything was actually |
210 // removed, so force it. | 211 // removed, so force it. |
211 mock_handler_->ForceSendCurrentDownloads(); | 212 mock_handler_->ForceSendCurrentDownloads(); |
212 mock_handler_->WaitForDownloadsList(); | 213 mock_handler_->WaitForDownloadsList(); |
213 ASSERT_EQ(1, static_cast<int>(mock_handler_->downloads_list()->GetSize())); | 214 ASSERT_EQ(1, static_cast<int>(mock_handler_->downloads_list()->GetSize())); |
(...skipping 10 matching lines...) Expand all Loading... |
224 // renderer. | 225 // renderer. |
225 // crbug.com/159390: This test fails when daylight savings time ends. | 226 // crbug.com/159390: This test fails when daylight savings time ends. |
226 IN_PROC_BROWSER_TEST_F(DownloadsDOMHandlerTest, DownloadsRelayed) { | 227 IN_PROC_BROWSER_TEST_F(DownloadsDOMHandlerTest, DownloadsRelayed) { |
227 DownloadAnItem(); | 228 DownloadAnItem(); |
228 | 229 |
229 mock_handler_->WaitForDownloadUpdated(); | 230 mock_handler_->WaitForDownloadUpdated(); |
230 ASSERT_EQ(1, static_cast<int>(mock_handler_->download_updated()->GetSize())); | 231 ASSERT_EQ(1, static_cast<int>(mock_handler_->download_updated()->GetSize())); |
231 EXPECT_TRUE(ListMatches( | 232 EXPECT_TRUE(ListMatches( |
232 mock_handler_->download_updated(), | 233 mock_handler_->download_updated(), |
233 "[{\"file_externally_removed\": true," | 234 "[{\"file_externally_removed\": true," |
234 " \"id\": 1}]")); | 235 " \"id\": \"1\"}]")); |
235 | 236 |
236 mock_handler_->reset_downloads_list(); | 237 mock_handler_->reset_downloads_list(); |
237 browser()->profile()->GetPrefs()->SetBoolean( | 238 browser()->profile()->GetPrefs()->SetBoolean( |
238 prefs::kAllowDeletingBrowserHistory, true); | 239 prefs::kAllowDeletingBrowserHistory, true); |
239 mock_handler_->HandleClearAll(NULL); | 240 mock_handler_->HandleClearAll(NULL); |
240 mock_handler_->WaitForDownloadsList(); | 241 mock_handler_->WaitForDownloadsList(); |
241 EXPECT_EQ(0, static_cast<int>(mock_handler_->downloads_list()->GetSize())); | 242 EXPECT_EQ(0, static_cast<int>(mock_handler_->downloads_list()->GetSize())); |
242 } | 243 } |
243 | 244 |
244 | 245 |
245 // TODO(benjhayden): Test the extension downloads filter for both | 246 // TODO(benjhayden): Test the extension downloads filter for both |
246 // mock_handler_.downloads_list() and mock_handler_.download_updated(). | 247 // mock_handler_.downloads_list() and mock_handler_.download_updated(). |
247 | 248 |
248 // TODO(benjhayden): Test incognito, both downloads_list() and that on-record | 249 // TODO(benjhayden): Test incognito, both downloads_list() and that on-record |
249 // calls can't access off-record items. | 250 // calls can't access off-record items. |
250 | 251 |
251 // TODO(benjhayden): Test that bad download ids incoming from the javascript are | 252 // TODO(benjhayden): Test that bad download ids incoming from the javascript are |
252 // dropped on the floor. | 253 // dropped on the floor. |
253 | 254 |
254 // TODO(benjhayden): Test that IsTemporary() downloads are not shown. | 255 // TODO(benjhayden): Test that IsTemporary() downloads are not shown. |
255 | 256 |
256 // TODO(benjhayden): Test that RemoveObserver is called on all download items, | 257 // TODO(benjhayden): Test that RemoveObserver is called on all download items, |
257 // including items that crossed IsTemporary() and back. | 258 // including items that crossed IsTemporary() and back. |
OLD | NEW |