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

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

Issue 16018005: Use DownloadItem::GetState() in chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 2599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2610 2610
2611 DownloadManager* download_manager = 2611 DownloadManager* download_manager =
2612 BrowserContext::GetDownloadManager(browser->profile()); 2612 BrowserContext::GetDownloadManager(browser->profile());
2613 DownloadItem* selected_item = download_manager->GetDownload(id); 2613 DownloadItem* selected_item = download_manager->GetDownload(id);
2614 if (!selected_item) { 2614 if (!selected_item) {
2615 AutomationJSONReply(this, reply_message) 2615 AutomationJSONReply(this, reply_message)
2616 .SendError(base::StringPrintf("No download with an id of %d\n", id)); 2616 .SendError(base::StringPrintf("No download with an id of %d\n", id));
2617 return; 2617 return;
2618 } 2618 }
2619 2619
2620 DownloadItem::DownloadState download_state = selected_item->GetState();
2621
2620 // We need to be IN_PROGRESS for these actions. 2622 // We need to be IN_PROGRESS for these actions.
2621 if ((action == "pause" || action == "resume" || action == "cancel") && 2623 if ((action == "pause" || action == "resume" || action == "cancel") &&
2622 !selected_item->IsInProgress()) { 2624 download_state != DownloadItem::IN_PROGRESS) {
asanka 2013/05/28 18:43:15 This check is necessary for 'pause' and 'resume' g
2623 AutomationJSONReply(this, reply_message) 2625 AutomationJSONReply(this, reply_message)
2624 .SendError("Selected DownloadItem is not in progress."); 2626 .SendError("Selected DownloadItem is not in progress.");
2625 } 2627 }
2626 2628
2627 if (action == "open") { 2629 if (action == "open") {
2628 selected_item->AddObserver( 2630 selected_item->AddObserver(
2629 new AutomationProviderDownloadUpdatedObserver( 2631 new AutomationProviderDownloadUpdatedObserver(
2630 this, reply_message, true, browser->profile()->IsOffTheRecord())); 2632 this, reply_message, true, browser->profile()->IsOffTheRecord()));
2631 selected_item->OpenDownload(); 2633 selected_item->OpenDownload();
2632 } else if (action == "toggle_open_files_like_this") { 2634 } else if (action == "toggle_open_files_like_this") {
(...skipping 11 matching lines...) Expand all
2644 selected_item->Remove(); 2646 selected_item->Remove();
2645 } else if (action == "decline_dangerous_download") { 2647 } else if (action == "decline_dangerous_download") {
2646 new AutomationProviderDownloadModelChangedObserver( 2648 new AutomationProviderDownloadModelChangedObserver(
2647 this, reply_message, download_manager); 2649 this, reply_message, download_manager);
2648 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 2650 selected_item->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
2649 } else if (action == "save_dangerous_download") { 2651 } else if (action == "save_dangerous_download") {
2650 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2652 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2651 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2653 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2652 selected_item->DangerousDownloadValidated(); 2654 selected_item->DangerousDownloadValidated();
2653 } else if (action == "pause") { 2655 } else if (action == "pause") {
2654 if (!selected_item->IsInProgress() || selected_item->IsPaused()) { 2656 // If action will be a no-op; respond right from here. No-op implies
2655 // Action would be a no-op; respond right from here. No-op implies 2657 // the test is poorly written or failing, so make it an error return.
2656 // the test is poorly written or failing, so make it an error return. 2658 if (download_state != DownloadItem::IN_PROGRESS) {
2657 if (!selected_item->IsInProgress()) { 2659 AutomationJSONReply(this, reply_message)
2658 AutomationJSONReply(this, reply_message) 2660 .SendError("Action 'pause' called on download in termal state.");
2659 .SendError("Action 'pause' called on download in termal state."); 2661 } else if (selected_item->IsPaused()) {
2660 } else { 2662 AutomationJSONReply(this, reply_message)
2661 AutomationJSONReply(this, reply_message) 2663 .SendError("Action 'pause' called on already paused download.");
2662 .SendError("Action 'pause' called on already paused download.");
2663 }
2664 } else { 2664 } else {
2665 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2665 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2666 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2666 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2667 selected_item->Pause(); 2667 selected_item->Pause();
2668 } 2668 }
2669 } else if (action == "resume") { 2669 } else if (action == "resume") {
2670 if (!selected_item->IsInProgress() || !selected_item->IsPaused()) { 2670 // If action will be a no-op; respond right from here. No-op implies
2671 // Action would be a no-op; respond right from here. No-op implies 2671 // the test is poorly written or failing, so make it an error return.
2672 // the test is poorly written or failing, so make it an error return. 2672 if (download_state != DownloadItem::IN_PROGRESS) {
2673 if (!selected_item->IsInProgress()) { 2673 AutomationJSONReply(this, reply_message)
2674 AutomationJSONReply(this, reply_message) 2674 .SendError("Action 'resume' called on download in termal state.");
2675 .SendError("Action 'resume' called on download in termal state."); 2675 } else if (!selected_item->IsPaused()) {
2676 } else { 2676 AutomationJSONReply(this, reply_message)
2677 AutomationJSONReply(this, reply_message) 2677 .SendError("Action 'resume' called on unpaused download.");
2678 .SendError("Action 'resume' called on unpaused download.");
2679 }
2680 } else { 2678 } else {
2681 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2679 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2682 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2680 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2683 selected_item->Resume(); 2681 selected_item->Resume();
2684 } 2682 }
2685 } else if (action == "cancel") { 2683 } else if (action == "cancel") {
2686 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver( 2684 selected_item->AddObserver(new AutomationProviderDownloadUpdatedObserver(
2687 this, reply_message, false, browser->profile()->IsOffTheRecord())); 2685 this, reply_message, false, browser->profile()->IsOffTheRecord()));
2688 selected_item->Cancel(true); 2686 selected_item->Cancel(true);
2689 } else { 2687 } else {
(...skipping 3000 matching lines...) Expand 10 before | Expand all | Expand 10 after
5690 if (g_browser_process) 5688 if (g_browser_process)
5691 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 5689 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
5692 } 5690 }
5693 5691
5694 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, 5692 void TestingAutomationProvider::EnsureTabSelected(Browser* browser,
5695 WebContents* tab) { 5693 WebContents* tab) {
5696 TabStripModel* tab_strip = browser->tab_strip_model(); 5694 TabStripModel* tab_strip = browser->tab_strip_model();
5697 if (tab_strip->GetActiveWebContents() != tab) 5695 if (tab_strip->GetActiveWebContents() != tab)
5698 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); 5696 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true);
5699 } 5697 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698