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/file_util.h" | 5 #include "base/file_util.h" |
6 #include "base/files/file_enumerator.h" | 6 #include "base/files/file_enumerator.h" |
7 #include "base/hash.h" | 7 #include "base/hash.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/chrome_paths.h" | 16 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/navigation_controller.h" | 19 #include "content/public/browser/navigation_controller.h" |
20 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
21 #include "content/public/browser/render_view_host.h" | 21 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
24 #include "net/test/spawned_test_server/spawned_test_server.h" | 24 #include "net/test/embedded_test_server/embedded_test_server.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
26 #include "ui/base/clipboard/clipboard.h" | 26 #include "ui/base/clipboard/clipboard.h" |
27 #include "ui/gfx/codec/png_codec.h" | 27 #include "ui/gfx/codec/png_codec.h" |
28 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
29 | 29 |
30 using content::NavigationController; | 30 using content::NavigationController; |
31 using content::WebContents; | 31 using content::WebContents; |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
35 // Include things like browser frame and scrollbar and make sure we're bigger | 35 // Include things like browser frame and scrollbar and make sure we're bigger |
36 // than the test pdf document. | 36 // than the test pdf document. |
37 static const int kBrowserWidth = 1000; | 37 static const int kBrowserWidth = 1000; |
38 static const int kBrowserHeight = 600; | 38 static const int kBrowserHeight = 600; |
39 | 39 |
40 class PDFBrowserTest : public InProcessBrowserTest, | 40 class PDFBrowserTest : public InProcessBrowserTest, |
41 public testing::WithParamInterface<int>, | 41 public testing::WithParamInterface<int>, |
42 public content::NotificationObserver { | 42 public content::NotificationObserver { |
43 public: | 43 public: |
44 PDFBrowserTest() | 44 PDFBrowserTest() |
45 : snapshot_different_(true), | 45 : snapshot_different_(true), |
46 next_dummy_search_value_(0), | 46 next_dummy_search_value_(0), |
47 load_stop_notification_count_(0) { | 47 load_stop_notification_count_(0), |
48 pdf_test_server_.reset(new net::SpawnedTestServer( | 48 pdf_test_server_( |
49 net::SpawnedTestServer::TYPE_HTTP, | 49 content::BrowserThread::GetMessageLoopProxyForThread( |
50 net::SpawnedTestServer::kLocalhost, | 50 content::BrowserThread::IO)) { |
51 base::FilePath(FILE_PATH_LITERAL("pdf/test")))); | 51 pdf_test_server_.ServeFilesFromDirectory( |
| 52 base::FilePath(FILE_PATH_LITERAL("pdf/test"))); |
52 } | 53 } |
53 | 54 |
54 protected: | 55 protected: |
55 // Use our own TestServer so that we can serve files from the pdf directory. | 56 // Use our own TestServer so that we can serve files from the pdf directory. |
56 net::SpawnedTestServer* pdf_test_server() { return pdf_test_server_.get(); } | 57 net::test_server::EmbeddedTestServer* pdf_test_server() { |
| 58 return &pdf_test_server_; |
| 59 } |
57 | 60 |
58 int load_stop_notification_count() const { | 61 int load_stop_notification_count() const { |
59 return load_stop_notification_count_; | 62 return load_stop_notification_count_; |
60 } | 63 } |
61 | 64 |
62 base::FilePath GetPDFTestDir() { | 65 base::FilePath GetPDFTestDir() { |
63 return base::FilePath(base::FilePath::kCurrentDirectory).AppendASCII(".."). | 66 return base::FilePath(base::FilePath::kCurrentDirectory).AppendASCII(".."). |
64 AppendASCII("..").AppendASCII("..").AppendASCII("pdf"). | 67 AppendASCII("..").AppendASCII("..").AppendASCII("pdf"). |
65 AppendASCII("test"); | 68 AppendASCII("test"); |
66 } | 69 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 bool snapshot_different_; | 203 bool snapshot_different_; |
201 // Internal variable used to synchronize to the renderer. | 204 // Internal variable used to synchronize to the renderer. |
202 int next_dummy_search_value_; | 205 int next_dummy_search_value_; |
203 // The filename of the bitmap to compare the snapshot to. | 206 // The filename of the bitmap to compare the snapshot to. |
204 std::string expected_filename_; | 207 std::string expected_filename_; |
205 // If the snapshot is different, holds the location where it's saved. | 208 // If the snapshot is different, holds the location where it's saved. |
206 base::FilePath snapshot_filename_; | 209 base::FilePath snapshot_filename_; |
207 // How many times we've seen chrome::LOAD_STOP. | 210 // How many times we've seen chrome::LOAD_STOP. |
208 int load_stop_notification_count_; | 211 int load_stop_notification_count_; |
209 | 212 |
210 scoped_ptr<net::SpawnedTestServer> pdf_test_server_; | 213 net::test_server::EmbeddedTestServer pdf_test_server_; |
211 }; | 214 }; |
212 | 215 |
213 #if defined(OS_CHROMEOS) | 216 #if defined(OS_CHROMEOS) |
214 // TODO(sanjeevr): http://crbug.com/79837 | 217 // TODO(sanjeevr): http://crbug.com/79837 |
215 #define MAYBE_Basic DISABLED_Basic | 218 #define MAYBE_Basic DISABLED_Basic |
216 #else | 219 #else |
217 #define MAYBE_Basic Basic | 220 #define MAYBE_Basic Basic |
218 #endif | 221 #endif |
219 // Tests basic PDF rendering. This can be broken depending on bad merges with | 222 // Tests basic PDF rendering. This can be broken depending on bad merges with |
220 // the vendor, so it's important that we have basic sanity checking. | 223 // the vendor, so it's important that we have basic sanity checking. |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 ASSERT_EQ("adipiscing", text); | 299 ASSERT_EQ("adipiscing", text); |
297 } | 300 } |
298 | 301 |
299 const int kLoadingNumberOfParts = 10; | 302 const int kLoadingNumberOfParts = 10; |
300 | 303 |
301 // Tests that loading async pdfs works correctly (i.e. document fully loads). | 304 // Tests that loading async pdfs works correctly (i.e. document fully loads). |
302 // This also loads all documents that used to crash, to ensure we don't have | 305 // This also loads all documents that used to crash, to ensure we don't have |
303 // regressions. | 306 // regressions. |
304 // If it flakes, reopen http://crbug.com/74548. | 307 // If it flakes, reopen http://crbug.com/74548. |
305 IN_PROC_BROWSER_TEST_P(PDFBrowserTest, Loading) { | 308 IN_PROC_BROWSER_TEST_P(PDFBrowserTest, Loading) { |
306 ASSERT_TRUE(pdf_test_server()->Start()); | 309 ASSERT_TRUE(pdf_test_server()->InitializeAndWaitUntilReady()); |
307 | 310 |
308 NavigationController* controller = | 311 NavigationController* controller = |
309 &(browser()->tab_strip_model()->GetActiveWebContents()->GetController()); | 312 &(browser()->tab_strip_model()->GetActiveWebContents()->GetController()); |
310 content::NotificationRegistrar registrar; | 313 content::NotificationRegistrar registrar; |
311 registrar.Add(this, | 314 registrar.Add(this, |
312 content::NOTIFICATION_LOAD_STOP, | 315 content::NOTIFICATION_LOAD_STOP, |
313 content::Source<NavigationController>(controller)); | 316 content::Source<NavigationController>(controller)); |
314 std::string base_url = std::string("files/"); | 317 std::string base_url = std::string("/"); |
315 | 318 |
316 base::FileEnumerator file_enumerator( | 319 base::FileEnumerator file_enumerator( |
317 ui_test_utils::GetTestFilePath(GetPDFTestDir(), base::FilePath()), | 320 ui_test_utils::GetTestFilePath(GetPDFTestDir(), base::FilePath()), |
318 false, | 321 false, |
319 base::FileEnumerator::FILES, | 322 base::FileEnumerator::FILES, |
320 FILE_PATH_LITERAL("*.pdf")); | 323 FILE_PATH_LITERAL("*.pdf")); |
321 for (base::FilePath file_path = file_enumerator.Next(); | 324 for (base::FilePath file_path = file_enumerator.Next(); |
322 !file_path.empty(); | 325 !file_path.empty(); |
323 file_path = file_enumerator.Next()) { | 326 file_path = file_enumerator.Next()) { |
324 std::string filename = file_path.BaseName().MaybeAsASCII(); | 327 std::string filename = file_path.BaseName().MaybeAsASCII(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 392 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
390 browser()->tab_strip_model()->GetActiveWebContents(), | 393 browser()->tab_strip_model()->GetActiveWebContents(), |
391 "window.domAutomationController.send(" | 394 "window.domAutomationController.send(" |
392 " document.getElementsByName('plugin')[0].getZoomLevel().toString())", | 395 " document.getElementsByName('plugin')[0].getZoomLevel().toString())", |
393 &zoom2)); | 396 &zoom2)); |
394 ASSERT_NE(zoom1, zoom2); | 397 ASSERT_NE(zoom1, zoom2); |
395 } | 398 } |
396 | 399 |
397 // Flaky as per http://crbug.com/74549. | 400 // Flaky as per http://crbug.com/74549. |
398 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_OnLoadAndReload) { | 401 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_OnLoadAndReload) { |
399 ASSERT_TRUE(pdf_test_server()->Start()); | 402 ASSERT_TRUE(pdf_test_server()->InitializeAndWaitUntilReady()); |
400 | 403 |
401 GURL url = pdf_test_server()->GetURL("files/onload_reload.html"); | 404 GURL url = pdf_test_server()->GetURL("/onload_reload.html"); |
402 ui_test_utils::NavigateToURL(browser(), url); | 405 ui_test_utils::NavigateToURL(browser(), url); |
403 | 406 |
404 content::WindowedNotificationObserver observer( | 407 content::WindowedNotificationObserver observer( |
405 content::NOTIFICATION_LOAD_STOP, | 408 content::NOTIFICATION_LOAD_STOP, |
406 content::Source<NavigationController>( | 409 content::Source<NavigationController>( |
407 &browser()->tab_strip_model()->GetActiveWebContents()-> | 410 &browser()->tab_strip_model()->GetActiveWebContents()-> |
408 GetController())); | 411 GetController())); |
409 ASSERT_TRUE(content::ExecuteScript( | 412 ASSERT_TRUE(content::ExecuteScript( |
410 browser()->tab_strip_model()->GetActiveWebContents(), | 413 browser()->tab_strip_model()->GetActiveWebContents(), |
411 "reloadPDF();")); | 414 "reloadPDF();")); |
412 observer.Wait(); | 415 observer.Wait(); |
413 | 416 |
414 ASSERT_EQ("success", | 417 ASSERT_EQ("success", |
415 browser()->tab_strip_model()->GetActiveWebContents()-> | 418 browser()->tab_strip_model()->GetActiveWebContents()-> |
416 GetURL().query()); | 419 GetURL().query()); |
417 } | 420 } |
418 | 421 |
419 } // namespace | 422 } // namespace |
OLD | NEW |