| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 EXPECT_CALL(download_, AddObserver(_)) | 79 EXPECT_CALL(download_, AddObserver(_)) |
| 80 .WillOnce(SaveArg<0>(&download_observer_)); | 80 .WillOnce(SaveArg<0>(&download_observer_)); |
| 81 EXPECT_CALL(download_, RemoveObserver(Eq(ByRef(download_observer_)))); | 81 EXPECT_CALL(download_, RemoveObserver(Eq(ByRef(download_observer_)))); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void CreatePrompt() { | 84 void CreatePrompt() { |
| 85 prompt_ = DownloadDangerPrompt::Create( | 85 prompt_ = DownloadDangerPrompt::Create( |
| 86 &download_, | 86 &download_, |
| 87 browser()->tab_strip_model()->GetActiveWebContents(), | 87 browser()->tab_strip_model()->GetActiveWebContents(), |
| 88 false, | 88 false, |
| 89 base::Bind(&DownloadDangerPromptTest::PromptCallback, this, | 89 base::Bind(&DownloadDangerPromptTest::PromptCallback, this)); |
| 90 DownloadDangerPrompt::ACCEPT), | |
| 91 base::Bind(&DownloadDangerPromptTest::PromptCallback, this, | |
| 92 DownloadDangerPrompt::CANCEL)); | |
| 93 content::RunAllPendingInMessageLoop(); | 90 content::RunAllPendingInMessageLoop(); |
| 94 } | 91 } |
| 95 | 92 |
| 96 void PromptCallback(DownloadDangerPrompt::Action action) { | 93 void PromptCallback(DownloadDangerPrompt::Action action) { |
| 97 EXPECT_FALSE(did_receive_callback_); | 94 EXPECT_FALSE(did_receive_callback_); |
| 98 EXPECT_EQ(expected_action_, action); | 95 EXPECT_EQ(expected_action_, action); |
| 99 did_receive_callback_ = true; | 96 did_receive_callback_ = true; |
| 100 prompt_ = NULL; | 97 prompt_ = NULL; |
| 101 } | 98 } |
| 102 | 99 |
| 103 content::MockDownloadItem download_; | 100 content::MockDownloadItem download_; |
| 104 content::DownloadItem::Observer* download_observer_; | 101 content::DownloadItem::Observer* download_observer_; |
| 105 DownloadDangerPrompt* prompt_; | 102 DownloadDangerPrompt* prompt_; |
| 106 DownloadDangerPrompt::Action expected_action_; | 103 DownloadDangerPrompt::Action expected_action_; |
| 107 bool did_receive_callback_; | 104 bool did_receive_callback_; |
| 108 | 105 |
| 109 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest); | 106 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest); |
| 110 }; | 107 }; |
| 111 | 108 |
| 112 IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, TestAll) { | 109 IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, TestAll) { |
| 113 OpenNewTab(); | 110 OpenNewTab(); |
| 114 | 111 |
| 115 // The Accept action should cause the accept callback to be invoked. | 112 // Clicking the Accept button should invoke the ACCEPT action. |
| 116 SetUpExpectations(DownloadDangerPrompt::ACCEPT); | 113 SetUpExpectations(DownloadDangerPrompt::ACCEPT); |
| 117 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); | 114 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); |
| 118 VerifyExpectations(); | 115 VerifyExpectations(); |
| 119 | 116 |
| 120 // The Discard action should cause the discard callback to be invoked. | 117 // Clicking the Cancel button should invoke the CANCEL action. |
| 121 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 118 SetUpExpectations(DownloadDangerPrompt::CANCEL); |
| 122 SimulatePromptAction(DownloadDangerPrompt::CANCEL); | 119 SimulatePromptAction(DownloadDangerPrompt::CANCEL); |
| 123 VerifyExpectations(); | 120 VerifyExpectations(); |
| 124 | 121 |
| 125 // If the download is no longer dangerous (because it was accepted), the | 122 // If the download is no longer dangerous (because it was accepted), the |
| 126 // dialog should dismiss itself. | 123 // dialog should DISMISS itself. |
| 127 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 124 SetUpExpectations(DownloadDangerPrompt::DISMISS); |
| 128 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(false)); | 125 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(false)); |
| 129 download_observer()->OnDownloadUpdated(&download()); | 126 download_observer()->OnDownloadUpdated(&download()); |
| 130 VerifyExpectations(); | 127 VerifyExpectations(); |
| 131 | 128 |
| 132 // If the download is in a terminal state then the dialog should dismiss | 129 // If the download is in a terminal state then the dialog should DISMISS |
| 133 // itself. | 130 // itself. |
| 134 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 131 SetUpExpectations(DownloadDangerPrompt::DISMISS); |
| 135 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(true)); | 132 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(true)); |
| 136 EXPECT_CALL(download(), IsDone()).WillOnce(Return(true)); | 133 EXPECT_CALL(download(), IsDone()).WillOnce(Return(true)); |
| 137 download_observer()->OnDownloadUpdated(&download()); | 134 download_observer()->OnDownloadUpdated(&download()); |
| 138 VerifyExpectations(); | 135 VerifyExpectations(); |
| 139 | 136 |
| 140 // If the download is dangerous and is not in a terminal state, don't dismiss | 137 // If the download is dangerous and is not in a terminal state, don't dismiss |
| 141 // the dialog. | 138 // the dialog. |
| 142 SetUpExpectations(DownloadDangerPrompt::ACCEPT); | 139 SetUpExpectations(DownloadDangerPrompt::ACCEPT); |
| 143 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(true)); | 140 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(true)); |
| 144 EXPECT_CALL(download(), IsDone()).WillOnce(Return(false)); | 141 EXPECT_CALL(download(), IsDone()).WillOnce(Return(false)); |
| 145 download_observer()->OnDownloadUpdated(&download()); | 142 download_observer()->OnDownloadUpdated(&download()); |
| 146 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); | 143 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); |
| 147 VerifyExpectations(); | 144 VerifyExpectations(); |
| 148 | 145 |
| 149 // If the containing tab is closed, the dialog should be canceled. | 146 // If the containing tab is closed, the dialog should DISMISS itself. |
| 150 OpenNewTab(); | 147 OpenNewTab(); |
| 148 // TODO(benjhayden): |
| 149 // SetUpExpectations(DownloadDangerPrompt::DISMISS); |
| 151 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 150 SetUpExpectations(DownloadDangerPrompt::CANCEL); |
| 152 chrome::CloseTab(browser()); | 151 chrome::CloseTab(browser()); |
| 153 VerifyExpectations(); | 152 VerifyExpectations(); |
| 154 } | 153 } |
| OLD | NEW |