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

Side by Side Diff: chrome/browser/ui/pdf/pdf_browsertest.cc

Issue 289873007: Update pdf browser tests to use test data from new location. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 7 months 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 | « .gitignore ('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) 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.h" 6 #include "base/files/file.h"
7 #include "base/files/file_enumerator.h" 7 #include "base/files/file_enumerator.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 class PDFBrowserTest : public InProcessBrowserTest, 44 class PDFBrowserTest : public InProcessBrowserTest,
45 public testing::WithParamInterface<int>, 45 public testing::WithParamInterface<int>,
46 public content::NotificationObserver { 46 public content::NotificationObserver {
47 public: 47 public:
48 PDFBrowserTest() 48 PDFBrowserTest()
49 : snapshot_different_(true), 49 : snapshot_different_(true),
50 next_dummy_search_value_(0), 50 next_dummy_search_value_(0),
51 load_stop_notification_count_(0) { 51 load_stop_notification_count_(0) {
52 base::FilePath src_dir; 52 base::FilePath src_dir;
53 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); 53 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
54 pdf_test_server_.ServeFilesFromDirectory(src_dir.AppendASCII("pdf/test")); 54 pdf_test_server_.ServeFilesFromDirectory(src_dir.AppendASCII(
55 "chrome/test/data/pdf_private"));
55 } 56 }
56 57
57 protected: 58 protected:
58 // Use our own TestServer so that we can serve files from the pdf directory. 59 // Use our own TestServer so that we can serve files from the pdf directory.
59 net::test_server::EmbeddedTestServer* pdf_test_server() { 60 net::test_server::EmbeddedTestServer* pdf_test_server() {
60 return &pdf_test_server_; 61 return &pdf_test_server_;
61 } 62 }
62 63
63 int load_stop_notification_count() const { 64 int load_stop_notification_count() const {
64 return load_stop_notification_count_; 65 return load_stop_notification_count_;
65 } 66 }
66 67
67 base::FilePath GetPDFTestDir() {
68 return base::FilePath(base::FilePath::kCurrentDirectory).AppendASCII("..").
69 AppendASCII("..").AppendASCII("..").AppendASCII("pdf").
70 AppendASCII("test");
71 }
72
73 void Load() { 68 void Load() {
74 // Make sure to set the window size before rendering, as otherwise rendering 69 // Make sure to set the window size before rendering, as otherwise rendering
75 // to a smaller window and then expanding leads to slight anti-aliasing 70 // to a smaller window and then expanding leads to slight anti-aliasing
76 // differences of the text and the pixel comparison fails. 71 // differences of the text and the pixel comparison fails.
77 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); 72 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight));
78 gfx::Rect screen_bounds = 73 gfx::Rect screen_bounds =
79 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds(); 74 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().bounds();
80 ASSERT_GT(screen_bounds.width(), kBrowserWidth); 75 ASSERT_GT(screen_bounds.width(), kBrowserWidth);
81 ASSERT_GT(screen_bounds.height(), kBrowserHeight); 76 ASSERT_GT(screen_bounds.height(), kBrowserHeight);
82 browser()->window()->SetBounds(bounds); 77 browser()->window()->SetBounds(bounds);
83 78
84 GURL url(ui_test_utils::GetTestUrl( 79 GURL url(ui_test_utils::GetTestUrl(
85 GetPDFTestDir(), 80 base::FilePath(FILE_PATH_LITERAL("pdf_private")),
86 base::FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); 81 base::FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf"))));
87 ui_test_utils::NavigateToURL(browser(), url); 82 ui_test_utils::NavigateToURL(browser(), url);
88 } 83 }
89 84
90 bool VerifySnapshot(const std::string& expected_filename) { 85 bool VerifySnapshot(const std::string& expected_filename) {
91 snapshot_different_ = true; 86 snapshot_different_ = true;
92 expected_filename_ = expected_filename; 87 expected_filename_ = expected_filename;
93 WebContents* web_contents = 88 WebContents* web_contents =
94 browser()->tab_strip_model()->GetActiveWebContents(); 89 browser()->tab_strip_model()->GetActiveWebContents();
95 DCHECK(web_contents); 90 DCHECK(web_contents);
(...skipping 30 matching lines...) Expand all
126 ASSERT_EQ(0, ui_test_utils::FindInPage( 121 ASSERT_EQ(0, ui_test_utils::FindInPage(
127 browser()->tab_strip_model()->GetActiveWebContents(), 122 browser()->tab_strip_model()->GetActiveWebContents(),
128 query, true, false, NULL, NULL)); 123 query, true, false, NULL, NULL));
129 } 124 }
130 125
131 private: 126 private:
132 void CopyFromBackingStoreCallback(bool success, const SkBitmap& bitmap) { 127 void CopyFromBackingStoreCallback(bool success, const SkBitmap& bitmap) {
133 base::MessageLoopForUI::current()->Quit(); 128 base::MessageLoopForUI::current()->Quit();
134 ASSERT_EQ(success, true); 129 ASSERT_EQ(success, true);
135 base::FilePath reference = ui_test_utils::GetTestFilePath( 130 base::FilePath reference = ui_test_utils::GetTestFilePath(
136 GetPDFTestDir(), 131 base::FilePath(FILE_PATH_LITERAL("pdf_private")),
137 base::FilePath().AppendASCII(expected_filename_)); 132 base::FilePath().AppendASCII(expected_filename_));
138 base::File::Info info; 133 base::File::Info info;
139 ASSERT_TRUE(base::GetFileInfo(reference, &info)); 134 ASSERT_TRUE(base::GetFileInfo(reference, &info));
140 int size = static_cast<size_t>(info.size); 135 int size = static_cast<size_t>(info.size);
141 scoped_ptr<char[]> data(new char[size]); 136 scoped_ptr<char[]> data(new char[size]);
142 ASSERT_EQ(size, base::ReadFile(reference, data.get(), size)); 137 ASSERT_EQ(size, base::ReadFile(reference, data.get(), size));
143 138
144 int w, h; 139 int w, h;
145 std::vector<unsigned char> decoded; 140 std::vector<unsigned char> decoded;
146 ASSERT_TRUE(gfx::PNGCodec::Decode( 141 ASSERT_TRUE(gfx::PNGCodec::Decode(
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 307
313 NavigationController* controller = 308 NavigationController* controller =
314 &(browser()->tab_strip_model()->GetActiveWebContents()->GetController()); 309 &(browser()->tab_strip_model()->GetActiveWebContents()->GetController());
315 content::NotificationRegistrar registrar; 310 content::NotificationRegistrar registrar;
316 registrar.Add(this, 311 registrar.Add(this,
317 content::NOTIFICATION_LOAD_STOP, 312 content::NOTIFICATION_LOAD_STOP,
318 content::Source<NavigationController>(controller)); 313 content::Source<NavigationController>(controller));
319 std::string base_url = std::string("/"); 314 std::string base_url = std::string("/");
320 315
321 base::FileEnumerator file_enumerator( 316 base::FileEnumerator file_enumerator(
322 ui_test_utils::GetTestFilePath(GetPDFTestDir(), base::FilePath()), 317 ui_test_utils::GetTestFilePath(
318 base::FilePath(FILE_PATH_LITERAL("pdf_private")), base::FilePath()),
323 false, 319 false,
324 base::FileEnumerator::FILES, 320 base::FileEnumerator::FILES,
325 FILE_PATH_LITERAL("*.pdf")); 321 FILE_PATH_LITERAL("*.pdf"));
326 for (base::FilePath file_path = file_enumerator.Next(); 322 for (base::FilePath file_path = file_enumerator.Next();
327 !file_path.empty(); 323 !file_path.empty();
328 file_path = file_enumerator.Next()) { 324 file_path = file_enumerator.Next()) {
329 std::string filename = file_path.BaseName().MaybeAsASCII(); 325 std::string filename = file_path.BaseName().MaybeAsASCII();
330 ASSERT_FALSE(filename.empty()); 326 ASSERT_FALSE(filename.empty());
331 327
332 #if defined(OS_POSIX) 328 #if defined(OS_POSIX)
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 browser()->tab_strip_model()->GetActiveWebContents(), 417 browser()->tab_strip_model()->GetActiveWebContents(),
422 "reloadPDF();")); 418 "reloadPDF();"));
423 observer.Wait(); 419 observer.Wait();
424 420
425 ASSERT_EQ("success", 421 ASSERT_EQ("success",
426 browser()->tab_strip_model()->GetActiveWebContents()-> 422 browser()->tab_strip_model()->GetActiveWebContents()->
427 GetURL().query()); 423 GetURL().query());
428 } 424 }
429 425
430 } // namespace 426 } // namespace
OLDNEW
« no previous file with comments | « .gitignore ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698