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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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), | 90 DownloadDangerPrompt::ACCEPT), |
91 base::Bind(&DownloadDangerPromptTest::PromptCallback, this, | 91 base::Bind(&DownloadDangerPromptTest::PromptCallback, this, |
92 DownloadDangerPrompt::CANCEL)); | 92 DownloadDangerPrompt::CANCEL), |
| 93 base::Bind(&DownloadDangerPromptTest::PromptDestroyed, this)); |
93 content::RunAllPendingInMessageLoop(); | 94 content::RunAllPendingInMessageLoop(); |
94 } | 95 } |
95 | 96 |
96 void PromptCallback(DownloadDangerPrompt::Action action) { | 97 void PromptCallback(DownloadDangerPrompt::Action action) { |
97 EXPECT_FALSE(did_receive_callback_); | 98 EXPECT_FALSE(did_receive_callback_); |
98 EXPECT_EQ(expected_action_, action); | 99 EXPECT_EQ(expected_action_, action); |
99 did_receive_callback_ = true; | 100 did_receive_callback_ = true; |
| 101 } |
| 102 |
| 103 void PromptDestroyed() { |
100 prompt_ = NULL; | 104 prompt_ = NULL; |
101 } | 105 } |
102 | 106 |
103 content::MockDownloadItem download_; | 107 content::MockDownloadItem download_; |
104 content::DownloadItem::Observer* download_observer_; | 108 content::DownloadItem::Observer* download_observer_; |
105 DownloadDangerPrompt* prompt_; | 109 DownloadDangerPrompt* prompt_; |
106 DownloadDangerPrompt::Action expected_action_; | 110 DownloadDangerPrompt::Action expected_action_; |
107 bool did_receive_callback_; | 111 bool did_receive_callback_; |
108 | 112 |
109 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest); | 113 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 download_observer()->OnDownloadUpdated(&download()); | 149 download_observer()->OnDownloadUpdated(&download()); |
146 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); | 150 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); |
147 VerifyExpectations(); | 151 VerifyExpectations(); |
148 | 152 |
149 // If the containing tab is closed, the dialog should be canceled. | 153 // If the containing tab is closed, the dialog should be canceled. |
150 OpenNewTab(); | 154 OpenNewTab(); |
151 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 155 SetUpExpectations(DownloadDangerPrompt::CANCEL); |
152 chrome::CloseTab(browser()); | 156 chrome::CloseTab(browser()); |
153 VerifyExpectations(); | 157 VerifyExpectations(); |
154 } | 158 } |
OLD | NEW |