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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
7 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 7 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_commands.h" | 9 #include "chrome/browser/ui/browser_commands.h" |
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 : WebContentsObserver(dialog) { | 26 : WebContentsObserver(dialog) { |
27 } | 27 } |
28 virtual ~RequestPrintPreviewObserver() {} | 28 virtual ~RequestPrintPreviewObserver() {} |
29 | 29 |
30 void set_quit_closure(const base::Closure& quit_closure) { | 30 void set_quit_closure(const base::Closure& quit_closure) { |
31 quit_closure_ = quit_closure; | 31 quit_closure_ = quit_closure; |
32 } | 32 } |
33 | 33 |
34 private: | 34 private: |
35 // content::WebContentsObserver implementation. | 35 // content::WebContentsObserver implementation. |
36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 36 virtual bool OnMessageReceived(const IPC::Message& message) override { |
37 IPC_BEGIN_MESSAGE_MAP(RequestPrintPreviewObserver, message) | 37 IPC_BEGIN_MESSAGE_MAP(RequestPrintPreviewObserver, message) |
38 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, | 38 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, |
39 OnRequestPrintPreview) | 39 OnRequestPrintPreview) |
40 IPC_MESSAGE_UNHANDLED(break;) | 40 IPC_MESSAGE_UNHANDLED(break;) |
41 IPC_END_MESSAGE_MAP(); | 41 IPC_END_MESSAGE_MAP(); |
42 return false; // Report not handled so the real handler receives it. | 42 return false; // Report not handled so the real handler receives it. |
43 } | 43 } |
44 | 44 |
45 void OnRequestPrintPreview( | 45 void OnRequestPrintPreview( |
46 const PrintHostMsg_RequestPrintPreview_Params& /* params */) { | 46 const PrintHostMsg_RequestPrintPreview_Params& /* params */) { |
(...skipping 13 matching lines...) Expand all Loading... |
60 virtual ~PrintPreviewDialogClonedObserver() {} | 60 virtual ~PrintPreviewDialogClonedObserver() {} |
61 | 61 |
62 RequestPrintPreviewObserver* request_preview_dialog_observer() { | 62 RequestPrintPreviewObserver* request_preview_dialog_observer() { |
63 return request_preview_dialog_observer_.get(); | 63 return request_preview_dialog_observer_.get(); |
64 } | 64 } |
65 | 65 |
66 private: | 66 private: |
67 // content::WebContentsObserver implementation. | 67 // content::WebContentsObserver implementation. |
68 virtual void DidCloneToNewWebContents( | 68 virtual void DidCloneToNewWebContents( |
69 WebContents* old_web_contents, | 69 WebContents* old_web_contents, |
70 WebContents* new_web_contents) OVERRIDE { | 70 WebContents* new_web_contents) override { |
71 request_preview_dialog_observer_.reset( | 71 request_preview_dialog_observer_.reset( |
72 new RequestPrintPreviewObserver(new_web_contents)); | 72 new RequestPrintPreviewObserver(new_web_contents)); |
73 } | 73 } |
74 | 74 |
75 scoped_ptr<RequestPrintPreviewObserver> request_preview_dialog_observer_; | 75 scoped_ptr<RequestPrintPreviewObserver> request_preview_dialog_observer_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogClonedObserver); | 77 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogClonedObserver); |
78 }; | 78 }; |
79 | 79 |
80 class PrintPreviewDialogDestroyedObserver : public WebContentsObserver { | 80 class PrintPreviewDialogDestroyedObserver : public WebContentsObserver { |
81 public: | 81 public: |
82 explicit PrintPreviewDialogDestroyedObserver(WebContents* dialog) | 82 explicit PrintPreviewDialogDestroyedObserver(WebContents* dialog) |
83 : WebContentsObserver(dialog), | 83 : WebContentsObserver(dialog), |
84 dialog_destroyed_(false) { | 84 dialog_destroyed_(false) { |
85 } | 85 } |
86 virtual ~PrintPreviewDialogDestroyedObserver() {} | 86 virtual ~PrintPreviewDialogDestroyedObserver() {} |
87 | 87 |
88 bool dialog_destroyed() const { return dialog_destroyed_; } | 88 bool dialog_destroyed() const { return dialog_destroyed_; } |
89 | 89 |
90 private: | 90 private: |
91 // content::WebContentsObserver implementation. | 91 // content::WebContentsObserver implementation. |
92 virtual void WebContentsDestroyed() OVERRIDE { | 92 virtual void WebContentsDestroyed() override { |
93 dialog_destroyed_ = true; | 93 dialog_destroyed_ = true; |
94 } | 94 } |
95 | 95 |
96 bool dialog_destroyed_; | 96 bool dialog_destroyed_; |
97 | 97 |
98 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver); | 98 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver); |
99 }; | 99 }; |
100 | 100 |
101 class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest { | 101 class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest { |
102 public: | 102 public: |
(...skipping 11 matching lines...) Expand all Loading... |
114 run_loop.Run(); | 114 run_loop.Run(); |
115 } | 115 } |
116 | 116 |
117 WebContents* GetPrintPreviewDialog() { | 117 WebContents* GetPrintPreviewDialog() { |
118 printing::PrintPreviewDialogController* dialog_controller = | 118 printing::PrintPreviewDialogController* dialog_controller = |
119 printing::PrintPreviewDialogController::GetInstance(); | 119 printing::PrintPreviewDialogController::GetInstance(); |
120 return dialog_controller->GetPrintPreviewForContents(initiator_); | 120 return dialog_controller->GetPrintPreviewForContents(initiator_); |
121 } | 121 } |
122 | 122 |
123 private: | 123 private: |
124 virtual void SetUpOnMainThread() OVERRIDE { | 124 virtual void SetUpOnMainThread() override { |
125 WebContents* first_tab = | 125 WebContents* first_tab = |
126 browser()->tab_strip_model()->GetActiveWebContents(); | 126 browser()->tab_strip_model()->GetActiveWebContents(); |
127 ASSERT_TRUE(first_tab); | 127 ASSERT_TRUE(first_tab); |
128 | 128 |
129 // Open a new tab so |cloned_tab_observer_| can see it first and attach a | 129 // Open a new tab so |cloned_tab_observer_| can see it first and attach a |
130 // RequestPrintPreviewObserver to it before the real | 130 // RequestPrintPreviewObserver to it before the real |
131 // PrintPreviewMessageHandler gets created. Thus enabling | 131 // PrintPreviewMessageHandler gets created. Thus enabling |
132 // RequestPrintPreviewObserver to get messages first for the purposes of | 132 // RequestPrintPreviewObserver to get messages first for the purposes of |
133 // this test. | 133 // this test. |
134 cloned_tab_observer_.reset(new PrintPreviewDialogClonedObserver(first_tab)); | 134 cloned_tab_observer_.reset(new PrintPreviewDialogClonedObserver(first_tab)); |
135 chrome::DuplicateTab(browser()); | 135 chrome::DuplicateTab(browser()); |
136 | 136 |
137 initiator_ = browser()->tab_strip_model()->GetActiveWebContents(); | 137 initiator_ = browser()->tab_strip_model()->GetActiveWebContents(); |
138 ASSERT_TRUE(initiator_); | 138 ASSERT_TRUE(initiator_); |
139 ASSERT_NE(first_tab, initiator_); | 139 ASSERT_NE(first_tab, initiator_); |
140 } | 140 } |
141 | 141 |
142 virtual void TearDownOnMainThread() OVERRIDE { | 142 virtual void TearDownOnMainThread() override { |
143 cloned_tab_observer_.reset(); | 143 cloned_tab_observer_.reset(); |
144 initiator_ = NULL; | 144 initiator_ = NULL; |
145 } | 145 } |
146 | 146 |
147 RequestPrintPreviewObserver* request_preview_dialog_observer() { | 147 RequestPrintPreviewObserver* request_preview_dialog_observer() { |
148 return cloned_tab_observer_->request_preview_dialog_observer(); | 148 return cloned_tab_observer_->request_preview_dialog_observer(); |
149 } | 149 } |
150 | 150 |
151 scoped_ptr<PrintPreviewDialogClonedObserver> cloned_tab_observer_; | 151 scoped_ptr<PrintPreviewDialogClonedObserver> cloned_tab_observer_; |
152 WebContents* initiator_; | 152 WebContents* initiator_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 browser()->tab_strip_model()->GetActiveWebContents()); | 217 browser()->tab_strip_model()->GetActiveWebContents()); |
218 ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed()); | 218 ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed()); |
219 | 219 |
220 // Try printing again. | 220 // Try printing again. |
221 PrintPreview(); | 221 PrintPreview(); |
222 | 222 |
223 // Create a preview dialog for the initiator tab. | 223 // Create a preview dialog for the initiator tab. |
224 WebContents* new_preview_dialog = GetPrintPreviewDialog(); | 224 WebContents* new_preview_dialog = GetPrintPreviewDialog(); |
225 EXPECT_TRUE(new_preview_dialog); | 225 EXPECT_TRUE(new_preview_dialog); |
226 } | 226 } |
OLD | NEW |