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
3 // found in the LICENSE file.
5 #include "base/files/file_enumerator.h"
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/pdf/pdf_browsertest_base.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/navigation_controller.h"
13 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "third_party/WebKit/public/web/WebInputEvent.h"
19 using content::NavigationController
;
20 using content::WebContents
;
22 // Note: All tests in here require the internal PDF plugin, so they're disabled
23 // in non-official builds. We still compile them though, to prevent bitrot.
27 // Tests basic PDF rendering. This can be broken depending on bad merges with
28 // the vendor, so it's important that we have basic sanity checking.
29 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_LINUX)
30 #define MAYBE_Basic DISABLED_Basic
32 #define MAYBE_Basic DISABLED_Basic
34 IN_PROC_BROWSER_TEST_F(PDFBrowserTest
, MAYBE_Basic
) {
35 ASSERT_NO_FATAL_FAILURE(Load());
36 ASSERT_NO_FATAL_FAILURE(WaitForResponse());
37 // OS X uses CoreText, and FreeType renders slightly different on Linux and
39 #if defined(OS_MACOSX)
40 // The bots render differently than locally, see http://crbug.com/142531.
41 ASSERT_TRUE(VerifySnapshot("pdf_browsertest_mac.png") ||
42 VerifySnapshot("pdf_browsertest_mac2.png"));
43 #elif defined(OS_LINUX)
44 ASSERT_TRUE(VerifySnapshot("pdf_browsertest_linux.png"));
46 ASSERT_TRUE(VerifySnapshot("pdf_browsertest.png"));
50 #if defined(GOOGLE_CHROME_BUILD) && \
51 (defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)))
52 #define MAYBE_Scroll DISABLED_Scroll
54 // TODO(thestig): http://crbug.com/79837, http://crbug.com/332778,
55 // http://crbug.com/446221 Possibly a race between mouse event processing and
56 // JavaScript execution in the renderer. The failure goes away if you Sleep()
58 #define MAYBE_Scroll DISABLED_Scroll
60 // Tests that scrolling works.
61 IN_PROC_BROWSER_TEST_F(PDFBrowserTest
, MAYBE_Scroll
) {
62 ASSERT_NO_FATAL_FAILURE(Load());
64 // We use wheel mouse event since that's the only one we can easily push to
65 // the renderer. There's no way to push a cross-platform keyboard event at
67 blink::WebMouseWheelEvent wheel_event
;
68 wheel_event
.type
= blink::WebInputEvent::MouseWheel
;
69 wheel_event
.deltaY
= -200;
70 wheel_event
.wheelTicksY
= -2;
71 WebContents
* web_contents
=
72 browser()->tab_strip_model()->GetActiveWebContents();
73 web_contents
->GetRenderViewHost()->ForwardWheelEvent(wheel_event
);
74 ASSERT_NO_FATAL_FAILURE(WaitForResponse());
77 ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
78 browser()->tab_strip_model()->GetActiveWebContents(),
79 "window.domAutomationController.send(plugin.pageYOffset())",
81 ASSERT_GT(y_offset
, 0);
84 const int kLoadingNumberOfParts
= 10;
86 // Tests that loading async pdfs works correctly (i.e. document fully loads).
87 // This also loads all documents that used to crash, to ensure we don't have
89 // If it flakes, reopen http://crbug.com/74548.
90 #if defined(GOOGLE_CHROME_BUILD)
91 #define MAYBE_Loading DISABLED_Loading
93 #define MAYBE_Loading DISABLED_Loading
95 IN_PROC_BROWSER_TEST_P(PDFBrowserTest
, MAYBE_Loading
) {
96 ASSERT_TRUE(pdf_test_server()->InitializeAndWaitUntilReady());
98 NavigationController
* controller
=
99 &(browser()->tab_strip_model()->GetActiveWebContents()->GetController());
100 content::NotificationRegistrar registrar
;
102 content::NOTIFICATION_LOAD_STOP
,
103 content::Source
<NavigationController
>(controller
));
104 std::string base_url
= std::string("/");
106 base::FileEnumerator
file_enumerator(
107 ui_test_utils::GetTestFilePath(
108 base::FilePath(FILE_PATH_LITERAL("pdf_private")), base::FilePath()),
110 base::FileEnumerator::FILES
,
111 FILE_PATH_LITERAL("*.pdf"));
112 for (base::FilePath file_path
= file_enumerator
.Next();
114 file_path
= file_enumerator
.Next()) {
115 std::string filename
= file_path
.BaseName().MaybeAsASCII();
116 ASSERT_FALSE(filename
.empty());
118 #if defined(OS_POSIX)
119 if (filename
== "sample.pdf")
120 continue; // Crashes on Mac and Linux. http://crbug.com/63549
123 // Split the test into smaller sub-tests. Each one only loads
125 if (static_cast<int>(base::Hash(filename
) % kLoadingNumberOfParts
) !=
130 LOG(WARNING
) << "PDFBrowserTest.Loading: " << filename
;
132 GURL url
= pdf_test_server()->GetURL(base_url
+ filename
);
133 ui_test_utils::NavigateToURL(browser(), url
);
136 int last_count
= load_stop_notification_count();
137 // We might get extraneous chrome::LOAD_STOP notifications when
138 // doing async loading. This happens when the first loader is cancelled
139 // and before creating a byte-range request loader.
140 bool complete
= false;
141 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(
142 browser()->tab_strip_model()->GetActiveWebContents(),
143 "window.domAutomationController.send(plugin.documentLoadComplete())",
148 // Check if the LOAD_STOP notification could have come while we run a
149 // nested message loop for the JS call.
150 if (last_count
!= load_stop_notification_count())
152 content::WaitForLoadStop(
153 browser()->tab_strip_model()->GetActiveWebContents());
158 INSTANTIATE_TEST_CASE_P(PDFTestFiles
,
160 testing::Range(0, kLoadingNumberOfParts
));
162 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX))
163 #define MAYBE_Action DISABLED_Action
165 // http://crbug.com/315160
166 #define MAYBE_Action DISABLED_Action
168 IN_PROC_BROWSER_TEST_F(PDFBrowserTest
, MAYBE_Action
) {
169 ASSERT_NO_FATAL_FAILURE(Load());
171 ASSERT_TRUE(content::ExecuteScript(
172 browser()->tab_strip_model()->GetActiveWebContents(),
173 "document.getElementsByName('plugin')[0].fitToHeight();"));
175 std::string zoom1
, zoom2
;
176 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
177 browser()->tab_strip_model()->GetActiveWebContents(),
178 "window.domAutomationController.send("
179 " document.getElementsByName('plugin')[0].getZoomLevel().toString())",
182 ASSERT_TRUE(content::ExecuteScript(
183 browser()->tab_strip_model()->GetActiveWebContents(),
184 "document.getElementsByName('plugin')[0].fitToWidth();"));
186 ASSERT_TRUE(content::ExecuteScriptAndExtractString(
187 browser()->tab_strip_model()->GetActiveWebContents(),
188 "window.domAutomationController.send("
189 " document.getElementsByName('plugin')[0].getZoomLevel().toString())",
191 ASSERT_NE(zoom1
, zoom2
);
194 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_LINUX)
195 #define MAYBE_OnLoadAndReload DISABLED_OnLoadAndReload
197 // Flaky as per http://crbug.com/74549.
198 #define MAYBE_OnLoadAndReload DISABLED_OnLoadAndReload
200 IN_PROC_BROWSER_TEST_F(PDFBrowserTest
, MAYBE_OnLoadAndReload
) {
201 ASSERT_TRUE(pdf_test_server()->InitializeAndWaitUntilReady());
203 GURL url
= pdf_test_server()->GetURL("/onload_reload.html");
204 ui_test_utils::NavigateToURL(browser(), url
);
205 WebContents
* contents
= browser()->tab_strip_model()->GetActiveWebContents();
207 content::WindowedNotificationObserver
observer(
208 content::NOTIFICATION_LOAD_STOP
,
209 content::Source
<NavigationController
>(
210 &contents
->GetController()));
211 ASSERT_TRUE(content::ExecuteScript(
212 browser()->tab_strip_model()->GetActiveWebContents(),
216 ASSERT_EQ("success", contents
->GetURL().query());