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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
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/path_service.h" 6 #include "base/path_service.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_tabstrip.h"
11 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/snapshot_tab_helper.h" 13 #include "chrome/browser/ui/snapshot_tab_helper.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
14 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
16 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/navigation_controller.h" 19 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/notification_observer.h" 20 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_view_host.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 77
77 GURL url(ui_test_utils::GetTestUrl( 78 GURL url(ui_test_utils::GetTestUrl(
78 GetPDFTestDir(), 79 GetPDFTestDir(),
79 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf")))); 80 FilePath(FILE_PATH_LITERAL("pdf_browsertest.pdf"))));
80 ui_test_utils::NavigateToURL(browser(), url); 81 ui_test_utils::NavigateToURL(browser(), url);
81 } 82 }
82 83
83 void VerifySnapshot(const std::string& expected_filename) { 84 void VerifySnapshot(const std::string& expected_filename) {
84 snapshot_different_ = true; 85 snapshot_different_ = true;
85 expected_filename_ = expected_filename; 86 expected_filename_ = expected_filename;
86 TabContents* tab_contents = browser()->GetActiveTabContents(); 87 TabContents* tab_contents = chrome::GetActiveTabContents(browser());
87 tab_contents->snapshot_tab_helper()->CaptureSnapshot(); 88 tab_contents->snapshot_tab_helper()->CaptureSnapshot();
88 ui_test_utils::RegisterAndWait( 89 ui_test_utils::RegisterAndWait(
89 this, 90 this,
90 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN, 91 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
91 content::Source<WebContents>(tab_contents->web_contents())); 92 content::Source<WebContents>(tab_contents->web_contents()));
92 ASSERT_FALSE(snapshot_different_) << "Rendering didn't match, see result " 93 ASSERT_FALSE(snapshot_different_) << "Rendering didn't match, see result "
93 "at " << snapshot_filename_.value().c_str(); 94 "at " << snapshot_filename_.value().c_str();
94 } 95 }
95 96
96 void WaitForResponse() { 97 void WaitForResponse() {
97 // Even if the plugin has loaded the data or scrolled, because of how 98 // Even if the plugin has loaded the data or scrolled, because of how
98 // pepper painting works, we might not have the data. One way to force this 99 // pepper painting works, we might not have the data. One way to force this
99 // to be flushed is to do a find operation, since on this two-page test 100 // to be flushed is to do a find operation, since on this two-page test
100 // document, it'll wait for us to flush the renderer message loop twice and 101 // document, it'll wait for us to flush the renderer message loop twice and
101 // also the browser's once, at which point we're guaranteed to have updated 102 // also the browser's once, at which point we're guaranteed to have updated
102 // the backingstore. Hacky, but it works. 103 // the backingstore. Hacky, but it works.
103 // Note that we need to change the text each time, because if we don't the 104 // Note that we need to change the text each time, because if we don't the
104 // renderer code will think the second message is to go to next result, but 105 // renderer code will think the second message is to go to next result, but
105 // there are none so the plugin will assert. 106 // there are none so the plugin will assert.
106 107
107 string16 query = UTF8ToUTF16( 108 string16 query = UTF8ToUTF16(
108 std::string("xyzxyz" + base::IntToString(next_dummy_search_value_++))); 109 std::string("xyzxyz" + base::IntToString(next_dummy_search_value_++)));
109 ASSERT_EQ(0, ui_test_utils::FindInPage( 110 ASSERT_EQ(0, ui_test_utils::FindInPage(
110 browser()->GetActiveTabContents(), query, true, false, NULL)); 111 chrome::GetActiveTabContents(browser()), query, true, false, NULL));
111 } 112 }
112 113
113 private: 114 private:
114 // content::NotificationObserver 115 // content::NotificationObserver
115 virtual void Observe(int type, 116 virtual void Observe(int type,
116 const content::NotificationSource& source, 117 const content::NotificationSource& source,
117 const content::NotificationDetails& details) { 118 const content::NotificationDetails& details) {
118 if (type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN) { 119 if (type == chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN) {
119 MessageLoopForUI::current()->Quit(); 120 MessageLoopForUI::current()->Quit();
120 FilePath reference = ui_test_utils::GetTestFilePath( 121 FilePath reference = ui_test_utils::GetTestFilePath(
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) { 231 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_Scroll) {
231 ASSERT_NO_FATAL_FAILURE(Load()); 232 ASSERT_NO_FATAL_FAILURE(Load());
232 233
233 // We use wheel mouse event since that's the only one we can easily push to 234 // We use wheel mouse event since that's the only one we can easily push to
234 // the renderer. There's no way to push a cross-platform keyboard event at 235 // the renderer. There's no way to push a cross-platform keyboard event at
235 // the moment. 236 // the moment.
236 WebKit::WebMouseWheelEvent wheel_event; 237 WebKit::WebMouseWheelEvent wheel_event;
237 wheel_event.type = WebKit::WebInputEvent::MouseWheel; 238 wheel_event.type = WebKit::WebInputEvent::MouseWheel;
238 wheel_event.deltaY = -200; 239 wheel_event.deltaY = -200;
239 wheel_event.wheelTicksY = -2; 240 wheel_event.wheelTicksY = -2;
240 WebContents* web_contents = browser()->GetActiveWebContents(); 241 WebContents* web_contents = chrome::GetActiveWebContents(browser());
241 web_contents->GetRenderViewHost()->ForwardWheelEvent(wheel_event); 242 web_contents->GetRenderViewHost()->ForwardWheelEvent(wheel_event);
242 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); 243 ASSERT_NO_FATAL_FAILURE(WaitForResponse());
243 244
244 int y_offset = 0; 245 int y_offset = 0;
245 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( 246 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt(
246 browser()->GetActiveWebContents()->GetRenderViewHost(), 247 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
247 std::wstring(), 248 std::wstring(),
248 L"window.domAutomationController.send(plugin.pageYOffset())", 249 L"window.domAutomationController.send(plugin.pageYOffset())",
249 &y_offset)); 250 &y_offset));
250 ASSERT_GT(y_offset, 0); 251 ASSERT_GT(y_offset, 0);
251 } 252 }
252 253
253 #if defined(OS_CHROMEOS) 254 #if defined(OS_CHROMEOS)
254 // TODO(sanjeevr): http://crbug.com/79837 255 // TODO(sanjeevr): http://crbug.com/79837
255 #define MAYBE_FindAndCopy DISABLED_FindAndCopy 256 #define MAYBE_FindAndCopy DISABLED_FindAndCopy
256 #else 257 #else
257 #define MAYBE_FindAndCopy FindAndCopy 258 #define MAYBE_FindAndCopy FindAndCopy
258 #endif 259 #endif
259 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) { 260 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, MAYBE_FindAndCopy) {
260 ASSERT_NO_FATAL_FAILURE(Load()); 261 ASSERT_NO_FATAL_FAILURE(Load());
261 // Verifies that find in page works. 262 // Verifies that find in page works.
262 ASSERT_EQ(3, ui_test_utils::FindInPage( 263 ASSERT_EQ(3, ui_test_utils::FindInPage(
263 browser()->GetActiveTabContents(), UTF8ToUTF16("adipiscing"), 264 chrome::GetActiveTabContents(browser()), UTF8ToUTF16("adipiscing"),
264 true, false, NULL)); 265 true, false, NULL));
265 266
266 // Verify that copying selected text works. 267 // Verify that copying selected text works.
267 ui::Clipboard clipboard; 268 ui::Clipboard clipboard;
268 // Reset the clipboard first. 269 // Reset the clipboard first.
269 ui::Clipboard::ObjectMap objects; 270 ui::Clipboard::ObjectMap objects;
270 ui::Clipboard::ObjectMapParams params; 271 ui::Clipboard::ObjectMapParams params;
271 params.push_back(std::vector<char>()); 272 params.push_back(std::vector<char>());
272 objects[ui::Clipboard::CBF_TEXT] = params; 273 objects[ui::Clipboard::CBF_TEXT] = params;
273 clipboard.WriteObjects(ui::Clipboard::BUFFER_STANDARD, objects); 274 clipboard.WriteObjects(ui::Clipboard::BUFFER_STANDARD, objects);
274 275
275 browser()->GetActiveWebContents()->GetRenderViewHost()->Copy(); 276 chrome::GetActiveWebContents(browser())->GetRenderViewHost()->Copy();
276 ASSERT_NO_FATAL_FAILURE(WaitForResponse()); 277 ASSERT_NO_FATAL_FAILURE(WaitForResponse());
277 278
278 std::string text; 279 std::string text;
279 clipboard.ReadAsciiText(ui::Clipboard::BUFFER_STANDARD, &text); 280 clipboard.ReadAsciiText(ui::Clipboard::BUFFER_STANDARD, &text);
280 ASSERT_EQ("adipiscing", text); 281 ASSERT_EQ("adipiscing", text);
281 } 282 }
282 283
283 // 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).
284 // 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
285 // regressions. 286 // regressions.
286 // If it flakes, reopen http://crbug.com/74548. 287 // If it flakes, reopen http://crbug.com/74548.
287 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, SLOW_Loading) { 288 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, SLOW_Loading) {
288 ASSERT_TRUE(pdf_test_server()->Start()); 289 ASSERT_TRUE(pdf_test_server()->Start());
289 290
290 NavigationController* controller = 291 NavigationController* controller =
291 &(browser()->GetActiveWebContents()->GetController()); 292 &(chrome::GetActiveWebContents(browser())->GetController());
292 content::NotificationRegistrar registrar; 293 content::NotificationRegistrar registrar;
293 registrar.Add(this, 294 registrar.Add(this,
294 content::NOTIFICATION_LOAD_STOP, 295 content::NOTIFICATION_LOAD_STOP,
295 content::Source<NavigationController>(controller)); 296 content::Source<NavigationController>(controller));
296 std::string base_url = std::string("files/"); 297 std::string base_url = std::string("files/");
297 298
298 file_util::FileEnumerator file_enumerator( 299 file_util::FileEnumerator file_enumerator(
299 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()), 300 ui_test_utils::GetTestFilePath(GetPDFTestDir(), FilePath()),
300 false, 301 false,
301 file_util::FileEnumerator::FILES, 302 file_util::FileEnumerator::FILES,
(...skipping 14 matching lines...) Expand all
316 GURL url = pdf_test_server()->GetURL(base_url + filename); 317 GURL url = pdf_test_server()->GetURL(base_url + filename);
317 ui_test_utils::NavigateToURL(browser(), url); 318 ui_test_utils::NavigateToURL(browser(), url);
318 319
319 while (true) { 320 while (true) {
320 int last_count = load_stop_notification_count(); 321 int last_count = load_stop_notification_count();
321 // We might get extraneous chrome::LOAD_STOP notifications when 322 // We might get extraneous chrome::LOAD_STOP notifications when
322 // doing async loading. This happens when the first loader is cancelled 323 // doing async loading. This happens when the first loader is cancelled
323 // and before creating a byte-range request loader. 324 // and before creating a byte-range request loader.
324 bool complete = false; 325 bool complete = false;
325 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 326 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
326 browser()->GetActiveWebContents()->GetRenderViewHost(), 327 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
327 std::wstring(), 328 std::wstring(),
328 L"window.domAutomationController.send(plugin.documentLoadComplete())", 329 L"window.domAutomationController.send(plugin.documentLoadComplete())",
329 &complete)); 330 &complete));
330 if (complete) 331 if (complete)
331 break; 332 break;
332 333
333 // Check if the LOAD_STOP notification could have come while we run a 334 // Check if the LOAD_STOP notification could have come while we run a
334 // nested message loop for the JS call. 335 // nested message loop for the JS call.
335 if (last_count != load_stop_notification_count()) 336 if (last_count != load_stop_notification_count())
336 continue; 337 continue;
337 ui_test_utils::WaitForLoadStop(browser()->GetActiveWebContents()); 338 ui_test_utils::WaitForLoadStop(chrome::GetActiveWebContents(browser()));
338 } 339 }
339 } 340 }
340 } 341 }
341 342
342 // Flaky as per http://crbug.com/74549. 343 // Flaky as per http://crbug.com/74549.
343 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_OnLoadAndReload) { 344 IN_PROC_BROWSER_TEST_F(PDFBrowserTest, DISABLED_OnLoadAndReload) {
344 ASSERT_TRUE(pdf_test_server()->Start()); 345 ASSERT_TRUE(pdf_test_server()->Start());
345 346
346 GURL url = pdf_test_server()->GetURL("files/onload_reload.html"); 347 GURL url = pdf_test_server()->GetURL("files/onload_reload.html");
347 ui_test_utils::NavigateToURL(browser(), url); 348 ui_test_utils::NavigateToURL(browser(), url);
348 349
349 ui_test_utils::WindowedNotificationObserver observer( 350 ui_test_utils::WindowedNotificationObserver observer(
350 content::NOTIFICATION_LOAD_STOP, 351 content::NOTIFICATION_LOAD_STOP,
351 content::Source<NavigationController>( 352 content::Source<NavigationController>(
352 &browser()->GetActiveWebContents()->GetController())); 353 &chrome::GetActiveWebContents(browser())->GetController()));
353 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 354 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript(
354 browser()->GetActiveWebContents()->GetRenderViewHost(), 355 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
355 std::wstring(), 356 std::wstring(),
356 L"reloadPDF();")); 357 L"reloadPDF();"));
357 observer.Wait(); 358 observer.Wait();
358 359
359 ASSERT_EQ("success", browser()->GetActiveWebContents()->GetURL().query()); 360 ASSERT_EQ("success",
361 chrome::GetActiveWebContents(browser())->GetURL().query());
360 } 362 }
361 363
362 } // namespace 364 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/ui/panels/panel_browsertest.cc ('k') | chrome/browser/ui/search/search_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698