OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/clipboard/clipboard.h" | 5 #include "app/clipboard/clipboard.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/browser_window.h" | 12 #include "chrome/browser/browser_window.h" |
13 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/window_sizer.h" | 16 #include "chrome/browser/window_sizer.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/notification_observer.h" | 19 #include "chrome/common/notification_observer.h" |
20 #include "chrome/common/notification_type.h" | 20 #include "chrome/common/notification_type.h" |
21 #include "chrome/test/in_process_browser_test.h" | 21 #include "chrome/test/in_process_browser_test.h" |
22 #include "chrome/test/ui_test_utils.h" | 22 #include "chrome/test/ui_test_utils.h" |
23 #include "gfx/codec/png_codec.h" | 23 #include "gfx/codec/png_codec.h" |
24 #include "net/test/test_server.h" | |
24 | 25 |
25 extern base::hash_map<std::string, int> g_test_timeout_overrides; | 26 extern base::hash_map<std::string, int> g_test_timeout_overrides; |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // Include things like browser frame and scrollbar and make sure we're bigger | 30 // Include things like browser frame and scrollbar and make sure we're bigger |
30 // than the test pdf document. | 31 // than the test pdf document. |
31 static const int kBrowserWidth = 1000; | 32 static const int kBrowserWidth = 1000; |
32 static const int kBrowserHeight = 600; | 33 static const int kBrowserHeight = 600; |
33 static const int kLoadingTestTimeoutMs = 60000; | 34 static const int kLoadingTestTimeoutMs = 60000; |
(...skipping 11 matching lines...) Expand all Loading... | |
45 IncreaseLoadingTimeout g_increase_loading_timeout; | 46 IncreaseLoadingTimeout g_increase_loading_timeout; |
46 | 47 |
47 class PDFBrowserTest : public InProcessBrowserTest, | 48 class PDFBrowserTest : public InProcessBrowserTest, |
48 public NotificationObserver { | 49 public NotificationObserver { |
49 public: | 50 public: |
50 PDFBrowserTest() | 51 PDFBrowserTest() |
51 : snapshot_different_(true), | 52 : snapshot_different_(true), |
52 next_dummy_search_value_(0), | 53 next_dummy_search_value_(0), |
53 load_stop_notification_count_(0) { | 54 load_stop_notification_count_(0) { |
54 EnableDOMAutomation(); | 55 EnableDOMAutomation(); |
56 | |
57 pdf_test_server_.reset(new net::TestServer( | |
58 net::TestServer::TYPE_HTTP, | |
59 FilePath(FILE_PATH_LITERAL("pdf/test")))); | |
chase
2010/11/20 02:41:31
Can GetPDFTestDir() be reused here too or does the
| |
55 } | 60 } |
56 | 61 |
57 protected: | 62 protected: |
63 net::TestServer* pdf_test_server() { return pdf_test_server_.get(); } | |
64 | |
58 int load_stop_notification_count() const { | 65 int load_stop_notification_count() const { |
59 return load_stop_notification_count_; | 66 return load_stop_notification_count_; |
60 } | 67 } |
61 | 68 |
62 virtual void SetUp() { | |
63 FilePath pdf_path; | |
64 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | |
65 InProcessBrowserTest::SetUp(); | |
66 } | |
67 | |
68 FilePath GetPDFTestDir() { | 69 FilePath GetPDFTestDir() { |
69 return FilePath(FilePath::kCurrentDirectory).AppendASCII("plugin"). | 70 return FilePath(FilePath::kCurrentDirectory).AppendASCII(".."). |
70 AppendASCII("pdf"); | 71 AppendASCII("..").AppendASCII("..").AppendASCII("pdf"). |
72 AppendASCII("test"); | |
71 } | 73 } |
72 | 74 |
73 void Load() { | 75 void Load() { |
74 GURL url(ui_test_utils::GetTestUrl( | 76 GURL url(ui_test_utils::GetTestUrl( |
75 GetPDFTestDir(), | 77 GetPDFTestDir(), |
76 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); | 78 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); |
77 ui_test_utils::NavigateToURL(browser(), url); | 79 ui_test_utils::NavigateToURL(browser(), url); |
78 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); | 80 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); |
79 | 81 |
80 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info( | 82 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info( |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 // True if the snapshot differed from the expected value. | 199 // True if the snapshot differed from the expected value. |
198 bool snapshot_different_; | 200 bool snapshot_different_; |
199 // Internal variable used to synchronize to the renderer. | 201 // Internal variable used to synchronize to the renderer. |
200 int next_dummy_search_value_; | 202 int next_dummy_search_value_; |
201 // The filename of the bitmap to compare the snapshot to. | 203 // The filename of the bitmap to compare the snapshot to. |
202 std::string expected_filename_; | 204 std::string expected_filename_; |
203 // If the snapshot is different, holds the location where it's saved. | 205 // If the snapshot is different, holds the location where it's saved. |
204 FilePath snapshot_filename_; | 206 FilePath snapshot_filename_; |
205 // How many times we've seen NotificationType::LOAD_STOP. | 207 // How many times we've seen NotificationType::LOAD_STOP. |
206 int load_stop_notification_count_; | 208 int load_stop_notification_count_; |
209 | |
210 scoped_ptr<net::TestServer> pdf_test_server_; | |
chase
2010/11/20 02:41:31
Would be good to have a comment here describing wh
| |
207 }; | 211 }; |
208 | 212 |
209 #if defined(OS_MACOSX) | 213 #if defined(OS_MACOSX) |
210 // See http://crbug.com/63223 | 214 // See http://crbug.com/63223 |
211 #define MAYBE_Basic FLAKY_Basic | 215 #define MAYBE_Basic FLAKY_Basic |
212 #else | 216 #else |
213 #define MAYBE_Basic Basic | 217 #define MAYBE_Basic Basic |
214 #endif | 218 #endif |
215 | 219 |
216 // Tests basic PDF rendering. This can be broken depending on bad merges with | 220 // Tests basic PDF rendering. This can be broken depending on bad merges with |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 | 278 |
275 std::string text; | 279 std::string text; |
276 clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &text); | 280 clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &text); |
277 ASSERT_EQ("adipiscing", text); | 281 ASSERT_EQ("adipiscing", text); |
278 } | 282 } |
279 | 283 |
280 // Tests that loading async pdfs works correctly (i.e. document fully loads). | 284 // Tests that loading async pdfs works correctly (i.e. document fully loads). |
281 // This also loads all documents that used to crash, to ensure we don't have | 285 // This also loads all documents that used to crash, to ensure we don't have |
282 // regressions. | 286 // regressions. |
283 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, Loading) { | 287 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, Loading) { |
284 ASSERT_TRUE(test_server()->Start()); | 288 ASSERT_TRUE(pdf_test_server()->Start()); |
285 | 289 |
286 NavigationController* controller = | 290 NavigationController* controller = |
287 &(browser()->GetSelectedTabContents()->controller()); | 291 &(browser()->GetSelectedTabContents()->controller()); |
288 NotificationRegistrar registrar; | 292 NotificationRegistrar registrar; |
289 registrar.Add(this, | 293 registrar.Add(this, |
290 NotificationType::LOAD_STOP, | 294 NotificationType::LOAD_STOP, |
291 Source<NavigationController>(controller)); | 295 Source<NavigationController>(controller)); |
292 std::string base_url = std::string("files/plugin/pdf/"); | 296 std::string base_url = std::string("files/"); |
293 | 297 |
294 file_util::FileEnumerator file_enumerator( | 298 file_util::FileEnumerator file_enumerator( |
295 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), | 299 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), |
296 false, | 300 false, |
297 file_util::FileEnumerator::FILES, | 301 file_util::FileEnumerator::FILES, |
298 FILE_PATH_LITERAL("*.pdf")); | 302 FILE_PATH_LITERAL("*.pdf")); |
299 for (FilePath file_path = file_enumerator.Next(); | 303 for (FilePath file_path = file_enumerator.Next(); |
300 !file_path.empty(); | 304 !file_path.empty(); |
301 file_path = file_enumerator.Next()) { | 305 file_path = file_enumerator.Next()) { |
302 std::string filename = WideToASCII(file_path.BaseName().ToWStringHack()); | 306 std::string filename = WideToASCII(file_path.BaseName().ToWStringHack()); |
303 | 307 |
304 #if defined(OS_MACOSX) || defined(OS_LINUX) | 308 #if defined(OS_MACOSX) || defined(OS_LINUX) |
305 if (filename == "sample.pdf") | 309 if (filename == "sample.pdf") |
306 continue; // Crashes on Mac and Linux. http://crbug.com/63549 | 310 continue; // Crashes on Mac and Linux. http://crbug.com/63549 |
307 #endif | 311 #endif |
308 | 312 |
309 LOG(WARNING) << "PDFBrowserTest.Loading: " << filename; | 313 LOG(WARNING) << "PDFBrowserTest.Loading: " << filename; |
310 | 314 |
311 GURL url = test_server()->GetURL(base_url + filename); | 315 GURL url = pdf_test_server()->GetURL(base_url + filename); |
312 ui_test_utils::NavigateToURL(browser(), url); | 316 ui_test_utils::NavigateToURL(browser(), url); |
313 | 317 |
314 while (true) { | 318 while (true) { |
315 int last_count = load_stop_notification_count(); | 319 int last_count = load_stop_notification_count(); |
316 // We might get extraneous NotificationType::LOAD_STOP notifications when | 320 // We might get extraneous NotificationType::LOAD_STOP notifications when |
317 // doing async loading. This happens when the first loader is cancelled | 321 // doing async loading. This happens when the first loader is cancelled |
318 // and before creating a byte-range request loader. | 322 // and before creating a byte-range request loader. |
319 bool complete = false; | 323 bool complete = false; |
320 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 324 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
321 browser()->GetSelectedTabContents()->render_view_host(), | 325 browser()->GetSelectedTabContents()->render_view_host(), |
322 std::wstring(), | 326 std::wstring(), |
323 L"window.domAutomationController.send(plugin.documentLoadComplete())", | 327 L"window.domAutomationController.send(plugin.documentLoadComplete())", |
324 &complete)); | 328 &complete)); |
325 if (complete) | 329 if (complete) |
326 break; | 330 break; |
327 | 331 |
328 // Check if the LOAD_STOP notification could have come while we run a | 332 // Check if the LOAD_STOP notification could have come while we run a |
329 // nested message loop for the JS call. | 333 // nested message loop for the JS call. |
330 if (last_count != load_stop_notification_count()) | 334 if (last_count != load_stop_notification_count()) |
331 continue; | 335 continue; |
332 ui_test_utils::WaitForLoadStop(controller); | 336 ui_test_utils::WaitForLoadStop(controller); |
333 } | 337 } |
334 } | 338 } |
335 } | 339 } |
336 | 340 |
337 } // namespace | 341 } // namespace |
OLD | NEW |