Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Side by Side Diff: chrome/browser/ui/webui/downloads_dom_handler_browsertest.cc

Issue 10915180: Make DownloadHistory observe manager, items (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/scoped_temp_dir.h" 6 #include "base/scoped_temp_dir.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/history/download_persistent_store_info.h"
8 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/webui/downloads_dom_handler.h" 12 #include "chrome/browser/ui/webui/downloads_dom_handler.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
15 #include "content/public/browser/download_persistent_store_info.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 17
18 namespace { 18 namespace {
19 19
20 // Reads |right_json| into a ListValue |left_list|; returns true if all 20 // Reads |right_json| into a ListValue |left_list|; returns true if all
21 // key-value pairs in in all dictionaries in |right_list| are also in the 21 // key-value pairs in in all dictionaries in |right_list| are also in the
22 // corresponding dictionary in |left_list|. Ignores keys in dictionaries in 22 // corresponding dictionary in |left_list|. Ignores keys in dictionaries in
23 // |left_list| that are not in the corresponding dictionary in |right_list|. 23 // |left_list| that are not in the corresponding dictionary in |right_list|.
24 bool ListMatches(base::ListValue* left_list, const std::string& right_json) { 24 bool ListMatches(base::ListValue* left_list, const std::string& right_json) {
25 scoped_ptr<base::Value> right_value(base::JSONReader::Read(right_json)); 25 scoped_ptr<base::Value> right_value(base::JSONReader::Read(right_json));
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 }; 104 };
105 105
106 // Tests that DownloadsDOMHandler detects new downloads and relays them to the 106 // Tests that DownloadsDOMHandler detects new downloads and relays them to the
107 // renderer. 107 // renderer.
108 IN_PROC_BROWSER_TEST_F(DownloadsDOMHandlerTest, 108 IN_PROC_BROWSER_TEST_F(DownloadsDOMHandlerTest,
109 DownloadsDOMHandlerTest_Created) { 109 DownloadsDOMHandlerTest_Created) {
110 MockDownloadsDOMHandler mddh(download_manager()); 110 MockDownloadsDOMHandler mddh(download_manager());
111 111
112 GURL url = test_server()->GetURL("files/downloads/image.jpg"); 112 GURL url = test_server()->GetURL("files/downloads/image.jpg");
113 base::Time current(base::Time::Now()); 113 base::Time current(base::Time::Now());
114 content::DownloadPersistentStoreInfo population_entries[] = { 114 download_manager()->CreateDownloadItem(
115 content::DownloadPersistentStoreInfo( 115 FilePath(FILE_PATH_LITERAL("/path/to/file")),
116 FilePath(FILE_PATH_LITERAL("/path/to/file")), 116 url,
117 url, 117 GURL(""),
118 GURL(""), 118 current - base::TimeDelta::FromMinutes(5),
119 current - base::TimeDelta::FromMinutes(5), 119 current,
120 current, 120 128,
121 128, 121 128,
122 128, 122 content::DownloadItem::COMPLETE,
123 content::DownloadItem::COMPLETE, 123 false);
124 1,
125 false),
126 };
127 std::vector<content::DownloadPersistentStoreInfo> entries(
128 population_entries, population_entries + arraysize(population_entries));
129 download_manager()->OnPersistentStoreQueryComplete(&entries);
130 content::RunMessageLoop(); 124 content::RunMessageLoop();
131 125
132 ASSERT_EQ(1, static_cast<int>(mddh.downloads_list()->GetSize())); 126 ASSERT_EQ(1, static_cast<int>(mddh.downloads_list()->GetSize()));
133 ASSERT_EQ(1, static_cast<int>(mddh.download_updated()->GetSize())); 127 ASSERT_EQ(1, static_cast<int>(mddh.download_updated()->GetSize()));
134 EXPECT_TRUE(ListMatches( 128 EXPECT_TRUE(ListMatches(
135 mddh.downloads_list(), 129 mddh.downloads_list(),
136 "[{\"file_externally_removed\": false," 130 "[{\"file_externally_removed\": false,"
137 " \"file_name\": \"file\"," 131 " \"file_name\": \"file\","
138 " \"id\": 0," 132 " \"id\": 0,"
139 " \"otr\": false," 133 " \"otr\": false,"
(...skipping 16 matching lines...) Expand all
156 // TODO(benjhayden): Test incognito, both downloads_list() and that on-record 150 // TODO(benjhayden): Test incognito, both downloads_list() and that on-record
157 // calls can't access off-record items. 151 // calls can't access off-record items.
158 152
159 // TODO(benjhayden): Test that bad download ids incoming from the javascript are 153 // TODO(benjhayden): Test that bad download ids incoming from the javascript are
160 // dropped on the floor. 154 // dropped on the floor.
161 155
162 // TODO(benjhayden): Test that IsTemporary() downloads are not shown. 156 // TODO(benjhayden): Test that IsTemporary() downloads are not shown.
163 157
164 // TODO(benjhayden): Test that RemoveObserver is called on all download items, 158 // TODO(benjhayden): Test that RemoveObserver is called on all download items,
165 // including items that crossed IsTemporary() and back. 159 // including items that crossed IsTemporary() and back.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698