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 "chrome/browser/printing/print_dialog_cloud.h" | 5 #include "chrome/browser/printing/print_dialog_cloud.h" |
6 #include "chrome/browser/printing/print_dialog_cloud_internal.h" | 6 #include "chrome/browser/printing/print_dialog_cloud_internal.h" |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" | 18 #include "chrome/browser/printing/cloud_print/cloud_print_url.h" |
| 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_list.h" | |
21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 22 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
23 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
25 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
26 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
27 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
28 #include "content/public/browser/notification_types.h" | 28 #include "content/public/browser/notification_types.h" |
29 #include "content/public/browser/render_view_host.h" | 29 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 201 |
202 CreateDialogForTest(); | 202 CreateDialogForTest(); |
203 } | 203 } |
204 | 204 |
205 void CreateDialogForTest() { | 205 void CreateDialogForTest() { |
206 FilePath path_to_pdf = | 206 FilePath path_to_pdf = |
207 test_data_directory_.AppendASCII("printing/cloud_print_uitest.pdf"); | 207 test_data_directory_.AppendASCII("printing/cloud_print_uitest.pdf"); |
208 BrowserThread::PostTask( | 208 BrowserThread::PostTask( |
209 BrowserThread::UI, FROM_HERE, | 209 BrowserThread::UI, FROM_HERE, |
210 base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl, | 210 base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl, |
| 211 browser()->profile(), browser()->window()->GetNativeHandle(), |
211 path_to_pdf, string16(), string16(), | 212 path_to_pdf, string16(), string16(), |
212 std::string("application/pdf"), true, false)); | 213 std::string("application/pdf"), false)); |
213 } | 214 } |
214 | 215 |
215 bool handler_added_; | 216 bool handler_added_; |
216 std::string scheme_; | 217 std::string scheme_; |
217 std::string host_name_; | 218 std::string host_name_; |
218 FilePath test_data_directory_; | 219 FilePath test_data_directory_; |
219 AutoQuitDelegate delegate_; | 220 AutoQuitDelegate delegate_; |
220 }; | 221 }; |
221 | 222 |
222 net::URLRequestJob* PrintDialogCloudTest::Factory(net::URLRequest* request, | 223 net::URLRequestJob* PrintDialogCloudTest::Factory(net::URLRequest* request, |
223 const std::string& scheme) { | 224 const std::string& scheme) { |
224 if (request && | 225 if (request && |
225 (request->url() == TestController::GetInstance()->expected_url())) { | 226 (request->url() == TestController::GetInstance()->expected_url())) { |
226 if (TestController::GetInstance()->use_delegate()) | 227 if (TestController::GetInstance()->use_delegate()) |
227 request->set_delegate(TestController::GetInstance()->delegate()); | 228 request->set_delegate(TestController::GetInstance()->delegate()); |
228 TestController::GetInstance()->set_result(true); | 229 TestController::GetInstance()->set_result(true); |
229 return new SimpleTestJob(request); | 230 return new SimpleTestJob(request); |
230 } | 231 } |
231 return new net::URLRequestTestJob(request, | 232 return new net::URLRequestTestJob(request, |
232 net::URLRequestTestJob::test_headers(), | 233 net::URLRequestTestJob::test_headers(), |
233 "", true); | 234 "", true); |
234 } | 235 } |
235 | 236 |
236 #if defined(OS_WIN) | 237 #if defined(OS_WIN) |
237 #define MAYBE_HandlersRegistered FLAKY_HandlersRegistered | 238 #define MAYBE_HandlersRegistered FLAKY_HandlersRegistered |
238 #else | 239 #else |
239 #define MAYBE_HandlersRegistered HandlersRegistered | 240 #define MAYBE_HandlersRegistered HandlersRegistered |
240 #endif | 241 #endif |
241 IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, MAYBE_HandlersRegistered) { | 242 IN_PROC_BROWSER_TEST_F(PrintDialogCloudTest, MAYBE_HandlersRegistered) { |
242 BrowserList::SetLastActive(browser()); | |
243 ASSERT_TRUE(BrowserList::GetLastActive()); | |
244 | |
245 AddTestHandlers(); | 243 AddTestHandlers(); |
246 | 244 |
247 TestController::GetInstance()->set_use_delegate(true); | 245 TestController::GetInstance()->set_use_delegate(true); |
248 | 246 |
249 ui_test_utils::RunMessageLoop(); | 247 ui_test_utils::RunMessageLoop(); |
250 | 248 |
251 ASSERT_TRUE(TestController::GetInstance()->result()); | 249 ASSERT_TRUE(TestController::GetInstance()->result()); |
252 | 250 |
253 // Close the dialog before finishing the test. | 251 // Close the dialog before finishing the test. |
254 ui_test_utils::WindowedNotificationObserver tab_closed_observer( | 252 ui_test_utils::WindowedNotificationObserver tab_closed_observer( |
255 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 253 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
256 content::NotificationService::AllSources()); | 254 content::NotificationService::AllSources()); |
257 | 255 |
258 // Can't use ui_test_utils::SendKeyPressSync or | 256 // Can't use ui_test_utils::SendKeyPressSync or |
259 // ui_test_utils::SendKeyPressAndWait due to a race condition with closing | 257 // ui_test_utils::SendKeyPressAndWait due to a race condition with closing |
260 // the window. See http://crbug.com/111269 | 258 // the window. See http://crbug.com/111269 |
261 BrowserWindow* window = browser()->window(); | 259 BrowserWindow* window = browser()->window(); |
262 ASSERT_TRUE(window); | 260 ASSERT_TRUE(window); |
263 gfx::NativeWindow native_window = window->GetNativeHandle(); | 261 gfx::NativeWindow native_window = window->GetNativeHandle(); |
264 ASSERT_TRUE(native_window); | 262 ASSERT_TRUE(native_window); |
265 bool key_sent = ui_controls::SendKeyPress(native_window, ui::VKEY_ESCAPE, | 263 bool key_sent = ui_controls::SendKeyPress(native_window, ui::VKEY_ESCAPE, |
266 false, false, false, false); | 264 false, false, false, false); |
267 EXPECT_TRUE(key_sent); | 265 EXPECT_TRUE(key_sent); |
268 if (key_sent) | 266 if (key_sent) |
269 tab_closed_observer.Wait(); | 267 tab_closed_observer.Wait(); |
270 } | 268 } |
OLD | NEW |