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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
13 #include "base/win/windows_version.h" | 13 #include "base/win/windows_version.h" |
14 #endif | 14 #endif |
15 #include "content/browser/frame_host/navigation_controller_impl.h" | 15 #include "content/browser/frame_host/navigation_controller_impl.h" |
16 #include "content/browser/frame_host/navigation_entry_impl.h" | 16 #include "content/browser/frame_host/navigation_entry_impl.h" |
17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" | 17 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
18 #include "content/browser/web_contents/web_contents_impl.h" | 18 #include "content/browser/web_contents/web_contents_impl.h" |
19 #include "content/browser/web_contents/web_contents_view.h" | 19 #include "content/browser/web_contents/web_contents_view.h" |
20 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
21 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
22 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "content/public/test/browser_test_utils.h" | 24 #include "content/public/test/browser_test_utils.h" |
25 #include "content/public/test/content_browser_test.h" | 25 #include "content/public/test/content_browser_test.h" |
26 #include "content/public/test/content_browser_test_utils.h" | 26 #include "content/public/test/content_browser_test_utils.h" |
27 #include "content/public/test/test_renderer_host.h" | 27 #include "content/public/test/test_renderer_host.h" |
28 #include "content/public/test/test_utils.h" | 28 #include "content/public/test/test_utils.h" |
29 #include "content/shell/browser/shell.h" | 29 #include "content/shell/browser/shell.h" |
30 #include "ui/aura/test/event_generator.h" | |
31 #include "ui/aura/window.h" | 30 #include "ui/aura/window.h" |
32 #include "ui/aura/window_tree_host.h" | 31 #include "ui/aura/window_tree_host.h" |
33 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 32 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
34 #include "ui/events/event_processor.h" | 33 #include "ui/events/event_processor.h" |
35 #include "ui/events/event_utils.h" | 34 #include "ui/events/event_utils.h" |
| 35 #include "ui/events/test/event_generator.h" |
36 | 36 |
37 namespace content { | 37 namespace content { |
38 | 38 |
39 // This class keeps track of the RenderViewHost whose screenshot was captured. | 39 // This class keeps track of the RenderViewHost whose screenshot was captured. |
40 class ScreenshotTracker : public NavigationEntryScreenshotManager { | 40 class ScreenshotTracker : public NavigationEntryScreenshotManager { |
41 public: | 41 public: |
42 explicit ScreenshotTracker(NavigationControllerImpl* controller) | 42 explicit ScreenshotTracker(NavigationControllerImpl* controller) |
43 : NavigationEntryScreenshotManager(controller), | 43 : NavigationEntryScreenshotManager(controller), |
44 screenshot_taken_for_(NULL), | 44 screenshot_taken_for_(NULL), |
45 waiting_for_screenshots_(0) { | 45 waiting_for_screenshots_(0) { |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 177 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
178 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 178 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
179 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); | 179 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); |
180 ASSERT_TRUE(value->GetAsInteger(&index)); | 180 ASSERT_TRUE(value->GetAsInteger(&index)); |
181 EXPECT_EQ(2, index); | 181 EXPECT_EQ(2, index); |
182 EXPECT_TRUE(controller.CanGoBack()); | 182 EXPECT_TRUE(controller.CanGoBack()); |
183 EXPECT_FALSE(controller.CanGoForward()); | 183 EXPECT_FALSE(controller.CanGoForward()); |
184 | 184 |
185 aura::Window* content = web_contents->GetContentNativeView(); | 185 aura::Window* content = web_contents->GetContentNativeView(); |
186 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 186 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
187 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 187 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
188 const int kScrollDurationMs = 20; | 188 const int kScrollDurationMs = 20; |
189 const int kScrollSteps = 10; | 189 const int kScrollSteps = 10; |
190 | 190 |
191 { | 191 { |
192 // Do a swipe-right now. That should navigate backwards. | 192 // Do a swipe-right now. That should navigate backwards. |
193 base::string16 expected_title = base::ASCIIToUTF16("Title: #1"); | 193 base::string16 expected_title = base::ASCIIToUTF16("Title: #1"); |
194 content::TitleWatcher title_watcher(web_contents, expected_title); | 194 content::TitleWatcher title_watcher(web_contents, expected_title); |
195 generator.GestureScrollSequence( | 195 generator.GestureScrollSequence( |
196 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 196 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
197 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 197 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 web_contents->GetController().GetEntryAtIndex(3)); | 441 web_contents->GetController().GetEntryAtIndex(3)); |
442 EXPECT_FALSE(entry->screenshot().get()); | 442 EXPECT_FALSE(entry->screenshot().get()); |
443 | 443 |
444 { | 444 { |
445 // Now, swipe right to navigate backwards. This should navigate away from | 445 // Now, swipe right to navigate backwards. This should navigate away from |
446 // index 3 to index 2, and index 3 should have a screenshot. | 446 // index 3 to index 2, and index 3 should have a screenshot. |
447 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); | 447 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); |
448 content::TitleWatcher title_watcher(web_contents, expected_title); | 448 content::TitleWatcher title_watcher(web_contents, expected_title); |
449 aura::Window* content = web_contents->GetContentNativeView(); | 449 aura::Window* content = web_contents->GetContentNativeView(); |
450 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 450 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
451 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 451 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
452 generator.GestureScrollSequence( | 452 generator.GestureScrollSequence( |
453 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 453 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
454 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 454 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
455 base::TimeDelta::FromMilliseconds(20), | 455 base::TimeDelta::FromMilliseconds(20), |
456 1); | 456 1); |
457 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 457 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
458 EXPECT_EQ(expected_title, actual_title); | 458 EXPECT_EQ(expected_title, actual_title); |
459 EXPECT_EQ(2, GetCurrentIndex()); | 459 EXPECT_EQ(2, GetCurrentIndex()); |
460 screenshot_manager()->WaitUntilScreenshotIsReady(); | 460 screenshot_manager()->WaitUntilScreenshotIsReady(); |
461 entry = NavigationEntryImpl::FromNavigationEntry( | 461 entry = NavigationEntryImpl::FromNavigationEntry( |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 609 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
610 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 610 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
611 | 611 |
612 WebContentsImpl* web_contents = | 612 WebContentsImpl* web_contents = |
613 static_cast<WebContentsImpl*>(shell()->web_contents()); | 613 static_cast<WebContentsImpl*>(shell()->web_contents()); |
614 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); | 614 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); |
615 EXPECT_EQ(1, GetCurrentIndex()); | 615 EXPECT_EQ(1, GetCurrentIndex()); |
616 | 616 |
617 aura::Window* content = web_contents->GetContentNativeView(); | 617 aura::Window* content = web_contents->GetContentNativeView(); |
618 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 618 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
619 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 619 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
620 generator.GestureScrollSequence( | 620 generator.GestureScrollSequence( |
621 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 621 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
622 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 622 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
623 base::TimeDelta::FromMilliseconds(20), | 623 base::TimeDelta::FromMilliseconds(20), |
624 1); | 624 1); |
625 | 625 |
626 window->AddChild(shell()->web_contents()->GetContentNativeView()); | 626 window->AddChild(shell()->web_contents()->GetContentNativeView()); |
627 } | 627 } |
628 | 628 |
629 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ContentWindowClose) { | 629 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ContentWindowClose) { |
630 ASSERT_NO_FATAL_FAILURE( | 630 ASSERT_NO_FATAL_FAILURE( |
631 StartTestWithPage("files/overscroll_navigation.html")); | 631 StartTestWithPage("files/overscroll_navigation.html")); |
632 | 632 |
633 WebContentsImpl* web_contents = | 633 WebContentsImpl* web_contents = |
634 static_cast<WebContentsImpl*>(shell()->web_contents()); | 634 static_cast<WebContentsImpl*>(shell()->web_contents()); |
635 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); | 635 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); |
636 EXPECT_EQ(1, GetCurrentIndex()); | 636 EXPECT_EQ(1, GetCurrentIndex()); |
637 | 637 |
638 aura::Window* content = web_contents->GetContentNativeView(); | 638 aura::Window* content = web_contents->GetContentNativeView(); |
639 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 639 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
640 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 640 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
641 generator.GestureScrollSequence( | 641 generator.GestureScrollSequence( |
642 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 642 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
643 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 643 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
644 base::TimeDelta::FromMilliseconds(20), | 644 base::TimeDelta::FromMilliseconds(20), |
645 1); | 645 1); |
646 | 646 |
647 delete web_contents->GetContentNativeView(); | 647 delete web_contents->GetContentNativeView(); |
648 } | 648 } |
649 | 649 |
650 | 650 |
(...skipping 27 matching lines...) Expand all Loading... |
678 | 678 |
679 web_contents->GetController().GoBack(); | 679 web_contents->GetController().GoBack(); |
680 WaitForLoadStop(web_contents); | 680 WaitForLoadStop(web_contents); |
681 EXPECT_EQ(1, GetCurrentIndex()); | 681 EXPECT_EQ(1, GetCurrentIndex()); |
682 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); | 682 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); |
683 EXPECT_TRUE(controller.CanGoBack()); | 683 EXPECT_TRUE(controller.CanGoBack()); |
684 EXPECT_TRUE(controller.CanGoForward()); | 684 EXPECT_TRUE(controller.CanGoForward()); |
685 | 685 |
686 aura::Window* content = web_contents->GetContentNativeView(); | 686 aura::Window* content = web_contents->GetContentNativeView(); |
687 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 687 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
688 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 688 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
689 | 689 |
690 // Do a swipe left to start a forward navigation. Then quickly do a swipe | 690 // Do a swipe left to start a forward navigation. Then quickly do a swipe |
691 // right. | 691 // right. |
692 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); | 692 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); |
693 content::TitleWatcher title_watcher(web_contents, expected_title); | 693 content::TitleWatcher title_watcher(web_contents, expected_title); |
694 NavigationWatcher nav_watcher(web_contents); | 694 NavigationWatcher nav_watcher(web_contents); |
695 | 695 |
696 generator.GestureScrollSequence( | 696 generator.GestureScrollSequence( |
697 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 697 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
698 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 698 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
(...skipping 21 matching lines...) Expand all Loading... |
720 static_cast<WebContentsImpl*>(shell()->web_contents()); | 720 static_cast<WebContentsImpl*>(shell()->web_contents()); |
721 aura::Window* content = web_contents->GetNativeView()->parent(); | 721 aura::Window* content = web_contents->GetNativeView()->parent(); |
722 EXPECT_TRUE(web_contents->should_normally_be_visible()); | 722 EXPECT_TRUE(web_contents->should_normally_be_visible()); |
723 content->Hide(); | 723 content->Hide(); |
724 EXPECT_FALSE(web_contents->should_normally_be_visible()); | 724 EXPECT_FALSE(web_contents->should_normally_be_visible()); |
725 content->Show(); | 725 content->Show(); |
726 EXPECT_TRUE(web_contents->should_normally_be_visible()); | 726 EXPECT_TRUE(web_contents->should_normally_be_visible()); |
727 } | 727 } |
728 | 728 |
729 } // namespace content | 729 } // namespace content |
OLD | NEW |