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