Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Side by Side Diff: chrome/browser/download/download_danger_prompt_browsertest.cc

Issue 402293002: Experience sampling instrumentation for dangerous downloads warnings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sampling-api
Patch Set: Add default actions for tests Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/browser_tabstrip.h" 11 #include "chrome/browser/ui/browser_tabstrip.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h" 14 #include "chrome/test/base/ui_test_utils.h"
14 #include "content/public/test/mock_download_item.h" 15 #include "content/public/test/mock_download_item.h"
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "url/gurl.h"
17 19
18 using ::testing::_; 20 using ::testing::_;
19 using ::testing::ByRef; 21 using ::testing::ByRef;
20 using ::testing::Eq; 22 using ::testing::Eq;
21 using ::testing::Return; 23 using ::testing::Return;
24 using ::testing::ReturnRef;
22 using ::testing::SaveArg; 25 using ::testing::SaveArg;
23 26
24 class DownloadDangerPromptTest : public InProcessBrowserTest { 27 class DownloadDangerPromptTest : public InProcessBrowserTest {
25 public: 28 public:
26 DownloadDangerPromptTest() 29 DownloadDangerPromptTest()
27 : prompt_(NULL), 30 : prompt_(NULL),
28 expected_action_(DownloadDangerPrompt::CANCEL), 31 expected_action_(DownloadDangerPrompt::CANCEL),
29 did_receive_callback_(false) { 32 did_receive_callback_(false) {
30 } 33 }
31 34
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 96
94 content::MockDownloadItem download_; 97 content::MockDownloadItem download_;
95 DownloadDangerPrompt* prompt_; 98 DownloadDangerPrompt* prompt_;
96 DownloadDangerPrompt::Action expected_action_; 99 DownloadDangerPrompt::Action expected_action_;
97 bool did_receive_callback_; 100 bool did_receive_callback_;
98 101
99 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest); 102 DISALLOW_COPY_AND_ASSIGN(DownloadDangerPromptTest);
100 }; 103 };
101 104
102 IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, TestAll) { 105 IN_PROC_BROWSER_TEST_F(DownloadDangerPromptTest, TestAll) {
106 // ExperienceSampling: Set default actions for DownloadItem methods we need.
107 ON_CALL(download(), GetURL()).WillByDefault(ReturnRef(GURL::EmptyGURL()));
108 ON_CALL(download(), GetReferrerUrl())
109 .WillByDefault(ReturnRef(GURL::EmptyGURL()));
110 ON_CALL(download(), GetBrowserContext())
111 .WillByDefault(Return(browser()->profile()));
112
103 OpenNewTab(); 113 OpenNewTab();
104 114
105 // Clicking the Accept button should invoke the ACCEPT action. 115 // Clicking the Accept button should invoke the ACCEPT action.
106 SetUpExpectations(DownloadDangerPrompt::ACCEPT); 116 SetUpExpectations(DownloadDangerPrompt::ACCEPT);
107 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); 117 SimulatePromptAction(DownloadDangerPrompt::ACCEPT);
108 VerifyExpectations(); 118 VerifyExpectations();
109 119
110 // Clicking the Cancel button should invoke the CANCEL action. 120 // Clicking the Cancel button should invoke the CANCEL action.
111 SetUpExpectations(DownloadDangerPrompt::CANCEL); 121 SetUpExpectations(DownloadDangerPrompt::CANCEL);
112 SimulatePromptAction(DownloadDangerPrompt::CANCEL); 122 SimulatePromptAction(DownloadDangerPrompt::CANCEL);
(...skipping 22 matching lines...) Expand all
135 download().NotifyObserversDownloadUpdated(); 145 download().NotifyObserversDownloadUpdated();
136 SimulatePromptAction(DownloadDangerPrompt::ACCEPT); 146 SimulatePromptAction(DownloadDangerPrompt::ACCEPT);
137 VerifyExpectations(); 147 VerifyExpectations();
138 148
139 // If the containing tab is closed, the dialog should DISMISS itself. 149 // If the containing tab is closed, the dialog should DISMISS itself.
140 OpenNewTab(); 150 OpenNewTab();
141 SetUpExpectations(DownloadDangerPrompt::DISMISS); 151 SetUpExpectations(DownloadDangerPrompt::DISMISS);
142 chrome::CloseTab(browser()); 152 chrome::CloseTab(browser());
143 VerifyExpectations(); 153 VerifyExpectations();
144 } 154 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698