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

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 11711003: Remove the DownloadItem::TogglePause() interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync'd to r175145. Created 7 years, 11 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 | « no previous file | chrome/browser/download/download_shelf_context_menu.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "chrome/browser/automation/testing_automation_provider.h" 5 #include "chrome/browser/automation/testing_automation_provider.h"
6 6
7 #include <map> 7 #include <map>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after
2650 DownloadManager* download_manager = 2650 DownloadManager* download_manager =
2651 BrowserContext::GetDownloadManager(browser->profile()); 2651 BrowserContext::GetDownloadManager(browser->profile());
2652 DownloadItem* selected_item = download_manager->GetDownload(id); 2652 DownloadItem* selected_item = download_manager->GetDownload(id);
2653 if (!selected_item) { 2653 if (!selected_item) {
2654 AutomationJSONReply(this, reply_message) 2654 AutomationJSONReply(this, reply_message)
2655 .SendError(StringPrintf("No download with an id of %d\n", id)); 2655 .SendError(StringPrintf("No download with an id of %d\n", id));
2656 return; 2656 return;
2657 } 2657 }
2658 2658
2659 // We need to be IN_PROGRESS for these actions. 2659 // We need to be IN_PROGRESS for these actions.
2660 if ((action == "toggle_pause" || action == "cancel") && 2660 if ((action == "pause" || action == "resume" || action == "cancel") &&
2661 !selected_item->IsInProgress()) { 2661 !selected_item->IsInProgress()) {
2662 AutomationJSONReply(this, reply_message) 2662 AutomationJSONReply(this, reply_message)
2663 .SendError("Selected DownloadItem is not in progress."); 2663 .SendError("Selected DownloadItem is not in progress.");
2664 } 2664 }
2665 2665
2666 if (action == "open") { 2666 if (action == "open") {
2667 selected_item->AddObserver( 2667 selected_item->AddObserver(
2668 new AutomationProviderDownloadUpdatedObserver( 2668 new AutomationProviderDownloadUpdatedObserver(
2669 this, reply_message, true, browser->profile()->IsOffTheRecord())); 2669 this, reply_message, true, browser->profile()->IsOffTheRecord()));
2670 selected_item->OpenDownload(); 2670 selected_item->OpenDownload();
(...skipping 11 matching lines...) Expand all
2682 this, reply_message, download_manager); 2682 this, reply_message, download_manager);
2683 selected_item->Remove(); 2683 selected_item->Remove();
2684 } else if (action == "decline_dangerous_download") { 2684 } else if (action == "decline_dangerous_download") {
2685 new AutomationProviderDownloadModelChangedObserver( 2685 new AutomationProviderDownloadModelChangedObserver(
2686 this, reply_message, download_manager); 2686 this, reply_message, download_manager);
2687 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 2687 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
2688 } else if (action == "save_dangerous_download") { 2688 } else if (action == "save_dangerous_download") {
2689 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2689 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2690 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2690 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2691 selected_item->DangerousDownloadValidated(); 2691 selected_item->DangerousDownloadValidated();
2692 } else if (action == "toggle_pause") { 2692 } else if (action == "pause") {
2693 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2693 if (!selected_item->IsInProgress() || selected_item->IsPaused()) {
2694 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2694 // Action would be a no-op; respond right from here. No-op implies
2695 // This will still return if download has already completed. 2695 // the test is poorly written or failing, so make it an error return.
2696 selected_item->TogglePause(); 2696 if (!selected_item->IsInProgress()) {
2697 AutomationJSONReply(this, reply_message)
2698 .SendError("Action 'pause' called on download in termal state.");
2699 } else {
2700 AutomationJSONReply(this, reply_message)
2701 .SendError("Action 'pause' called on already paused download.");
2702 }
2703 } else {
2704 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2705 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2706 selected_item->Pause();
2707 }
2708 } else if (action == "resume") {
2709 if (!selected_item->IsInProgress() || !selected_item->IsPaused()) {
2710 // Action would be a no-op; respond right from here. No-op implies
2711 // the test is poorly written or failing, so make it an error return.
2712 if (!selected_item->IsInProgress()) {
2713 AutomationJSONReply(this, reply_message)
2714 .SendError("Action 'resume' called on download in termal state.");
2715 } else {
2716 AutomationJSONReply(this, reply_message)
2717 .SendError("Action 'resume' called on unpaused download.");
2718 }
2719 } else {
2720 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2721 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2722 selected_item->Resume();
2723 }
2697 } else if (action == "cancel") { 2724 } else if (action == "cancel") {
2698 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2725 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2699 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2726 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2700 selected_item->Cancel(true); 2727 selected_item->Cancel(true);
2701 } else { 2728 } else {
2702 AutomationJSONReply(this, reply_message) 2729 AutomationJSONReply(this, reply_message)
2703 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str())); 2730 .SendError(StringPrintf("Invalid action '%s' given.", action.c_str()));
2704 } 2731 }
2705 } 2732 }
2706 2733
(...skipping 3569 matching lines...) Expand 10 before | Expand all | Expand 10 after
6276 if (g_browser_process) 6303 if (g_browser_process)
6277 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 6304 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
6278 } 6305 }
6279 6306
6280 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 6307 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
6281 WebContents* tab) { 6308 WebContents* tab) {
6282 TabStripModel* tab_strip = browser->tab_strip_model(); 6309 TabStripModel* tab_strip = browser->tab_strip_model();
6283 if (tab_strip->GetActiveWebContents() != tab) 6310 if (tab_strip->GetActiveWebContents() != tab)
6284 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); 6311 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true);
6285 } 6312 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_shelf_context_menu.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698