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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

Issue 14308002: Save memory in the downloads extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r195142 Created 7 years, 8 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
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // and DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT. 257 // and DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT.
258 content::DownloadDangerType danger_type; 258 content::DownloadDangerType danger_type;
259 }; 259 };
260 260
261 void LoadExtension(const char* name) { 261 void LoadExtension(const char* name) {
262 // Store the created Extension object so that we can attach it to 262 // Store the created Extension object so that we can attach it to
263 // ExtensionFunctions. Also load the extension in incognito profiles for 263 // ExtensionFunctions. Also load the extension in incognito profiles for
264 // testing incognito. 264 // testing incognito.
265 extension_ = LoadExtensionIncognito(test_data_dir_.AppendASCII(name)); 265 extension_ = LoadExtensionIncognito(test_data_dir_.AppendASCII(name));
266 CHECK(extension_); 266 CHECK(extension_);
267 content::WebContents* tab = chrome::AddSelectedTabWithURL(
268 current_browser(),
269 extension_->GetResourceURL("empty.html"),
270 content::PAGE_TRANSITION_LINK);
271 extensions::ExtensionSystem::Get(current_browser()->profile())->
272 event_router()->AddEventListener(
273 extensions::event_names::kOnDownloadCreated,
274 tab->GetRenderProcessHost(),
275 GetExtensionId());
276 extensions::ExtensionSystem::Get(current_browser()->profile())->
277 event_router()->AddEventListener(
278 extensions::event_names::kOnDownloadChanged,
279 tab->GetRenderProcessHost(),
280 GetExtensionId());
281 extensions::ExtensionSystem::Get(current_browser()->profile())->
282 event_router()->AddEventListener(
283 extensions::event_names::kOnDownloadErased,
284 tab->GetRenderProcessHost(),
285 GetExtensionId());
267 } 286 }
268 287
269 content::RenderProcessHost* AddFilenameDeterminer() { 288 content::RenderProcessHost* AddFilenameDeterminer() {
270 content::WebContents* tab = chrome::AddSelectedTabWithURL( 289 content::WebContents* tab = chrome::AddSelectedTabWithURL(
271 current_browser(), 290 current_browser(),
272 extension_->GetResourceURL("empty.html"), 291 extension_->GetResourceURL("empty.html"),
273 content::PAGE_TRANSITION_LINK); 292 content::PAGE_TRANSITION_LINK);
274 extensions::ExtensionSystem::Get(current_browser()->profile())-> 293 extensions::ExtensionSystem::Get(current_browser()->profile())->
275 event_router()->AddEventListener( 294 event_router()->AddEventListener(
276 extensions::event_names::kOnDownloadDeterminingFilename, 295 extensions::event_names::kOnDownloadDeterminingFilename,
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
877 }; 896 };
878 897
879 bool ItemIsInterrupted(DownloadItem* item) { 898 bool ItemIsInterrupted(DownloadItem* item) {
880 return item->IsInterrupted(); 899 return item->IsInterrupted();
881 } 900 }
882 901
883 } // namespace 902 } // namespace
884 903
885 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 904 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
886 DownloadExtensionTest_Open) { 905 DownloadExtensionTest_Open) {
906 LoadExtension("downloads_split");
887 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 907 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
888 RunFunctionAndReturnError( 908 RunFunctionAndReturnError(
889 new DownloadsOpenFunction(), 909 new DownloadsOpenFunction(),
890 "[-42]").c_str()); 910 "[-42]").c_str());
891 911
892 DownloadItem* download_item = CreateSlowTestDownload(); 912 DownloadItem* download_item = CreateSlowTestDownload();
893 ASSERT_TRUE(download_item); 913 ASSERT_TRUE(download_item);
894 EXPECT_FALSE(download_item->GetOpened()); 914 EXPECT_FALSE(download_item->GetOpened());
895 EXPECT_FALSE(download_item->GetOpenWhenComplete()); 915 EXPECT_FALSE(download_item->GetOpenWhenComplete());
896 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated, 916 ASSERT_TRUE(WaitFor(events::kOnDownloadCreated,
(...skipping 2353 matching lines...) Expand 10 before | Expand all | Expand 10 after
3250 " \"state\": {" 3270 " \"state\": {"
3251 " \"previous\": \"in_progress\"," 3271 " \"previous\": \"in_progress\","
3252 " \"current\": \"complete\"}}]", 3272 " \"current\": \"complete\"}}]",
3253 item->GetId(), 3273 item->GetId(),
3254 GetFilename("42.txt.crdownload").c_str(), 3274 GetFilename("42.txt.crdownload").c_str(),
3255 GetFilename("42.txt").c_str()))); 3275 GetFilename("42.txt").c_str())));
3256 } 3276 }
3257 3277
3258 // TODO(benjhayden) Figure out why DisableExtension() does not fire 3278 // TODO(benjhayden) Figure out why DisableExtension() does not fire
3259 // OnListenerRemoved. 3279 // OnListenerRemoved.
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698