Chromium Code Reviews| 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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 class AutoQuitDelegate : public net::TestDelegate { | 159 class AutoQuitDelegate : public net::TestDelegate { |
| 160 public: | 160 public: |
| 161 AutoQuitDelegate() {} | 161 AutoQuitDelegate() {} |
| 162 | 162 |
| 163 virtual void OnResponseCompleted(net::URLRequest* request) { | 163 virtual void OnResponseCompleted(net::URLRequest* request) { |
| 164 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 164 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 165 MessageLoop::QuitClosure()); | 165 MessageLoop::QuitClosure()); |
| 166 } | 166 } |
| 167 }; | 167 }; |
| 168 | 168 |
| 169 virtual void SetUp() { | 169 virtual void SetUp() { |
|
mmenke
2012/12/18 20:32:15
nit: While you're here, these two should be OVERR
| |
| 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(Register, scheme_, host_name_)); | |
| 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 static void Register(const std::string& scheme, | |
|
mmenke
2012/12/18 20:32:15
Think these names are a little too vague. Just Re
| |
| 224 const std::string& host_name) { | |
| 225 net::URLRequestFilter::GetInstance()->AddHostnameHandler( | |
| 226 scheme, host_name, &PrintDialogCloudTest::Factory); | |
| 227 } | |
| 228 static void Unregister(const std::string& scheme, | |
| 229 const std::string& host_name) { | |
| 230 net::URLRequestFilter::GetInstance()->RemoveHostnameHandler(scheme, | |
| 231 host_name); | |
| 232 } | |
| 233 | |
| 221 bool handler_added_; | 234 bool handler_added_; |
| 222 std::string scheme_; | 235 std::string scheme_; |
| 223 std::string host_name_; | 236 std::string host_name_; |
| 224 FilePath test_data_directory_; | 237 FilePath test_data_directory_; |
| 225 AutoQuitDelegate delegate_; | 238 AutoQuitDelegate delegate_; |
| 226 }; | 239 }; |
| 227 | 240 |
| 228 net::URLRequestJob* PrintDialogCloudTest::Factory( | 241 net::URLRequestJob* PrintDialogCloudTest::Factory( |
| 229 net::URLRequest* request, | 242 net::URLRequest* request, |
| 230 net::NetworkDelegate* network_delegate, | 243 net::NetworkDelegate* network_delegate, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 BrowserWindow* window = browser()->window(); | 281 BrowserWindow* window = browser()->window(); |
| 269 ASSERT_TRUE(window); | 282 ASSERT_TRUE(window); |
| 270 gfx::NativeWindow native_window = window->GetNativeWindow(); | 283 gfx::NativeWindow native_window = window->GetNativeWindow(); |
| 271 ASSERT_TRUE(native_window); | 284 ASSERT_TRUE(native_window); |
| 272 bool key_sent = ui_controls::SendKeyPress(native_window, ui::VKEY_ESCAPE, | 285 bool key_sent = ui_controls::SendKeyPress(native_window, ui::VKEY_ESCAPE, |
| 273 false, false, false, false); | 286 false, false, false, false); |
| 274 EXPECT_TRUE(key_sent); | 287 EXPECT_TRUE(key_sent); |
| 275 if (key_sent) | 288 if (key_sent) |
| 276 tab_closed_observer.Wait(); | 289 tab_closed_observer.Wait(); |
| 277 } | 290 } |
| OLD | NEW |