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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 entry = NavigationEntryImpl::FromNavigationEntry( | 438 entry = NavigationEntryImpl::FromNavigationEntry( |
439 web_contents->GetController().GetEntryAtIndex(3)); | 439 web_contents->GetController().GetEntryAtIndex(3)); |
440 EXPECT_FALSE(entry->screenshot().get()); | 440 EXPECT_FALSE(entry->screenshot().get()); |
441 { | 441 { |
442 // Now, swipe right to navigate backwards. This should navigate away from | 442 // Now, swipe right to navigate backwards. This should navigate away from |
443 // index 3 to index 2. | 443 // index 3 to index 2. |
444 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); | 444 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); |
445 content::TitleWatcher title_watcher(web_contents, expected_title); | 445 content::TitleWatcher title_watcher(web_contents, expected_title); |
446 aura::Window* content = web_contents->GetContentNativeView(); | 446 aura::Window* content = web_contents->GetContentNativeView(); |
447 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 447 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
448 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 448 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
449 generator.GestureScrollSequence( | 449 generator.GestureScrollSequence( |
450 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 450 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
451 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 451 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
452 base::TimeDelta::FromMilliseconds(20), | 452 base::TimeDelta::FromMilliseconds(20), |
453 1); | 453 1); |
454 base::string16 actual_title = title_watcher.WaitAndGetTitle(); | 454 base::string16 actual_title = title_watcher.WaitAndGetTitle(); |
455 EXPECT_EQ(expected_title, actual_title); | 455 EXPECT_EQ(expected_title, actual_title); |
456 EXPECT_EQ(2, GetCurrentIndex()); | 456 EXPECT_EQ(2, GetCurrentIndex()); |
457 screenshot_manager()->WaitUntilScreenshotIsReady(); | 457 screenshot_manager()->WaitUntilScreenshotIsReady(); |
458 entry = NavigationEntryImpl::FromNavigationEntry( | 458 entry = NavigationEntryImpl::FromNavigationEntry( |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 611 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
612 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 612 window->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
613 | 613 |
614 WebContentsImpl* web_contents = | 614 WebContentsImpl* web_contents = |
615 static_cast<WebContentsImpl*>(shell()->web_contents()); | 615 static_cast<WebContentsImpl*>(shell()->web_contents()); |
616 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); | 616 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); |
617 EXPECT_EQ(1, GetCurrentIndex()); | 617 EXPECT_EQ(1, GetCurrentIndex()); |
618 | 618 |
619 aura::Window* content = web_contents->GetContentNativeView(); | 619 aura::Window* content = web_contents->GetContentNativeView(); |
620 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 620 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
621 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 621 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
622 generator.GestureScrollSequence( | 622 generator.GestureScrollSequence( |
623 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 623 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
624 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 624 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
625 base::TimeDelta::FromMilliseconds(20), | 625 base::TimeDelta::FromMilliseconds(20), |
626 1); | 626 1); |
627 | 627 |
628 window->AddChild(shell()->web_contents()->GetContentNativeView()); | 628 window->AddChild(shell()->web_contents()->GetContentNativeView()); |
629 } | 629 } |
630 | 630 |
631 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ContentWindowClose) { | 631 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, ContentWindowClose) { |
632 ASSERT_NO_FATAL_FAILURE( | 632 ASSERT_NO_FATAL_FAILURE( |
633 StartTestWithPage("files/overscroll_navigation.html")); | 633 StartTestWithPage("files/overscroll_navigation.html")); |
634 | 634 |
635 WebContentsImpl* web_contents = | 635 WebContentsImpl* web_contents = |
636 static_cast<WebContentsImpl*>(shell()->web_contents()); | 636 static_cast<WebContentsImpl*>(shell()->web_contents()); |
637 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); | 637 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); |
638 EXPECT_EQ(1, GetCurrentIndex()); | 638 EXPECT_EQ(1, GetCurrentIndex()); |
639 | 639 |
640 aura::Window* content = web_contents->GetContentNativeView(); | 640 aura::Window* content = web_contents->GetContentNativeView(); |
641 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 641 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
642 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 642 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
643 generator.GestureScrollSequence( | 643 generator.GestureScrollSequence( |
644 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 644 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
645 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 645 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
646 base::TimeDelta::FromMilliseconds(20), | 646 base::TimeDelta::FromMilliseconds(20), |
647 1); | 647 1); |
648 | 648 |
649 delete web_contents->GetContentNativeView(); | 649 delete web_contents->GetContentNativeView(); |
650 } | 650 } |
651 | 651 |
652 | 652 |
(...skipping 27 matching lines...) Expand all Loading... |
680 | 680 |
681 web_contents->GetController().GoBack(); | 681 web_contents->GetController().GoBack(); |
682 WaitForLoadStop(web_contents); | 682 WaitForLoadStop(web_contents); |
683 EXPECT_EQ(1, GetCurrentIndex()); | 683 EXPECT_EQ(1, GetCurrentIndex()); |
684 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); | 684 EXPECT_EQ(base::ASCIIToUTF16("Title: #1"), web_contents->GetTitle()); |
685 EXPECT_TRUE(controller.CanGoBack()); | 685 EXPECT_TRUE(controller.CanGoBack()); |
686 EXPECT_TRUE(controller.CanGoForward()); | 686 EXPECT_TRUE(controller.CanGoForward()); |
687 | 687 |
688 aura::Window* content = web_contents->GetContentNativeView(); | 688 aura::Window* content = web_contents->GetContentNativeView(); |
689 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 689 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
690 aura::test::EventGenerator generator(content->GetRootWindow(), content); | 690 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
691 | 691 |
692 // Do a swipe left to start a forward navigation. Then quickly do a swipe | 692 // Do a swipe left to start a forward navigation. Then quickly do a swipe |
693 // right. | 693 // right. |
694 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); | 694 base::string16 expected_title = base::ASCIIToUTF16("Title: #2"); |
695 content::TitleWatcher title_watcher(web_contents, expected_title); | 695 content::TitleWatcher title_watcher(web_contents, expected_title); |
696 NavigationWatcher nav_watcher(web_contents); | 696 NavigationWatcher nav_watcher(web_contents); |
697 | 697 |
698 generator.GestureScrollSequence( | 698 generator.GestureScrollSequence( |
699 gfx::Point(bounds.right() - 10, bounds.y() + 10), | 699 gfx::Point(bounds.right() - 10, bounds.y() + 10), |
700 gfx::Point(bounds.x() + 2, bounds.y() + 10), | 700 gfx::Point(bounds.x() + 2, bounds.y() + 10), |
(...skipping 21 matching lines...) Expand all Loading... |
722 static_cast<WebContentsImpl*>(shell()->web_contents()); | 722 static_cast<WebContentsImpl*>(shell()->web_contents()); |
723 aura::Window* content = web_contents->GetNativeView()->parent(); | 723 aura::Window* content = web_contents->GetNativeView()->parent(); |
724 EXPECT_TRUE(web_contents->should_normally_be_visible()); | 724 EXPECT_TRUE(web_contents->should_normally_be_visible()); |
725 content->Hide(); | 725 content->Hide(); |
726 EXPECT_FALSE(web_contents->should_normally_be_visible()); | 726 EXPECT_FALSE(web_contents->should_normally_be_visible()); |
727 content->Show(); | 727 content->Show(); |
728 EXPECT_TRUE(web_contents->should_normally_be_visible()); | 728 EXPECT_TRUE(web_contents->should_normally_be_visible()); |
729 } | 729 } |
730 | 730 |
731 } // namespace content | 731 } // namespace content |
OLD | NEW |