OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "base/files/file_enumerator.h" | |
6 #include "base/hash.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" | |
18 | |
19 using content::NavigationController; | |
20 using content::WebContents; | |
21 | |
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. | |
24 | |
25 namespace { | |
26 | |
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 | |
31 #else | |
32 #define MAYBE_Basic DISABLED_Basic | |
33 #endif | |
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 | |
38 // Win. | |
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")); | |
45 #else | |
46 ASSERT_TRUE(VerifySnapshot("pdf_browsertest.png")); | |
47 #endif | |
48 } | |
49 | |
50 #if defined(GOOGLE_CHROME_BUILD) && \ | |
51 (defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))) | |
52 #define MAYBE_Scroll DISABLED_Scroll | |
53 #else | |
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() | |
57 // after SwapBuffers. | |
58 #define MAYBE_Scroll DISABLED_Scroll | |
59 #endif | |
60 // Tests that scrolling works. | |
61 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) { | |
62 ASSERT_NO_FATAL_FAILURE(Load()); | |
63 | |
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 | |
66 // the moment. | |
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()); | |
75 | |
76 int y_offset = 0; | |
77 ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
78 browser()->tab_strip_model()->GetActiveWebContents(), | |
79 "window.domAutomationController.send(plugin.pageYOffset())", | |
80 &y_offset)); | |
81 ASSERT_GT(y_offset, 0); | |
82 } | |
83 | |
84 const int kLoadingNumberOfParts = 10; | |
85 | |
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 | |
88 // regressions. | |
89 // If it flakes, reopen http://crbug.com/74548. | |
90 #if defined(GOOGLE_CHROME_BUILD) | |
91 #define MAYBE_Loading DISABLED_Loading | |
92 #else | |
93 #define MAYBE_Loading DISABLED_Loading | |
94 #endif | |
95 IN_PROC_BROWSER_TEST_P(PDFBrowserTest, MAYBE_Loading) { | |
96 ASSERT_TRUE(pdf_test_server()->InitializeAndWaitUntilReady()); | |
97 | |
98 NavigationController* controller = | |
99 &(browser()->tab_strip_model()->GetActiveWebContents()->GetController()); | |
100 content::NotificationRegistrar registrar; | |
101 registrar.Add(this, | |
102 content::NOTIFICATION_LOAD_STOP, | |
103 content::Source<NavigationController>(controller)); | |
104 std::string base_url = std::string("/"); | |
105 | |
106 base::FileEnumerator file_enumerator( | |
107 ui_test_utils::GetTestFilePath( | |
108 base::FilePath(FILE_PATH_LITERAL("pdf_private")), base::FilePath()), | |
109 false, | |
110 base::FileEnumerator::FILES, | |
111 FILE_PATH_LITERAL("*.pdf")); | |
112 for (base::FilePath file_path = file_enumerator.Next(); | |
113 !file_path.empty(); | |
114 file_path = file_enumerator.Next()) { | |
115 std::string filename = file_path.BaseName().MaybeAsASCII(); | |
116 ASSERT_FALSE(filename.empty()); | |
117 | |
118 #if defined(OS_POSIX) | |
119 if (filename == "sample.pdf") | |
120 continue; // Crashes on Mac and Linux. http://crbug.com/63549 | |
121 #endif | |
122 | |
123 // Split the test into smaller sub-tests. Each one only loads | |
124 // every k-th file. | |
125 if (static_cast<int>(base::Hash(filename) % kLoadingNumberOfParts) != | |
126 GetParam()) { | |
127 continue; | |
128 } | |
129 | |
130 LOG(WARNING) << "PDFBrowserTest.Loading: " << filename; | |
131 | |
132 GURL url = pdf_test_server()->GetURL(base_url + filename); | |
133 ui_test_utils::NavigateToURL(browser(), url); | |
134 | |
135 while (true) { | |
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())", | |
144 &complete)); | |
145 if (complete) | |
146 break; | |
147 | |
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()) | |
151 continue; | |
152 content::WaitForLoadStop( | |
153 browser()->tab_strip_model()->GetActiveWebContents()); | |
154 } | |
155 } | |
156 } | |
157 | |
158 INSTANTIATE_TEST_CASE_P(PDFTestFiles, | |
159 PDFBrowserTest, | |
160 testing::Range(0, kLoadingNumberOfParts)); | |
161 | |
162 #if defined(GOOGLE_CHROME_BUILD) && (defined(OS_WIN) || defined(OS_LINUX)) | |
163 #define MAYBE_Action DISABLED_Action | |
164 #else | |
165 // http://crbug.com/315160 | |
166 #define MAYBE_Action DISABLED_Action | |
167 #endif | |
168 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Action) { | |
169 ASSERT_NO_FATAL_FAILURE(Load()); | |
170 | |
171 ASSERT_TRUE(content::ExecuteScript( | |
172 browser()->tab_strip_model()->GetActiveWebContents(), | |
173 "document.getElementsByName('plugin')[0].fitToHeight();")); | |
174 | |
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())", | |
180 &zoom1)); | |
181 | |
182 ASSERT_TRUE(content::ExecuteScript( | |
183 browser()->tab_strip_model()->GetActiveWebContents(), | |
184 "document.getElementsByName('plugin')[0].fitToWidth();")); | |
185 | |
186 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
187 browser()->tab_strip_model()->GetActiveWebContents(), | |
188 "window.domAutomationController.send(" | |
189 " document.getElementsByName('plugin')[0].getZoomLevel().toString())", | |
190 &zoom2)); | |
191 ASSERT_NE(zoom1, zoom2); | |
192 } | |
193 | |
194 #if defined(GOOGLE_CHROME_BUILD) && defined(OS_LINUX) | |
195 #define MAYBE_OnLoadAndReload DISABLED_OnLoadAndReload | |
196 #else | |
197 // Flaky as per http://crbug.com/74549. | |
198 #define MAYBE_OnLoadAndReload DISABLED_OnLoadAndReload | |
199 #endif | |
200 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_OnLoadAndReload) { | |
201 ASSERT_TRUE(pdf_test_server()->InitializeAndWaitUntilReady()); | |
202 | |
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(); | |
206 | |
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(), | |
213 "reloadPDF();")); | |
214 observer.Wait(); | |
215 | |
216 ASSERT_EQ("success", contents->GetURL().query()); | |
217 } | |
218 | |
219 } // namespace | |
OLD | NEW |