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/file_path.h" | 6 #include "base/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/tab_contents/tab_contents.h" | 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
11 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
12 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
13 #include "content/public/test/mock_download_item.h" | 14 #include "content/public/test/mock_download_item.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 | 17 |
17 using ::testing::_; | 18 using ::testing::_; |
18 using ::testing::ByRef; | 19 using ::testing::ByRef; |
19 using ::testing::Eq; | 20 using ::testing::Eq; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 EXPECT_CALL(download_, GetFileNameToReportUser()).WillRepeatedly(Return( | 77 EXPECT_CALL(download_, GetFileNameToReportUser()).WillRepeatedly(Return( |
77 FilePath(FILE_PATH_LITERAL("evil.exe")))); | 78 FilePath(FILE_PATH_LITERAL("evil.exe")))); |
78 EXPECT_CALL(download_, AddObserver(_)) | 79 EXPECT_CALL(download_, AddObserver(_)) |
79 .WillOnce(SaveArg<0>(&download_observer_)); | 80 .WillOnce(SaveArg<0>(&download_observer_)); |
80 EXPECT_CALL(download_, RemoveObserver(Eq(ByRef(download_observer_)))); | 81 EXPECT_CALL(download_, RemoveObserver(Eq(ByRef(download_observer_)))); |
81 } | 82 } |
82 | 83 |
83 void CreatePrompt() { | 84 void CreatePrompt() { |
84 prompt_ = DownloadDangerPrompt::Create( | 85 prompt_ = DownloadDangerPrompt::Create( |
85 &download_, | 86 &download_, |
86 browser()->GetActiveTabContents(), | 87 chrome::GetActiveTabContents(browser()), |
87 base::Bind(&DownloadDangerPromptTest::PromptCallback, this, | 88 base::Bind(&DownloadDangerPromptTest::PromptCallback, this, |
88 DownloadDangerPrompt::ACCEPT), | 89 DownloadDangerPrompt::ACCEPT), |
89 base::Bind(&DownloadDangerPromptTest::PromptCallback, this, | 90 base::Bind(&DownloadDangerPromptTest::PromptCallback, this, |
90 DownloadDangerPrompt::CANCEL)); | 91 DownloadDangerPrompt::CANCEL)); |
91 ui_test_utils::RunAllPendingInMessageLoop(); | 92 ui_test_utils::RunAllPendingInMessageLoop(); |
92 } | 93 } |
93 | 94 |
94 void PromptCallback(DownloadDangerPrompt::Action action) { | 95 void PromptCallback(DownloadDangerPrompt::Action action) { |
95 EXPECT_FALSE(did_receive_callback_); | 96 EXPECT_FALSE(did_receive_callback_); |
96 EXPECT_EQ(expected_action_, action); | 97 EXPECT_EQ(expected_action_, action); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(false)); | 134 EXPECT_CALL(download(), IsDangerous()).WillOnce(Return(false)); |
134 download_observer()->OnDownloadUpdated(&download()); | 135 download_observer()->OnDownloadUpdated(&download()); |
135 VerifyExpectations(); | 136 VerifyExpectations(); |
136 | 137 |
137 // If the containing tab is closed, the dialog should be canceled. | 138 // If the containing tab is closed, the dialog should be canceled. |
138 OpenNewTab(); | 139 OpenNewTab(); |
139 SetUpExpectations(DownloadDangerPrompt::CANCEL); | 140 SetUpExpectations(DownloadDangerPrompt::CANCEL); |
140 chrome::CloseTab(browser()); | 141 chrome::CloseTab(browser()); |
141 VerifyExpectations(); | 142 VerifyExpectations(); |
142 } | 143 } |
OLD | NEW |