Chromium Code Reviews| 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/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_window.h" | 12 #include "chrome/browser/browser_window.h" |
| 12 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/window_sizer.h" | 16 #include "chrome/browser/window_sizer.h" |
| 16 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/notification_observer.h" | 19 #include "chrome/common/notification_observer.h" |
| 19 #include "chrome/test/in_process_browser_test.h" | 20 #include "chrome/test/in_process_browser_test.h" |
| 20 #include "chrome/test/ui_test_utils.h" | 21 #include "chrome/test/ui_test_utils.h" |
| 21 #include "gfx/codec/png_codec.h" | 22 #include "gfx/codec/png_codec.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // Include things like browser frame and scrollbar and make sure we're bigger | 26 // Include things like browser frame and scrollbar and make sure we're bigger |
| 26 // than the test pdf document. | 27 // than the test pdf document. |
| 27 static const int kBrowserWidth = 1000; | 28 static const int kBrowserWidth = 1000; |
| 28 static const int kBrowserHeight = 600; | 29 static const int kBrowserHeight = 600; |
| 29 | 30 |
| 30 class PDFBrowserTest : public InProcessBrowserTest, | 31 class PDFBrowserTest : public InProcessBrowserTest, |
| 31 public NotificationObserver { | 32 public NotificationObserver { |
| 32 public: | 33 public: |
| 33 PDFBrowserTest() | 34 PDFBrowserTest() |
| 34 : have_plugin_(false), | 35 : snapshot_different_(true), |
| 35 snapshot_different_(true), | |
| 36 next_dummy_search_value_(0) { | 36 next_dummy_search_value_(0) { |
| 37 EnableDOMAutomation(); | |
| 37 } | 38 } |
| 38 | 39 |
| 39 protected: | 40 protected: |
| 40 bool have_plugin() const { return have_plugin_; } | |
| 41 | |
| 42 virtual void SetUp() { | 41 virtual void SetUp() { |
| 43 FilePath pdf_path; | 42 FilePath pdf_path; |
| 44 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); | 43 PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| 45 have_plugin_ = file_util::PathExists(pdf_path); | |
| 46 InProcessBrowserTest::SetUp(); | 44 InProcessBrowserTest::SetUp(); |
| 47 } | 45 } |
| 48 | 46 |
| 47 FilePath GetPDFTestDir() { | |
| 48 return FilePath(FilePath::kCurrentDirectory).AppendASCII("plugin"). | |
| 49 AppendASCII("pdf"); | |
| 50 } | |
| 51 | |
| 49 void Load() { | 52 void Load() { |
| 50 GURL url(ui_test_utils::GetTestUrl( | 53 GURL url(ui_test_utils::GetTestUrl( |
| 51 FilePath(FilePath::kCurrentDirectory), | 54 GetPDFTestDir(), |
| 52 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); | 55 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); |
| 53 ui_test_utils::NavigateToURL(browser(), url); | 56 ui_test_utils::NavigateToURL(browser(), url); |
| 54 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); | 57 gfx::Rect bounds(gfx::Rect(0, 0, kBrowserWidth, kBrowserHeight)); |
| 55 | 58 |
| 56 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info( | 59 scoped_ptr<WindowSizer::MonitorInfoProvider> monitor_info( |
| 57 WindowSizer::CreateDefaultMonitorInfoProvider()); | 60 WindowSizer::CreateDefaultMonitorInfoProvider()); |
| 58 gfx::Rect screen_bounds = monitor_info->GetPrimaryMonitorBounds(); | 61 gfx::Rect screen_bounds = monitor_info->GetPrimaryMonitorBounds(); |
| 59 ASSERT_GT(screen_bounds.width(), kBrowserWidth); | 62 ASSERT_GT(screen_bounds.width(), kBrowserWidth); |
| 60 ASSERT_GT(screen_bounds.height(), kBrowserHeight); | 63 ASSERT_GT(screen_bounds.height(), kBrowserHeight); |
| 61 | 64 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 command_line->AppendSwitch(switches::kForceInternalPDFPlugin); | 101 command_line->AppendSwitch(switches::kForceInternalPDFPlugin); |
| 99 } | 102 } |
| 100 | 103 |
| 101 // NotificationObserver | 104 // NotificationObserver |
| 102 virtual void Observe(NotificationType type, | 105 virtual void Observe(NotificationType type, |
| 103 const NotificationSource& source, | 106 const NotificationSource& source, |
| 104 const NotificationDetails& details) { | 107 const NotificationDetails& details) { |
| 105 if (type == NotificationType::TAB_SNAPSHOT_TAKEN) { | 108 if (type == NotificationType::TAB_SNAPSHOT_TAKEN) { |
| 106 MessageLoopForUI::current()->Quit(); | 109 MessageLoopForUI::current()->Quit(); |
| 107 FilePath reference = ui_test_utils::GetTestFilePath( | 110 FilePath reference = ui_test_utils::GetTestFilePath( |
| 108 FilePath(FilePath::kCurrentDirectory), | 111 GetPDFTestDir(), |
| 109 FilePath().AppendASCII(expected_filename_)); | 112 FilePath().AppendASCII(expected_filename_)); |
| 110 base::PlatformFileInfo info; | 113 base::PlatformFileInfo info; |
| 111 ASSERT_TRUE(file_util::GetFileInfo(reference, &info)); | 114 ASSERT_TRUE(file_util::GetFileInfo(reference, &info)); |
| 112 int size = static_cast<size_t>(info.size); | 115 int size = static_cast<size_t>(info.size); |
| 113 scoped_array<char> data(new char[size]); | 116 scoped_array<char> data(new char[size]); |
| 114 ASSERT_EQ(size, file_util::ReadFile(reference, data.get(), size)); | 117 ASSERT_EQ(size, file_util::ReadFile(reference, data.get(), size)); |
| 115 | 118 |
| 116 int w, h; | 119 int w, h; |
| 117 std::vector<unsigned char> decoded; | 120 std::vector<unsigned char> decoded; |
| 118 ASSERT_TRUE(gfx::PNGCodec::Decode( | 121 ASSERT_TRUE(gfx::PNGCodec::Decode( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 std::vector<unsigned char> png_data; | 164 std::vector<unsigned char> png_data; |
| 162 gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data); | 165 gfx::PNGCodec::EncodeBGRASkBitmap(*bitmap, false, &png_data); |
| 163 if (file_util::CreateTemporaryFile(&snapshot_filename_)) { | 166 if (file_util::CreateTemporaryFile(&snapshot_filename_)) { |
| 164 file_util::WriteFile(snapshot_filename_, | 167 file_util::WriteFile(snapshot_filename_, |
| 165 reinterpret_cast<char*>(&png_data[0]), png_data.size()); | 168 reinterpret_cast<char*>(&png_data[0]), png_data.size()); |
| 166 } | 169 } |
| 167 } | 170 } |
| 168 } | 171 } |
| 169 } | 172 } |
| 170 | 173 |
| 171 // True if we found the pdf plugin. Needed since only official builders have | |
| 172 // the pdf plugin, so for the rest, and for other devs, we don't want the test | |
| 173 // to fail. | |
| 174 bool have_plugin_; | |
| 175 // True if the snapshot differed from the expected value. | 174 // True if the snapshot differed from the expected value. |
| 176 bool snapshot_different_; | 175 bool snapshot_different_; |
| 177 // Internal variable used to synchronize to the renderer. | 176 // Internal variable used to synchronize to the renderer. |
| 178 int next_dummy_search_value_; | 177 int next_dummy_search_value_; |
| 179 // The filename of the bitmap to compare the snapshot to. | 178 // The filename of the bitmap to compare the snapshot to. |
| 180 std::string expected_filename_; | 179 std::string expected_filename_; |
| 181 // If the snapshot is different, holds the location where it's saved. | 180 // If the snapshot is different, holds the location where it's saved. |
| 182 FilePath snapshot_filename_; | 181 FilePath snapshot_filename_; |
| 183 }; | 182 }; |
| 184 | 183 |
| 185 #if defined(OS_MACOSX) | 184 #if defined(OS_MACOSX) |
| 186 // See http://crbug.com/63223 | 185 // See http://crbug.com/63223 |
| 187 #define MAYBE_Basic FLAKY_Basic | 186 #define MAYBE_Basic FLAKY_Basic |
| 188 #else | 187 #else |
| 189 #define MAYBE_Basic Basic | 188 #define MAYBE_Basic Basic |
| 190 #endif | 189 #endif |
| 191 | 190 |
| 192 // Tests basic PDF rendering. This can be broken depending on bad merges with | 191 // Tests basic PDF rendering. This can be broken depending on bad merges with |
| 193 // the vendor, so it's important that we have basic sanity checking. | 192 // the vendor, so it's important that we have basic sanity checking. |
| 194 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Basic) { | 193 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Basic) { |
| 195 if (!have_plugin()) | |
| 196 return; | |
| 197 | 194 |
| 198 ASSERT_NO_FATAL_FAILURE(Load()); | 195 ASSERT_NO_FATAL_FAILURE(Load()); |
| 199 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); | 196 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); |
| 200 ASSERT_NO_FATAL_FAILURE(VerifySnapshot("pdf_browsertest.png")); | 197 ASSERT_NO_FATAL_FAILURE(VerifySnapshot("pdf_browsertest.png")); |
| 201 } | 198 } |
| 202 | 199 |
| 203 #if defined(OS_MACOSX) | 200 #if defined(OS_MACOSX) |
| 204 // See http://crbug.com/63223 | 201 // See http://crbug.com/63223 |
| 205 #define MAYBE_Scroll FLAKY_Scroll | 202 #define MAYBE_Scroll FLAKY_Scroll |
| 206 #else | 203 #else |
| 207 #define MAYBE_Scroll Scroll | 204 #define MAYBE_Scroll Scroll |
| 208 #endif | 205 #endif |
| 209 | 206 |
| 210 // Tests that scrolling works. | 207 // Tests that scrolling works. |
| 211 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) { | 208 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) { |
| 212 if (!have_plugin()) | |
| 213 return; | |
| 214 | |
| 215 ASSERT_NO_FATAL_FAILURE(Load()); | 209 ASSERT_NO_FATAL_FAILURE(Load()); |
| 216 | 210 |
| 217 // We use wheel mouse event since that's the only one we can easily push to | 211 // We use wheel mouse event since that's the only one we can easily push to |
| 218 // the renderer. There's no way to push a cross-platform keyboard event at | 212 // the renderer. There's no way to push a cross-platform keyboard event at |
| 219 // the moment. | 213 // the moment. |
| 220 WebKit::WebMouseWheelEvent wheel_event; | 214 WebKit::WebMouseWheelEvent wheel_event; |
| 221 wheel_event.type = WebKit::WebInputEvent::MouseWheel; | 215 wheel_event.type = WebKit::WebInputEvent::MouseWheel; |
| 222 wheel_event.deltaY = -200; | 216 wheel_event.deltaY = -200; |
| 223 wheel_event.wheelTicksY = -2; | 217 wheel_event.wheelTicksY = -2; |
| 224 TabContents* tab_contents = browser()->GetSelectedTabContents(); | 218 TabContents* tab_contents = browser()->GetSelectedTabContents(); |
| 225 tab_contents->render_view_host()->ForwardWheelEvent(wheel_event); | 219 tab_contents->render_view_host()->ForwardWheelEvent(wheel_event); |
| 226 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); | 220 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); |
| 227 ASSERT_NO_FATAL_FAILURE(VerifySnapshot("pdf_browsertest_scroll.png")); | 221 ASSERT_NO_FATAL_FAILURE(VerifySnapshot("pdf_browsertest_scroll.png")); |
| 228 } | 222 } |
| 229 | 223 |
| 230 #if defined(OS_MACOSX) | 224 #if defined(OS_MACOSX) |
| 231 // See http://crbug.com/63223 | 225 // See http://crbug.com/63223 |
| 232 #define MAYBE_FindAndCopy FLAKY_FindAndCopy | 226 #define MAYBE_FindAndCopy FLAKY_FindAndCopy |
| 233 #else | 227 #else |
| 234 #define MAYBE_FindAndCopy FindAndCopy | 228 #define MAYBE_FindAndCopy FindAndCopy |
| 235 #endif | 229 #endif |
| 236 | 230 |
| 237 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) { | 231 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) { |
| 238 if (!have_plugin()) | |
| 239 return; | |
| 240 | |
| 241 ASSERT_NO_FATAL_FAILURE(Load()); | 232 ASSERT_NO_FATAL_FAILURE(Load()); |
| 242 // Verifies that find in page works. | 233 // Verifies that find in page works. |
| 243 ASSERT_EQ(3, ui_test_utils::FindInPage( | 234 ASSERT_EQ(3, ui_test_utils::FindInPage( |
| 244 browser()->GetSelectedTabContents(), UTF8ToUTF16("adipiscing"), true, | 235 browser()->GetSelectedTabContents(), UTF8ToUTF16("adipiscing"), true, |
| 245 false, NULL)); | 236 false, NULL)); |
| 246 | 237 |
| 247 // Verify that copying selected text works. | 238 // Verify that copying selected text works. |
| 248 Clipboard clipboard; | 239 Clipboard clipboard; |
| 249 // Reset the clipboard first. | 240 // Reset the clipboard first. |
| 250 Clipboard::ObjectMap objects; | 241 Clipboard::ObjectMap objects; |
| 251 Clipboard::ObjectMapParams params; | 242 Clipboard::ObjectMapParams params; |
| 252 params.push_back(std::vector<char>()); | 243 params.push_back(std::vector<char>()); |
| 253 objects[Clipboard::CBF_TEXT] = params; | 244 objects[Clipboard::CBF_TEXT] = params; |
| 254 clipboard.WriteObjects(objects); | 245 clipboard.WriteObjects(objects); |
| 255 | 246 |
| 256 browser()->GetSelectedTabContents()->render_view_host()->Copy(); | 247 browser()->GetSelectedTabContents()->render_view_host()->Copy(); |
| 257 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); | 248 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); |
| 258 | 249 |
| 259 std::string text; | 250 std::string text; |
| 260 clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &text); | 251 clipboard.ReadAsciiText(Clipboard::BUFFER_STANDARD, &text); |
| 261 ASSERT_EQ("adipiscing", text); | 252 ASSERT_EQ("adipiscing", text); |
| 262 } | 253 } |
| 263 | 254 |
| 255 // Tests that loading async pdfs works correctly (i.e. document fully loads). | |
| 256 // This also loads all documents that used to crash, to ensure we don't have | |
| 257 // regressions. | |
| 258 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, Loading) { | |
| 259 ASSERT_TRUE(test_server()->Start()); | |
| 260 | |
| 261 std::string base_url = std::string("files/plugin/pdf/"); | |
| 262 | |
| 263 file_util::FileEnumerator file_enumerator( | |
| 264 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), | |
| 265 false, | |
| 266 file_util::FileEnumerator::FILES, | |
| 267 FILE_PATH_LITERAL("*.pdf")); | |
| 268 for (FilePath file_path = file_enumerator.Next(); | |
| 269 !file_path.empty(); | |
| 270 file_path = file_enumerator.Next()) { | |
| 271 std::string filename = WideToASCII(file_path.BaseName().ToWStringHack()); | |
| 272 LOG(WARNING) << "PDFBrowserTest.Loading: " << filename; | |
|
cbentzel
2010/11/17 03:02:01
Local debugging?
jam
2010/11/17 04:10:10
no, i wanted it to show which pdf it's starting, s
| |
| 273 | |
| 274 GURL url = test_server()->GetURL(base_url + filename); | |
| 275 ui_test_utils::NavigateToURL(browser(), url); | |
| 276 | |
| 277 bool complete = false; | |
| 278 while (true) { | |
| 279 // We might get extraneous NotificationType::LOAD_STOP notifications when | |
| 280 // doing async loading. This happens when the first loader is cancelled | |
| 281 // and before creating a byte-range request loader. | |
| 282 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | |
| 283 browser()->GetSelectedTabContents()->render_view_host(), | |
| 284 std::wstring(), | |
| 285 L"window.domAutomationController.send(plugin.documentLoadComplete())", | |
| 286 &complete)); | |
| 287 if (complete) | |
| 288 break; | |
| 289 | |
| 290 ui_test_utils::WaitForLoadStop( | |
| 291 &(browser()->GetSelectedTabContents()->controller())); | |
| 292 } | |
| 293 } | |
| 294 } | |
| 295 | |
| 264 } // namespace | 296 } // namespace |
| OLD | NEW |