| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <fstream> | 6 #include <fstream> |
| 7 #include <iostream> | 7 #include <iostream> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Sets closure for the observer so that it can end the loop. | 123 // Sets closure for the observer so that it can end the loop. |
| 124 void set_quit_closure(const base::Closure &closure) { | 124 void set_quit_closure(const base::Closure &closure) { |
| 125 quit_closure_ = closure; | 125 quit_closure_ = closure; |
| 126 } | 126 } |
| 127 | 127 |
| 128 // Actually stops the message loop so that the test can proceed. | 128 // Actually stops the message loop so that the test can proceed. |
| 129 void EndLoop() { | 129 void EndLoop() { |
| 130 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); | 130 base::MessageLoop::current()->PostTask(FROM_HERE, quit_closure_); |
| 131 } | 131 } |
| 132 | 132 |
| 133 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 133 virtual bool OnMessageReceived(const IPC::Message& message) override { |
| 134 IPC_BEGIN_MESSAGE_MAP(PrintPreviewObserver, message) | 134 IPC_BEGIN_MESSAGE_MAP(PrintPreviewObserver, message) |
| 135 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount, | 135 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount, |
| 136 OnDidGetPreviewPageCount) | 136 OnDidGetPreviewPageCount) |
| 137 IPC_END_MESSAGE_MAP(); | 137 IPC_END_MESSAGE_MAP(); |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Gets the web contents for the print preview dialog so that the UI and | 141 // Gets the web contents for the print preview dialog so that the UI and |
| 142 // other elements can be accessed. | 142 // other elements can be accessed. |
| 143 WebContents* GetDialog() { | 143 WebContents* GetDialog() { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 void HandleFailure(const base::ListValue* /* args */) { | 235 void HandleFailure(const base::ListValue* /* args */) { |
| 236 FAIL() << "Failed to set: " << observer_->GetFailedSetting(); | 236 FAIL() << "Failed to set: " << observer_->GetFailedSetting(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 // Allows this class to listen for the 'UILoadedForTest' and | 239 // Allows this class to listen for the 'UILoadedForTest' and |
| 240 // 'UIFailedLoadingForTest' messages. These messages are sent by the print | 240 // 'UIFailedLoadingForTest' messages. These messages are sent by the print |
| 241 // preview dialog. 'UILoadedForTest' is sent when a setting has been | 241 // preview dialog. 'UILoadedForTest' is sent when a setting has been |
| 242 // successfully set and its effects have been finalized. | 242 // successfully set and its effects have been finalized. |
| 243 // 'UIFailedLoadingForTest' is sent when the setting could not be set. This | 243 // 'UIFailedLoadingForTest' is sent when the setting could not be set. This |
| 244 // causes the browser test to fail. | 244 // causes the browser test to fail. |
| 245 virtual void RegisterMessages() OVERRIDE { | 245 virtual void RegisterMessages() override { |
| 246 web_ui()->RegisterMessageCallback( | 246 web_ui()->RegisterMessageCallback( |
| 247 "UILoadedForTest", | 247 "UILoadedForTest", |
| 248 base::Bind(&UIDoneLoadingMessageHandler::HandleDone, | 248 base::Bind(&UIDoneLoadingMessageHandler::HandleDone, |
| 249 base::Unretained(this))); | 249 base::Unretained(this))); |
| 250 | 250 |
| 251 web_ui()->RegisterMessageCallback( | 251 web_ui()->RegisterMessageCallback( |
| 252 "UIFailedLoadingForTest", | 252 "UIFailedLoadingForTest", |
| 253 base::Bind(&UIDoneLoadingMessageHandler::HandleFailure, | 253 base::Bind(&UIDoneLoadingMessageHandler::HandleFailure, |
| 254 base::Unretained(this))); | 254 base::Unretained(this))); |
| 255 } | 255 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 272 ASSERT_TRUE(ui); | 272 ASSERT_TRUE(ui); |
| 273 ASSERT_TRUE(ui->web_ui()); | 273 ASSERT_TRUE(ui->web_ui()); |
| 274 | 274 |
| 275 // The |ui->web_ui()| owns the message handler. | 275 // The |ui->web_ui()| owns the message handler. |
| 276 ui->web_ui()->AddMessageHandler(new UIDoneLoadingMessageHandler(this)); | 276 ui->web_ui()->AddMessageHandler(new UIDoneLoadingMessageHandler(this)); |
| 277 ui->web_ui()->CallJavascriptFunction("onEnableManipulateSettingsForTest"); | 277 ui->web_ui()->CallJavascriptFunction("onEnableManipulateSettingsForTest"); |
| 278 } | 278 } |
| 279 | 279 |
| 280 virtual void DidCloneToNewWebContents( | 280 virtual void DidCloneToNewWebContents( |
| 281 WebContents* old_web_contents, | 281 WebContents* old_web_contents, |
| 282 WebContents* new_web_contents) OVERRIDE { | 282 WebContents* new_web_contents) override { |
| 283 Observe(new_web_contents); | 283 Observe(new_web_contents); |
| 284 } | 284 } |
| 285 | 285 |
| 286 Browser* browser_; | 286 Browser* browser_; |
| 287 base::Closure quit_closure_; | 287 base::Closure quit_closure_; |
| 288 scoped_ptr<PrintPreviewSettings> settings_; | 288 scoped_ptr<PrintPreviewSettings> settings_; |
| 289 | 289 |
| 290 // State of the observer. The state indicates what message to send | 290 // State of the observer. The state indicates what message to send |
| 291 // next. The state advances whenever the message handler calls | 291 // next. The state advances whenever the message handler calls |
| 292 // ManipulatePreviewSettings() on the observer. | 292 // ManipulatePreviewSettings() on the observer. |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 // waiting for this message and start waiting for the image data. | 694 // waiting for this message and start waiting for the image data. |
| 695 std::cout << "#EOF\n"; | 695 std::cout << "#EOF\n"; |
| 696 std::cout.flush(); | 696 std::cout.flush(); |
| 697 | 697 |
| 698 SendPng(); | 698 SendPng(); |
| 699 Reset(); | 699 Reset(); |
| 700 } | 700 } |
| 701 } | 701 } |
| 702 | 702 |
| 703 } // namespace printing | 703 } // namespace printing |
| OLD | NEW |