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

Side by Side Diff: chrome/test/plugin/pdf_browsertest.cc

Issue 5145009: Switch the PDF browser test to get its data from the pdf repo. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/data/pdf_browsertest_scroll.png ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"))));
55 } 60 }
56 61
57 protected: 62 protected:
63 // Use our own TestServer so that we can serve files from the pdf directory.
64 net::TestServer* pdf_test_server() { return pdf_test_server_.get(); }
65
58 int load_stop_notification_count() const { 66 int load_stop_notification_count() const {
59 return load_stop_notification_count_; 67 return load_stop_notification_count_;
60 } 68 }
61 69
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() { 70 FilePath GetPDFTestDir() {
69 return FilePath(FilePath::kCurrentDirectory).AppendASCII("plugin"). 71 return FilePath(FilePath::kCurrentDirectory).AppendASCII("..").
70 AppendASCII("pdf"); 72 AppendASCII("..").AppendASCII("..").AppendASCII("pdf").
73 AppendASCII("test");
71 } 74 }
72 75
73 void Load() { 76 void Load() {
74 GURL url(ui_test_utils::GetTestUrl( 77 GURL url(ui_test_utils::GetTestUrl(
75 GetPDFTestDir(), 78 GetPDFTestDir(),
76 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); 79 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf"))));
77 ui_test_utils::NavigateToURL(browser(), url); 80 ui_test_utils::NavigateToURL(browser(), url);
78 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); 81 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight));
79 82
80 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info( 83 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // True if the snapshot differed from the expected value. 200 // True if the snapshot differed from the expected value.
198 bool snapshot_different_; 201 bool snapshot_different_;
199 // Internal variable used to synchronize to the renderer. 202 // Internal variable used to synchronize to the renderer.
200 int next_dummy_search_value_; 203 int next_dummy_search_value_;
201 // The filename of the bitmap to compare the snapshot to. 204 // The filename of the bitmap to compare the snapshot to.
202 std::string expected_filename_; 205 std::string expected_filename_;
203 // If the snapshot is different, holds the location where it's saved. 206 // If the snapshot is different, holds the location where it's saved.
204 FilePath snapshot_filename_; 207 FilePath snapshot_filename_;
205 // How many times we've seen NotificationType::LOAD_STOP. 208 // How many times we've seen NotificationType::LOAD_STOP.
206 int load_stop_notification_count_; 209 int load_stop_notification_count_;
210
211 scoped_ptr<net::TestServer> pdf_test_server_;
207 }; 212 };
208 213
209 #if defined(OS_MACOSX) 214 #if defined(OS_MACOSX)
210 // See http://crbug.com/63223 215 // See http://crbug.com/63223
211 #define MAYBE_Basic FLAKY_Basic 216 #define MAYBE_Basic FLAKY_Basic
212 #else 217 #else
213 #define MAYBE_Basic Basic 218 #define MAYBE_Basic Basic
214 #endif 219 #endif
215 220
216 // Tests basic PDF rendering. This can be broken depending on bad merges with 221 // 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
274 279
275 std::string text; 280 std::string text;
276 clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &text); 281 clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &text);
277 ASSERT_EQ("adipiscing", text); 282 ASSERT_EQ("adipiscing", text);
278 } 283 }
279 284
280 // Tests that loading async pdfs works correctly (i.e. document fully loads). 285 // 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 286 // This also loads all documents that used to crash, to ensure we don't have
282 // regressions. 287 // regressions.
283 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, Loading) { 288 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, Loading) {
284 ASSERT_TRUE(test_server()->Start()); 289 ASSERT_TRUE(pdf_test_server()->Start());
285 290
286 NavigationController* controller = 291 NavigationController* controller =
287 &(browser()->GetSelectedTabContents()->controller()); 292 &(browser()->GetSelectedTabContents()->controller());
288 NotificationRegistrar registrar; 293 NotificationRegistrar registrar;
289 registrar.Add(this, 294 registrar.Add(this,
290 NotificationType::LOAD_STOP, 295 NotificationType::LOAD_STOP,
291 Source<NavigationController>(controller)); 296 Source<NavigationController>(controller));
292 std::string base_url = std::string("files/plugin/pdf/"); 297 std::string base_url = std::string("files/");
293 298
294 file_util::FileEnumerator file_enumerator( 299 file_util::FileEnumerator file_enumerator(
295 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), 300 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()),
296 false, 301 false,
297 file_util::FileEnumerator::FILES, 302 file_util::FileEnumerator::FILES,
298 FILE_PATH_LITERAL("*.pdf")); 303 FILE_PATH_LITERAL("*.pdf"));
299 for (FilePath file_path = file_enumerator.Next(); 304 for (FilePath file_path = file_enumerator.Next();
300 !file_path.empty(); 305 !file_path.empty();
301 file_path = file_enumerator.Next()) { 306 file_path = file_enumerator.Next()) {
302 std::string filename = WideToASCII(file_path.BaseName().ToWStringHack()); 307 std::string filename = WideToASCII(file_path.BaseName().ToWStringHack());
303 308
304 #if defined(OS_MACOSX) || defined(OS_LINUX) 309 #if defined(OS_MACOSX) || defined(OS_LINUX)
305 if (filename == "sample.pdf") 310 if (filename == "sample.pdf")
306 continue; // Crashes on Mac and Linux. http://crbug.com/63549 311 continue; // Crashes on Mac and Linux. http://crbug.com/63549
307 #endif 312 #endif
308 313
309 LOG(WARNING) << "PDFBrowserTest.Loading: " << filename; 314 LOG(WARNING) << "PDFBrowserTest.Loading: " << filename;
310 315
311 GURL url = test_server()->GetURL(base_url + filename); 316 GURL url = pdf_test_server()->GetURL(base_url + filename);
312 ui_test_utils::NavigateToURL(browser(), url); 317 ui_test_utils::NavigateToURL(browser(), url);
313 318
314 while (true) { 319 while (true) {
315 int last_count = load_stop_notification_count(); 320 int last_count = load_stop_notification_count();
316 // We might get extraneous NotificationType::LOAD_STOP notifications when 321 // We might get extraneous NotificationType::LOAD_STOP notifications when
317 // doing async loading. This happens when the first loader is cancelled 322 // doing async loading. This happens when the first loader is cancelled
318 // and before creating a byte-range request loader. 323 // and before creating a byte-range request loader.
319 bool complete = false; 324 bool complete = false;
320 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 325 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
321 browser()->GetSelectedTabContents()->render_view_host(), 326 browser()->GetSelectedTabContents()->render_view_host(),
322 std::wstring(), 327 std::wstring(),
323 L"window.domAutomationController.send(plugin.documentLoadComplete())", 328 L"window.domAutomationController.send(plugin.documentLoadComplete())",
324 &complete)); 329 &complete));
325 if (complete) 330 if (complete)
326 break; 331 break;
327 332
328 // Check if the LOAD_STOP notification could have come while we run a 333 // Check if the LOAD_STOP notification could have come while we run a
329 // nested message loop for the JS call. 334 // nested message loop for the JS call.
330 if (last_count != load_stop_notification_count()) 335 if (last_count != load_stop_notification_count())
331 continue; 336 continue;
332 ui_test_utils::WaitForLoadStop(controller); 337 ui_test_utils::WaitForLoadStop(controller);
333 } 338 }
334 } 339 }
335 } 340 }
336 341
337 } // namespace 342 } // namespace
OLDNEW
« no previous file with comments | « chrome/test/data/pdf_browsertest_scroll.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698