| 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/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/history/download_row.h" |
| 9 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/webui/downloads_dom_handler.h" | 13 #include "chrome/browser/ui/webui/downloads_dom_handler.h" |
| 13 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "content/public/browser/download_persistent_store_info.h" | |
| 17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Reads |right_json| into a ListValue |left_list|; returns true if all | 21 // Reads |right_json| into a ListValue |left_list|; returns true if all |
| 22 // key-value pairs in in all dictionaries in |right_list| are also in the | 22 // key-value pairs in in all dictionaries in |right_list| are also in the |
| 23 // corresponding dictionary in |left_list|. Ignores keys in dictionaries in | 23 // corresponding dictionary in |left_list|. Ignores keys in dictionaries in |
| 24 // |left_list| that are not in the corresponding dictionary in |right_list|. | 24 // |left_list| that are not in the corresponding dictionary in |right_list|. |
| 25 bool ListMatches(base::ListValue* left_list, const std::string& right_json) { | 25 bool ListMatches(base::ListValue* left_list, const std::string& right_json) { |
| 26 scoped_ptr<base::Value> right_value(base::JSONReader::Read(right_json)); | 26 scoped_ptr<base::Value> right_value(base::JSONReader::Read(right_json)); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 134 |
| 135 // Tests that DownloadsDOMHandler detects new downloads and relays them to the | 135 // Tests that DownloadsDOMHandler detects new downloads and relays them to the |
| 136 // renderer. | 136 // renderer. |
| 137 // crbug.com/159390: This test fails when daylight savings time ends. | 137 // crbug.com/159390: This test fails when daylight savings time ends. |
| 138 IN_PROC_BROWSER_TEST_F(DownloadsDOMHandlerTest, | 138 IN_PROC_BROWSER_TEST_F(DownloadsDOMHandlerTest, |
| 139 DownloadsDOMHandlerTest_Created) { | 139 DownloadsDOMHandlerTest_Created) { |
| 140 MockDownloadsDOMHandler mddh(download_manager()); | 140 MockDownloadsDOMHandler mddh(download_manager()); |
| 141 | 141 |
| 142 GURL url = test_server()->GetURL("files/downloads/image.jpg"); | 142 GURL url = test_server()->GetURL("files/downloads/image.jpg"); |
| 143 base::Time current(base::Time::Now()); | 143 base::Time current(base::Time::Now()); |
| 144 content::DownloadPersistentStoreInfo population_entries[] = { | 144 download_manager()->CreateDownloadItem( |
| 145 content::DownloadPersistentStoreInfo( | 145 FilePath(FILE_PATH_LITERAL("/path/to/file")), |
| 146 FilePath(FILE_PATH_LITERAL("/path/to/file")), | 146 url, |
| 147 url, | 147 GURL(""), |
| 148 GURL(""), | 148 current - base::TimeDelta::FromMinutes(5), |
| 149 current - base::TimeDelta::FromMinutes(5), | 149 current, |
| 150 current, | 150 128, |
| 151 128, | 151 128, |
| 152 128, | 152 content::DownloadItem::COMPLETE, |
| 153 content::DownloadItem::COMPLETE, | 153 false); |
| 154 1, | |
| 155 false), | |
| 156 }; | |
| 157 std::vector<content::DownloadPersistentStoreInfo> entries( | |
| 158 population_entries, population_entries + arraysize(population_entries)); | |
| 159 download_manager()->OnPersistentStoreQueryComplete(&entries); | |
| 160 | 154 |
| 161 mddh.WaitForDownloadsList(); | 155 mddh.WaitForDownloadsList(); |
| 162 ASSERT_EQ(1, static_cast<int>(mddh.downloads_list()->GetSize())); | 156 ASSERT_EQ(1, static_cast<int>(mddh.downloads_list()->GetSize())); |
| 163 EXPECT_TRUE(ListMatches( | 157 EXPECT_TRUE(ListMatches( |
| 164 mddh.downloads_list(), | 158 mddh.downloads_list(), |
| 165 "[{\"file_externally_removed\": false," | 159 "[{\"file_externally_removed\": false," |
| 166 " \"file_name\": \"file\"," | 160 " \"file_name\": \"file\"," |
| 167 " \"id\": 0," | 161 " \"id\": 0," |
| 168 " \"otr\": false," | 162 " \"otr\": false," |
| 169 " \"since_string\": \"Today\"," | 163 " \"since_string\": \"Today\"," |
| (...skipping 19 matching lines...) Expand all Loading... |
| 189 // TODO(benjhayden): Test incognito, both downloads_list() and that on-record | 183 // TODO(benjhayden): Test incognito, both downloads_list() and that on-record |
| 190 // calls can't access off-record items. | 184 // calls can't access off-record items. |
| 191 | 185 |
| 192 // TODO(benjhayden): Test that bad download ids incoming from the javascript are | 186 // TODO(benjhayden): Test that bad download ids incoming from the javascript are |
| 193 // dropped on the floor. | 187 // dropped on the floor. |
| 194 | 188 |
| 195 // TODO(benjhayden): Test that IsTemporary() downloads are not shown. | 189 // TODO(benjhayden): Test that IsTemporary() downloads are not shown. |
| 196 | 190 |
| 197 // TODO(benjhayden): Test that RemoveObserver is called on all download items, | 191 // TODO(benjhayden): Test that RemoveObserver is called on all download items, |
| 198 // including items that crossed IsTemporary() and back. | 192 // including items that crossed IsTemporary() and back. |
| OLD | NEW |