Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: chrome/browser/printing/print_preview_dialog_controller_browsertest.cc

Issue 1022673002: Enable PDF plugin for iframes within the print preview dialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: better comments Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bind_helpers.h"
5 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
6 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
10 #include "chrome/browser/plugins/plugin_prefs.h"
7 #include "chrome/browser/printing/print_preview_dialog_controller.h" 11 #include "chrome/browser/printing/print_preview_dialog_controller.h"
8 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_commands.h" 13 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/common/chrome_content_client.h"
11 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
12 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
14 #include "components/printing/common/print_messages.h" 19 #include "components/printing/common/print_messages.h"
20 #include "content/public/browser/plugin_service.h"
21 #include "content/public/browser/render_frame_host.h"
22 #include "content/public/browser/render_process_host.h"
15 #include "content/public/browser/web_contents_observer.h" 23 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/test/browser_test_utils.h" 24 #include "content/public/test/browser_test_utils.h"
17 #include "ipc/ipc_message_macros.h" 25 #include "ipc/ipc_message_macros.h"
18 #include "url/gurl.h" 26 #include "url/gurl.h"
19 27
20 using content::WebContents; 28 using content::WebContents;
21 using content::WebContentsObserver; 29 using content::WebContentsObserver;
22 30
31 namespace {
32
23 class RequestPrintPreviewObserver : public WebContentsObserver { 33 class RequestPrintPreviewObserver : public WebContentsObserver {
24 public: 34 public:
25 explicit RequestPrintPreviewObserver(WebContents* dialog) 35 explicit RequestPrintPreviewObserver(WebContents* dialog)
26 : WebContentsObserver(dialog) { 36 : WebContentsObserver(dialog) {
27 } 37 }
28 ~RequestPrintPreviewObserver() override {} 38 ~RequestPrintPreviewObserver() override {}
29 39
30 void set_quit_closure(const base::Closure& quit_closure) { 40 void set_quit_closure(const base::Closure& quit_closure) {
31 quit_closure_ = quit_closure; 41 quit_closure_ = quit_closure;
32 } 42 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 98
89 private: 99 private:
90 // content::WebContentsObserver implementation. 100 // content::WebContentsObserver implementation.
91 void WebContentsDestroyed() override { dialog_destroyed_ = true; } 101 void WebContentsDestroyed() override { dialog_destroyed_ = true; }
92 102
93 bool dialog_destroyed_; 103 bool dialog_destroyed_;
94 104
95 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver); 105 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogDestroyedObserver);
96 }; 106 };
97 107
108 void PluginsLoadedCallback(
109 const base::Closure& quit_closure,
110 const std::vector<content::WebPluginInfo>& /* info */) {
111 quit_closure.Run();
112 }
113
114 bool GetPdfPluginInfo(content::WebPluginInfo* info) {
115 base::FilePath pdf_plugin_path = base::FilePath::FromUTF8Unsafe(
116 ChromeContentClient::kPDFPluginPath);
117 return content::PluginService::GetInstance()->GetPluginInfoByPath(
118 pdf_plugin_path, info);
119 }
120
121 const char kDummyPrintUrl[] = "chrome://print/dummy.pdf";
122
123 void CountFrames(int* frame_count,
124 content::RenderFrameHost* frame) {
125 ++(*frame_count);
126 }
127
128 void CheckPdfPluginForRenderFrame(content::RenderFrameHost* frame) {
129 content::WebPluginInfo pdf_plugin_info;
130 ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info));
131
132 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance();
133 EXPECT_TRUE(filter->IsPluginAvailable(
134 frame->GetProcess()->GetID(),
135 frame->GetRoutingID(),
136 nullptr,
137 GURL(kDummyPrintUrl),
138 GURL(),
139 &pdf_plugin_info));
140 }
141
142 } // namespace
143
98 class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest { 144 class PrintPreviewDialogControllerBrowserTest : public InProcessBrowserTest {
99 public: 145 public:
100 PrintPreviewDialogControllerBrowserTest() : initiator_(NULL) {} 146 PrintPreviewDialogControllerBrowserTest() : initiator_(NULL) {}
101 ~PrintPreviewDialogControllerBrowserTest() override {} 147 ~PrintPreviewDialogControllerBrowserTest() override {}
102 148
103 WebContents* initiator() { 149 WebContents* initiator() {
104 return initiator_; 150 return initiator_;
105 } 151 }
106 152
107 void PrintPreview() { 153 void PrintPreview() {
(...skipping 19 matching lines...) Expand all
127 // RequestPrintPreviewObserver to it before the real 173 // RequestPrintPreviewObserver to it before the real
128 // PrintPreviewMessageHandler gets created. Thus enabling 174 // PrintPreviewMessageHandler gets created. Thus enabling
129 // RequestPrintPreviewObserver to get messages first for the purposes of 175 // RequestPrintPreviewObserver to get messages first for the purposes of
130 // this test. 176 // this test.
131 cloned_tab_observer_.reset(new PrintPreviewDialogClonedObserver(first_tab)); 177 cloned_tab_observer_.reset(new PrintPreviewDialogClonedObserver(first_tab));
132 chrome::DuplicateTab(browser()); 178 chrome::DuplicateTab(browser());
133 179
134 initiator_ = browser()->tab_strip_model()->GetActiveWebContents(); 180 initiator_ = browser()->tab_strip_model()->GetActiveWebContents();
135 ASSERT_TRUE(initiator_); 181 ASSERT_TRUE(initiator_);
136 ASSERT_NE(first_tab, initiator_); 182 ASSERT_NE(first_tab, initiator_);
183
184 content::PluginService::GetInstance()->Init();
185 content::PluginService::GetInstance()->DisablePluginsDiscoveryForTesting();
137 } 186 }
138 187
139 void TearDownOnMainThread() override { 188 void TearDownOnMainThread() override {
140 cloned_tab_observer_.reset(); 189 cloned_tab_observer_.reset();
141 initiator_ = NULL; 190 initiator_ = NULL;
142 } 191 }
143 192
144 RequestPrintPreviewObserver* request_preview_dialog_observer() { 193 RequestPrintPreviewObserver* request_preview_dialog_observer() {
145 return cloned_tab_observer_->request_preview_dialog_observer(); 194 return cloned_tab_observer_->request_preview_dialog_observer();
146 } 195 }
147 196
148 scoped_ptr<PrintPreviewDialogClonedObserver> cloned_tab_observer_; 197 scoped_ptr<PrintPreviewDialogClonedObserver> cloned_tab_observer_;
149 WebContents* initiator_; 198 WebContents* initiator_;
150 199
151 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogControllerBrowserTest); 200 DISALLOW_COPY_AND_ASSIGN(PrintPreviewDialogControllerBrowserTest);
152 }; 201 };
153 202
154 // Test to verify that when a initiator navigates, we can create a new preview 203 // Test to verify that when a initiator navigates, we can create a new preview
155 // dialog for the new tab contents. 204 // dialog for the new tab contents.
156 // http://crbug.com/377337 205 // http://crbug.com/377337
157 #if defined(OS_WIN) 206 #if defined(OS_WIN)
158 #define MAYBE_NavigateFromInitiatorTab DISABLED_NavigateFromInitiatorTab 207 #define MAYBE_NavigateFromInitiatorTab DISABLED_NavigateFromInitiatorTab
159 #else 208 #else
160 #define MAYBE_NavigateFromInitiatorTab NavigateFromInitiatorTab 209 #define MAYBE_NavigateFromInitiatorTab NavigateFromInitiatorTab
161 #endif 210 #endif
162 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest, 211 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
163 MAYBE_NavigateFromInitiatorTab) { 212 MAYBE_NavigateFromInitiatorTab) {
164 // print for the first time. 213 // Print for the first time.
165 PrintPreview(); 214 PrintPreview();
166 215
167 // Get the preview dialog for the initiator tab. 216 // Get the preview dialog for the initiator tab.
168 WebContents* preview_dialog = GetPrintPreviewDialog(); 217 WebContents* preview_dialog = GetPrintPreviewDialog();
169 218
170 // Check a new print preview dialog got created. 219 // Check a new print preview dialog got created.
171 ASSERT_TRUE(preview_dialog); 220 ASSERT_TRUE(preview_dialog);
172 ASSERT_NE(initiator(), preview_dialog); 221 ASSERT_NE(initiator(), preview_dialog);
173 222
174 // Navigate in the initiator tab. Make sure navigating destroys the print 223 // Navigate in the initiator tab. Make sure navigating destroys the print
(...skipping 15 matching lines...) Expand all
190 // Test to verify that after reloading the initiator, it creates a new print 239 // Test to verify that after reloading the initiator, it creates a new print
191 // preview dialog. 240 // preview dialog.
192 // http://crbug.com/377337 241 // http://crbug.com/377337
193 #if defined(OS_WIN) 242 #if defined(OS_WIN)
194 #define MAYBE_ReloadInitiatorTab DISABLED_ReloadInitiatorTab 243 #define MAYBE_ReloadInitiatorTab DISABLED_ReloadInitiatorTab
195 #else 244 #else
196 #define MAYBE_ReloadInitiatorTab ReloadInitiatorTab 245 #define MAYBE_ReloadInitiatorTab ReloadInitiatorTab
197 #endif 246 #endif
198 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest, 247 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
199 MAYBE_ReloadInitiatorTab) { 248 MAYBE_ReloadInitiatorTab) {
200 // print for the first time. 249 // Print for the first time.
201 PrintPreview(); 250 PrintPreview();
202 251
203 WebContents* preview_dialog = GetPrintPreviewDialog(); 252 WebContents* preview_dialog = GetPrintPreviewDialog();
204 253
205 // Check a new print preview dialog got created. 254 // Check a new print preview dialog got created.
206 ASSERT_TRUE(preview_dialog); 255 ASSERT_TRUE(preview_dialog);
207 ASSERT_NE(initiator(), preview_dialog); 256 ASSERT_NE(initiator(), preview_dialog);
208 257
209 // Reload the initiator. Make sure reloading destroys the print preview 258 // Reload the initiator. Make sure reloading destroys the print preview
210 // dialog. 259 // dialog.
211 PrintPreviewDialogDestroyedObserver dialog_destroyed_observer(preview_dialog); 260 PrintPreviewDialogDestroyedObserver dialog_destroyed_observer(preview_dialog);
212 chrome::Reload(browser(), CURRENT_TAB); 261 chrome::Reload(browser(), CURRENT_TAB);
213 content::WaitForLoadStop( 262 content::WaitForLoadStop(
214 browser()->tab_strip_model()->GetActiveWebContents()); 263 browser()->tab_strip_model()->GetActiveWebContents());
215 ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed()); 264 ASSERT_TRUE(dialog_destroyed_observer.dialog_destroyed());
216 265
217 // Try printing again. 266 // Try printing again.
218 PrintPreview(); 267 PrintPreview();
219 268
220 // Create a preview dialog for the initiator tab. 269 // Create a preview dialog for the initiator tab.
221 WebContents* new_preview_dialog = GetPrintPreviewDialog(); 270 WebContents* new_preview_dialog = GetPrintPreviewDialog();
222 EXPECT_TRUE(new_preview_dialog); 271 EXPECT_TRUE(new_preview_dialog);
223 } 272 }
273
274 // Test to verify that after print preview works even when the PDF plugin is
275 // disabled for webpages.
276 IN_PROC_BROWSER_TEST_F(PrintPreviewDialogControllerBrowserTest,
277 PdfPluginDisabled) {
278 // Make sure plugins are loaded.
279 {
280 base::RunLoop run_loop;
281 content::PluginService::GetInstance()->GetPlugins(
282 base::Bind(&PluginsLoadedCallback, run_loop.QuitClosure()));
283 run_loop.Run();
284 }
285 // Get the PDF plugin info.
286 content::WebPluginInfo pdf_plugin_info;
287 ASSERT_TRUE(GetPdfPluginInfo(&pdf_plugin_info));
288
289 // Disable the PDF plugin.
290 PluginPrefs::GetForProfile(browser()->profile())->EnablePluginGroup(
291 false, base::ASCIIToUTF16(ChromeContentClient::kPDFPluginName));
292
293 // Make sure it is actually disabled for webpages.
294 ChromePluginServiceFilter* filter = ChromePluginServiceFilter::GetInstance();
295 content::WebPluginInfo dummy_pdf_plugin_info = pdf_plugin_info;
296 EXPECT_FALSE(filter->IsPluginAvailable(
297 initiator()->GetRenderProcessHost()->GetID(),
298 initiator()->GetMainFrame()->GetRoutingID(),
299 nullptr,
300 GURL("http://google.com"),
301 GURL(),
302 &dummy_pdf_plugin_info));
303
304 PrintPreview();
305
306 // Check a new print preview dialog got created.
307 WebContents* preview_dialog = GetPrintPreviewDialog();
308 ASSERT_TRUE(preview_dialog);
309 ASSERT_NE(initiator(), preview_dialog);
310
311 // Wait until the <iframe> in the print preview renderer has loaded.
312 // |frame_count| should be 2. The other frame is the main frame.
313 const int kExpectedFrameCount = 2;
314 int frame_count;
315 do {
316 base::RunLoop run_loop;
317 base::MessageLoop::current()->PostDelayedTask(
318 FROM_HERE, run_loop.QuitClosure(), base::TimeDelta::FromSeconds(1));
319 run_loop.Run();
320
321 frame_count = 0;
322 preview_dialog->ForEachFrame(
323 base::Bind(&CountFrames, base::Unretained(&frame_count)));
324 } while (frame_count < kExpectedFrameCount);
325 ASSERT_EQ(kExpectedFrameCount, frame_count);
326
327 // Make sure all the frames in the dialog has access to the PDF plugin.
328 preview_dialog->ForEachFrame(base::Bind(&CheckPdfPluginForRenderFrame));
329 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_dialog_controller.cc ('k') | chrome/browser/printing/print_view_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698