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/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "chrome/browser/download/download_danger_prompt.h" | 7 #include "chrome/browser/download/download_danger_prompt.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
10 #include "chrome/browser/ui/browser_tabstrip.h" | 10 #include "chrome/browser/ui/browser_tabstrip.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // The Accept action should cause the accept callback to be invoked. | 115 // The Accept action should cause the accept callback to be invoked. |
116 SetUpExpectations(DownloadDangerPrompt::ACCEPT); | 116 SetUpExpectations(DownloadDangerPrompt::ACCEPT); |
117 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); | 117 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); |
118 VerifyExpectations(); | 118 VerifyExpectations(); |
119 | 119 |
120 // The Discard action should cause the discard callback to be invoked. | 120 // The Discard action should cause the discard callback to be invoked. |
121 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 121 SetUpExpectations(DownloadDangerPrompt::CANCEL); |
122 SimulatePromptAction(DownloadDangerPrompt::CANCEL); | 122 SimulatePromptAction(DownloadDangerPrompt::CANCEL); |
123 VerifyExpectations(); | 123 VerifyExpectations(); |
124 | 124 |
125 // If the download is no longer in-progress, the dialog should dismiss itself. | |
126 SetUpExpectations(DownloadDangerPrompt::CANCEL); | |
127 EXPECT_CALL(download(), GetState()).WillOnce( | |
128 Return(content::DownloadItem::CANCELLED)); | |
129 download_observer()->OnDownloadUpdated(&download()); | |
130 VerifyExpectations(); | |
131 | |
132 // If the download is no longer dangerous (because it was accepted), the | 125 // If the download is no longer dangerous (because it was accepted), the |
133 // dialog should dismiss itself. | 126 // dialog should dismiss itself. |
134 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 127 SetUpExpectations(DownloadDangerPrompt::CANCEL); |
135 EXPECT_CALL(download(), GetState()).WillOnce( | |
136 Return(content::DownloadItem::IN_PROGRESS)); | |
137 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(false)); | 128 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(false)); |
138 download_observer()->OnDownloadUpdated(&download()); | 129 download_observer()->OnDownloadUpdated(&download()); |
139 VerifyExpectations(); | 130 VerifyExpectations(); |
140 | 131 |
| 132 // If the download is in a terminal state then the dialog should dismiss |
| 133 // itself. |
| 134 SetUpExpectations(DownloadDangerPrompt::CANCEL); |
| 135 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(true)); |
| 136 EXPECT_CALL(download(), IsDone()).WillOnce(Return(true)); |
| 137 download_observer()->OnDownloadUpdated(&download()); |
| 138 VerifyExpectations(); |
| 139 |
| 140 // If the download is dangerous and is not in a terminal state, don't dismiss |
| 141 // the dialog. |
| 142 SetUpExpectations(DownloadDangerPrompt::ACCEPT); |
| 143 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(true)); |
| 144 EXPECT_CALL(download(), IsDone()).WillOnce(Return(false)); |
| 145 download_observer()->OnDownloadUpdated(&download()); |
| 146 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); |
| 147 VerifyExpectations(); |
| 148 |
141 // If the containing tab is closed, the dialog should be canceled. | 149 // If the containing tab is closed, the dialog should be canceled. |
142 OpenNewTab(); | 150 OpenNewTab(); |
143 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 151 SetUpExpectations(DownloadDangerPrompt::CANCEL); |
144 chrome::CloseTab(browser()); | 152 chrome::CloseTab(browser()); |
145 VerifyExpectations(); | 153 VerifyExpectations(); |
146 } | 154 } |
OLD | NEW |