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 "content/browser/web_contents/web_contents_view_aura.h" | 5 #include "content/browser/web_contents/web_contents_view_aura.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | 12 #include "content/browser/renderer_host/render_view_host_impl.h" |
13 #include "content/browser/web_contents/navigation_controller_impl.h" | 13 #include "content/browser/web_contents/navigation_controller_impl.h" |
14 #include "content/browser/web_contents/navigation_entry_impl.h" | 14 #include "content/browser/web_contents/navigation_entry_impl.h" |
15 #include "content/browser/web_contents/web_contents_impl.h" | 15 #include "content/browser/web_contents/web_contents_impl.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
18 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
19 #include "content/shell/shell.h" | 19 #include "content/shell/shell.h" |
20 #include "content/test/content_browser_test.h" | 20 #include "content/test/content_browser_test.h" |
21 #include "content/test/content_browser_test_utils.h" | 21 #include "content/test/content_browser_test_utils.h" |
22 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
23 #include "ui/aura/test/event_generator.h" | 23 #include "ui/aura/test/event_generator.h" |
24 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 // A dummy callback to reset the screenshot-taker callback. | |
29 void Dummy(RenderViewHost* host) { | |
Charlie Reis
2013/01/09 23:33:31
nit: DummyCallback
sadrul
2013/01/09 23:37:58
Done.
| |
30 } | |
31 | |
32 // This class keeps track of the RenderViewHost whose screenshot was captured. | |
33 class ScreenshotTracker { | |
34 public: | |
35 explicit ScreenshotTracker(NavigationControllerImpl* controller) | |
36 : screenshot_taken_for_(NULL), | |
37 controller_(controller) { | |
38 controller_->SetTakeScreenshotCallbackForTest( | |
39 base::Bind(&ScreenshotTracker::TakeScreenshotCallback, | |
40 base::Unretained(this))); | |
41 } | |
42 | |
43 virtual ~ScreenshotTracker() { | |
44 controller_->SetTakeScreenshotCallbackForTest( | |
45 base::Bind(&Dummy)); | |
46 } | |
47 | |
48 RenderViewHost* screenshot_taken_for() { return screenshot_taken_for_; } | |
49 | |
50 void Reset() { | |
51 screenshot_taken_for_ = NULL; | |
52 } | |
53 | |
54 private: | |
55 void TakeScreenshotCallback(RenderViewHost* host) { | |
56 screenshot_taken_for_ = host; | |
57 } | |
58 | |
59 RenderViewHost* screenshot_taken_for_; | |
60 NavigationControllerImpl* controller_; | |
61 | |
62 DISALLOW_COPY_AND_ASSIGN(ScreenshotTracker); | |
63 }; | |
64 | |
28 class WebContentsViewAuraTest : public ContentBrowserTest { | 65 class WebContentsViewAuraTest : public ContentBrowserTest { |
29 public: | 66 public: |
30 WebContentsViewAuraTest() {} | 67 WebContentsViewAuraTest() {} |
31 | 68 |
32 virtual void SetUpCommandLine(CommandLine* command_line) { | 69 virtual void SetUpCommandLine(CommandLine* command_line) { |
33 command_line->AppendSwitch(switches::kEnableOverscrollHistoryNavigation); | 70 command_line->AppendSwitch(switches::kEnableOverscrollHistoryNavigation); |
34 } | 71 } |
35 | 72 |
36 // Executes the javascript synchronously and makes sure the returned value is | 73 // Executes the javascript synchronously and makes sure the returned value is |
37 // freed properly. | 74 // freed properly. |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 web_contents->GetController().GoBack(); | 393 web_contents->GetController().GoBack(); |
357 string16 actual_title = title_watcher.WaitAndGetTitle(); | 394 string16 actual_title = title_watcher.WaitAndGetTitle(); |
358 EXPECT_EQ(expected_title, actual_title); | 395 EXPECT_EQ(expected_title, actual_title); |
359 EXPECT_EQ(3, GetCurrentIndex()); | 396 EXPECT_EQ(3, GetCurrentIndex()); |
360 entry = NavigationEntryImpl::FromNavigationEntry( | 397 entry = NavigationEntryImpl::FromNavigationEntry( |
361 web_contents->GetController().GetEntryAtIndex(4)); | 398 web_contents->GetController().GetEntryAtIndex(4)); |
362 EXPECT_TRUE(entry->screenshot().get()); | 399 EXPECT_TRUE(entry->screenshot().get()); |
363 } | 400 } |
364 } | 401 } |
365 | 402 |
403 // Tests that screenshot is taken correct when navigation causes a | |
Charlie Reis
2013/01/09 23:33:31
nit: correctly
sadrul
2013/01/09 23:37:58
Done.
| |
404 // RenderViewHost to be swapped out. | |
405 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, | |
406 ScreenshotForSwappedOutRenderViews) { | |
407 ASSERT_NO_FATAL_FAILURE( | |
408 StartTestWithPage("files/overscroll_navigation.html")); | |
409 // Create a new server with a different site. | |
410 net::TestServer https_server( | |
411 net::TestServer::TYPE_HTTPS, | |
412 net::TestServer::kLocalhost, | |
413 FilePath(FILE_PATH_LITERAL("content/test/data"))); | |
414 ASSERT_TRUE(https_server.Start()); | |
415 | |
416 WebContentsImpl* web_contents = | |
417 static_cast<WebContentsImpl*>(shell()->web_contents()); | |
418 | |
419 struct { | |
420 GURL url; | |
421 int transition; | |
422 } navigations[] = { | |
423 { https_server.GetURL("files/title1.html"), | |
424 PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR }, | |
425 { test_server()->GetURL("files/title2.html"), | |
426 PAGE_TRANSITION_AUTO_BOOKMARK }, | |
427 { https_server.GetURL("files/title3.html"), | |
428 PAGE_TRANSITION_TYPED | PAGE_TRANSITION_FROM_ADDRESS_BAR }, | |
429 { GURL(), 0 } | |
430 }; | |
431 | |
432 ScreenshotTracker tracker(&web_contents->GetController()); | |
433 for (int i = 0; !navigations[i].url.is_empty(); ++i) { | |
434 // Navigate via the user initiating a navigation from the UI. | |
435 NavigationController::LoadURLParams params(navigations[i].url); | |
436 params.transition_type = PageTransitionFromInt(navigations[i].transition); | |
437 | |
438 RenderViewHost* old_host = web_contents->GetRenderViewHost(); | |
439 web_contents->GetController().LoadURLWithParams(params); | |
440 WaitForLoadStop(web_contents); | |
441 | |
442 EXPECT_NE(old_host, web_contents->GetRenderViewHost()) | |
443 << navigations[i].url.spec(); | |
444 EXPECT_EQ(old_host, tracker.screenshot_taken_for()); | |
445 tracker.Reset(); | |
446 | |
447 NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( | |
448 web_contents->GetController().GetEntryAtOffset(-1)); | |
449 EXPECT_TRUE(entry->screenshot().get()); | |
450 | |
451 entry = NavigationEntryImpl::FromNavigationEntry( | |
452 web_contents->GetController().GetActiveEntry()); | |
453 EXPECT_FALSE(entry->screenshot().get()); | |
454 } | |
455 } | |
456 | |
366 } // namespace content | 457 } // namespace content |
OLD | NEW |