| 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" | 
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 166     } | 166     } | 
| 167   }; | 167   }; | 
| 168 | 168 | 
| 169   virtual void SetUp() { | 169   virtual void SetUp() { | 
| 170     TestController::GetInstance()->set_result(false); | 170     TestController::GetInstance()->set_result(false); | 
| 171     InProcessBrowserTest::SetUp(); | 171     InProcessBrowserTest::SetUp(); | 
| 172   } | 172   } | 
| 173 | 173 | 
| 174   virtual void TearDown() { | 174   virtual void TearDown() { | 
| 175     if (handler_added_) { | 175     if (handler_added_) { | 
| 176       net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); | 176       BrowserThread::PostTask( | 
| 177       filter->RemoveHostnameHandler(scheme_, host_name_); | 177           BrowserThread::IO, FROM_HERE, | 
|  | 178           base::Bind(Unregister, scheme_, host_name_)); | 
| 178       handler_added_ = false; | 179       handler_added_ = false; | 
| 179       TestController::GetInstance()->set_delegate(NULL); | 180       TestController::GetInstance()->set_delegate(NULL); | 
| 180     } | 181     } | 
| 181     InProcessBrowserTest::TearDown(); | 182     InProcessBrowserTest::TearDown(); | 
| 182   } | 183   } | 
| 183 | 184 | 
| 184   // Normally this is something I would expect could go into SetUp(), | 185   // Normally this is something I would expect could go into SetUp(), | 
| 185   // but there seems to be some timing or ordering related issue with | 186   // but there seems to be some timing or ordering related issue with | 
| 186   // the test harness that made that flaky.  Calling this from the | 187   // the test harness that made that flaky.  Calling this from the | 
| 187   // individual test functions seems to fix that. | 188   // individual test functions seems to fix that. | 
| 188   void AddTestHandlers() { | 189   void AddTestHandlers() { | 
| 189     if (!handler_added_) { | 190     if (!handler_added_) { | 
| 190       net::URLRequestFilter* filter = net::URLRequestFilter::GetInstance(); |  | 
| 191       GURL cloud_print_service_url = | 191       GURL cloud_print_service_url = | 
| 192           CloudPrintURL(browser()->profile()). | 192           CloudPrintURL(browser()->profile()). | 
| 193           GetCloudPrintServiceURL(); | 193           GetCloudPrintServiceURL(); | 
| 194       scheme_ = cloud_print_service_url.scheme(); | 194       scheme_ = cloud_print_service_url.scheme(); | 
| 195       host_name_ = cloud_print_service_url.host(); | 195       host_name_ = cloud_print_service_url.host(); | 
| 196       filter->AddHostnameHandler(scheme_, host_name_, | 196       BrowserThread::PostTask( | 
| 197                                  &PrintDialogCloudTest::Factory); | 197           BrowserThread::IO, FROM_HERE, | 
|  | 198           base::Bind(&PrintDialogCloudTest::Register, this)); | 
| 198       handler_added_ = true; | 199       handler_added_ = true; | 
| 199 | 200 | 
| 200       GURL cloud_print_dialog_url = | 201       GURL cloud_print_dialog_url = | 
| 201           CloudPrintURL(browser()->profile()). | 202           CloudPrintURL(browser()->profile()). | 
| 202           GetCloudPrintServiceDialogURL(); | 203           GetCloudPrintServiceDialogURL(); | 
| 203       TestController::GetInstance()->set_expected_url(cloud_print_dialog_url); | 204       TestController::GetInstance()->set_expected_url(cloud_print_dialog_url); | 
| 204       TestController::GetInstance()->set_delegate(&delegate_); | 205       TestController::GetInstance()->set_delegate(&delegate_); | 
| 205     } | 206     } | 
| 206 | 207 | 
| 207     CreateDialogForTest(); | 208     CreateDialogForTest(); | 
| 208   } | 209   } | 
| 209 | 210 | 
| 210   void CreateDialogForTest() { | 211   void CreateDialogForTest() { | 
| 211     FilePath path_to_pdf = | 212     FilePath path_to_pdf = | 
| 212         test_data_directory_.AppendASCII("printing/cloud_print_uitest.pdf"); | 213         test_data_directory_.AppendASCII("printing/cloud_print_uitest.pdf"); | 
| 213     BrowserThread::PostTask( | 214     BrowserThread::PostTask( | 
| 214         BrowserThread::UI, FROM_HERE, | 215         BrowserThread::UI, FROM_HERE, | 
| 215         base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl, | 216         base::Bind(&internal_cloud_print_helpers::CreateDialogFullImpl, | 
| 216                    browser()->profile(), browser()->window()->GetNativeWindow(), | 217                    browser()->profile(), browser()->window()->GetNativeWindow(), | 
| 217                    path_to_pdf, string16(), string16(), | 218                    path_to_pdf, string16(), string16(), | 
| 218                    std::string("application/pdf"), false)); | 219                    std::string("application/pdf"), false)); | 
| 219   } | 220   } | 
| 220 | 221 | 
|  | 222  private: | 
|  | 223   void Register() { | 
|  | 224     net::URLRequestFilter::GetInstance()->AddHostnameHandler( | 
|  | 225         scheme_, host_name_, &PrintDialogCloudTest::Factory); | 
|  | 226   } | 
|  | 227   static void Unregister(const std::string& scheme, | 
|  | 228                          const std::string& host_name) { | 
|  | 229     net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(scheme, | 
|  | 230                                                                 host_name); | 
|  | 231   } | 
|  | 232 | 
| 221   bool handler_added_; | 233   bool handler_added_; | 
| 222   std::string scheme_; | 234   std::string scheme_; | 
| 223   std::string host_name_; | 235   std::string host_name_; | 
| 224   FilePath test_data_directory_; | 236   FilePath test_data_directory_; | 
| 225   AutoQuitDelegate delegate_; | 237   AutoQuitDelegate delegate_; | 
| 226 }; | 238 }; | 
| 227 | 239 | 
| 228 net::URLRequestJob* PrintDialogCloudTest::Factory( | 240 net::URLRequestJob* PrintDialogCloudTest::Factory( | 
| 229     net::URLRequest* request, | 241     net::URLRequest* request, | 
| 230     net::NetworkDelegate* network_delegate, | 242     net::NetworkDelegate* network_delegate, | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 268   BrowserWindow* window = browser()->window(); | 280   BrowserWindow* window = browser()->window(); | 
| 269   ASSERT_TRUE(window); | 281   ASSERT_TRUE(window); | 
| 270   gfx::NativeWindow native_window = window->GetNativeWindow(); | 282   gfx::NativeWindow native_window = window->GetNativeWindow(); | 
| 271   ASSERT_TRUE(native_window); | 283   ASSERT_TRUE(native_window); | 
| 272   bool key_sent = ui_controls::SendKeyPress(native_window, ui::VKEY_ESCAPE, | 284   bool key_sent = ui_controls::SendKeyPress(native_window, ui::VKEY_ESCAPE, | 
| 273                                             false, false, false, false); | 285                                             false, false, false, false); | 
| 274   EXPECT_TRUE(key_sent); | 286   EXPECT_TRUE(key_sent); | 
| 275   if (key_sent) | 287   if (key_sent) | 
| 276     tab_closed_observer.Wait(); | 288     tab_closed_observer.Wait(); | 
| 277 } | 289 } | 
| OLD | NEW | 
|---|