| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" |
| 12 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/test/test_timeouts.h" | 16 #include "base/test/test_timeouts.h" |
| 16 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 19 #include "content/browser/frame_host/navigation_controller_impl.h" | 20 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 20 #include "content/browser/frame_host/navigation_entry_impl.h" | 21 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 21 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" | 22 #include "content/browser/frame_host/navigation_entry_screenshot_manager.h" |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 242 |
| 242 class WebContentsViewAuraTest : public ContentBrowserTest { | 243 class WebContentsViewAuraTest : public ContentBrowserTest { |
| 243 public: | 244 public: |
| 244 WebContentsViewAuraTest() | 245 WebContentsViewAuraTest() |
| 245 : screenshot_manager_(NULL) { | 246 : screenshot_manager_(NULL) { |
| 246 } | 247 } |
| 247 | 248 |
| 248 // Executes the javascript synchronously and makes sure the returned value is | 249 // Executes the javascript synchronously and makes sure the returned value is |
| 249 // freed properly. | 250 // freed properly. |
| 250 void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) { | 251 void ExecuteSyncJSFunction(RenderFrameHost* rfh, const std::string& jscript) { |
| 251 scoped_ptr<base::Value> value = | 252 std::unique_ptr<base::Value> value = |
| 252 content::ExecuteScriptAndGetValue(rfh, jscript); | 253 content::ExecuteScriptAndGetValue(rfh, jscript); |
| 253 } | 254 } |
| 254 | 255 |
| 255 // Starts the test server and navigates to the given url. Sets a large enough | 256 // Starts the test server and navigates to the given url. Sets a large enough |
| 256 // size to the root window. Returns after the navigation to the url is | 257 // size to the root window. Returns after the navigation to the url is |
| 257 // complete. | 258 // complete. |
| 258 void StartTestWithPage(const std::string& url) { | 259 void StartTestWithPage(const std::string& url) { |
| 259 ASSERT_TRUE(embedded_test_server()->Start()); | 260 ASSERT_TRUE(embedded_test_server()->Start()); |
| 260 GURL test_url; | 261 GURL test_url; |
| 261 if (url == "about:blank") | 262 if (url == "about:blank") |
| 262 test_url = GURL(url); | 263 test_url = GURL(url); |
| 263 else | 264 else |
| 264 test_url = GURL(embedded_test_server()->GetURL(url)); | 265 test_url = GURL(embedded_test_server()->GetURL(url)); |
| 265 NavigateToURL(shell(), test_url); | 266 NavigateToURL(shell(), test_url); |
| 266 | 267 |
| 267 WebContentsImpl* web_contents = | 268 WebContentsImpl* web_contents = |
| 268 static_cast<WebContentsImpl*>(shell()->web_contents()); | 269 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 269 NavigationControllerImpl* controller = &web_contents->GetController(); | 270 NavigationControllerImpl* controller = &web_contents->GetController(); |
| 270 | 271 |
| 271 screenshot_manager_ = new ScreenshotTracker(controller); | 272 screenshot_manager_ = new ScreenshotTracker(controller); |
| 272 controller->SetScreenshotManager(make_scoped_ptr(screenshot_manager_)); | 273 controller->SetScreenshotManager(base::WrapUnique(screenshot_manager_)); |
| 273 | 274 |
| 274 frame_watcher_ = new FrameWatcher(); | 275 frame_watcher_ = new FrameWatcher(); |
| 275 frame_watcher_->AttachTo(shell()->web_contents()); | 276 frame_watcher_->AttachTo(shell()->web_contents()); |
| 276 } | 277 } |
| 277 | 278 |
| 278 void SetUpCommandLine(base::CommandLine* cmd) override { | 279 void SetUpCommandLine(base::CommandLine* cmd) override { |
| 279 cmd->AppendSwitchASCII(switches::kTouchEvents, | 280 cmd->AppendSwitchASCII(switches::kTouchEvents, |
| 280 switches::kTouchEventsEnabled); | 281 switches::kTouchEventsEnabled); |
| 281 } | 282 } |
| 282 | 283 |
| 283 void TestOverscrollNavigation(bool touch_handler) { | 284 void TestOverscrollNavigation(bool touch_handler) { |
| 284 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/overscroll_navigation.html")); | 285 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/overscroll_navigation.html")); |
| 285 WebContentsImpl* web_contents = | 286 WebContentsImpl* web_contents = |
| 286 static_cast<WebContentsImpl*>(shell()->web_contents()); | 287 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 287 NavigationController& controller = web_contents->GetController(); | 288 NavigationController& controller = web_contents->GetController(); |
| 288 RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 289 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 289 | 290 |
| 290 EXPECT_FALSE(controller.CanGoBack()); | 291 EXPECT_FALSE(controller.CanGoBack()); |
| 291 EXPECT_FALSE(controller.CanGoForward()); | 292 EXPECT_FALSE(controller.CanGoForward()); |
| 292 int index = -1; | 293 int index = -1; |
| 293 scoped_ptr<base::Value> value = | 294 std::unique_ptr<base::Value> value = |
| 294 content::ExecuteScriptAndGetValue(main_frame, "get_current()"); | 295 content::ExecuteScriptAndGetValue(main_frame, "get_current()"); |
| 295 ASSERT_TRUE(value->GetAsInteger(&index)); | 296 ASSERT_TRUE(value->GetAsInteger(&index)); |
| 296 EXPECT_EQ(0, index); | 297 EXPECT_EQ(0, index); |
| 297 | 298 |
| 298 if (touch_handler) | 299 if (touch_handler) |
| 299 ExecuteSyncJSFunction(main_frame, "install_touch_handler()"); | 300 ExecuteSyncJSFunction(main_frame, "install_touch_handler()"); |
| 300 | 301 |
| 301 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 302 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
| 302 ExecuteSyncJSFunction(main_frame, "navigate_next()"); | 303 ExecuteSyncJSFunction(main_frame, "navigate_next()"); |
| 303 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); | 304 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 EXPECT_TRUE(controller.CanGoBack()); | 366 EXPECT_TRUE(controller.CanGoBack()); |
| 366 EXPECT_TRUE(controller.CanGoForward()); | 367 EXPECT_TRUE(controller.CanGoForward()); |
| 367 } | 368 } |
| 368 } | 369 } |
| 369 | 370 |
| 370 int GetCurrentIndex() { | 371 int GetCurrentIndex() { |
| 371 WebContentsImpl* web_contents = | 372 WebContentsImpl* web_contents = |
| 372 static_cast<WebContentsImpl*>(shell()->web_contents()); | 373 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 373 RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 374 RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
| 374 int index = -1; | 375 int index = -1; |
| 375 scoped_ptr<base::Value> value; | 376 std::unique_ptr<base::Value> value; |
| 376 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); | 377 value = content::ExecuteScriptAndGetValue(main_frame, "get_current()"); |
| 377 if (!value->GetAsInteger(&index)) | 378 if (!value->GetAsInteger(&index)) |
| 378 index = -1; | 379 index = -1; |
| 379 return index; | 380 return index; |
| 380 } | 381 } |
| 381 | 382 |
| 382 int ExecuteScriptAndExtractInt(const std::string& script) { | 383 int ExecuteScriptAndExtractInt(const std::string& script) { |
| 383 int value = 0; | 384 int value = 0; |
| 384 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( | 385 EXPECT_TRUE(content::ExecuteScriptAndExtractInt( |
| 385 shell()->web_contents(), | 386 shell()->web_contents(), |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 // FocusController does not support. This code would crash in | 759 // FocusController does not support. This code would crash in |
| 759 // a production build. It only passed prior to this revision | 760 // a production build. It only passed prior to this revision |
| 760 // because testing used the old FocusManager which did some | 761 // because testing used the old FocusManager which did some |
| 761 // different (osbolete) processing. TODO(sadrul) to figure out | 762 // different (osbolete) processing. TODO(sadrul) to figure out |
| 762 // how this test should work that mimics production code a bit | 763 // how this test should work that mimics production code a bit |
| 763 // better. | 764 // better. |
| 764 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, | 765 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, |
| 765 DISABLED_ContentWindowReparent) { | 766 DISABLED_ContentWindowReparent) { |
| 766 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/overscroll_navigation.html")); | 767 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/overscroll_navigation.html")); |
| 767 | 768 |
| 768 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 769 std::unique_ptr<aura::Window> window(new aura::Window(NULL)); |
| 769 window->Init(ui::LAYER_NOT_DRAWN); | 770 window->Init(ui::LAYER_NOT_DRAWN); |
| 770 | 771 |
| 771 WebContentsImpl* web_contents = | 772 WebContentsImpl* web_contents = |
| 772 static_cast<WebContentsImpl*>(shell()->web_contents()); | 773 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 773 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); | 774 ExecuteSyncJSFunction(web_contents->GetMainFrame(), "navigate_next()"); |
| 774 EXPECT_EQ(1, GetCurrentIndex()); | 775 EXPECT_EQ(1, GetCurrentIndex()); |
| 775 | 776 |
| 776 aura::Window* content = web_contents->GetContentNativeView(); | 777 aura::Window* content = web_contents->GetContentNativeView(); |
| 777 gfx::Rect bounds = content->GetBoundsInRootWindow(); | 778 gfx::Rect bounds = content->GetBoundsInRootWindow(); |
| 778 ui::test::EventGenerator generator(content->GetRootWindow(), content); | 779 ui::test::EventGenerator generator(content->GetRootWindow(), content); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 881 EXPECT_FALSE(web_contents->should_normally_be_visible()); | 882 EXPECT_FALSE(web_contents->should_normally_be_visible()); |
| 882 content->Show(); | 883 content->Show(); |
| 883 EXPECT_TRUE(web_contents->should_normally_be_visible()); | 884 EXPECT_TRUE(web_contents->should_normally_be_visible()); |
| 884 } | 885 } |
| 885 | 886 |
| 886 // Ensure that SnapToPhysicalPixelBoundary() is called on WebContentsView parent | 887 // Ensure that SnapToPhysicalPixelBoundary() is called on WebContentsView parent |
| 887 // change. This is a regression test for http://crbug.com/388908. | 888 // change. This is a regression test for http://crbug.com/388908. |
| 888 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, WebContentsViewReparent) { | 889 IN_PROC_BROWSER_TEST_F(WebContentsViewAuraTest, WebContentsViewReparent) { |
| 889 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/overscroll_navigation.html")); | 890 ASSERT_NO_FATAL_FAILURE(StartTestWithPage("/overscroll_navigation.html")); |
| 890 | 891 |
| 891 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 892 std::unique_ptr<aura::Window> window(new aura::Window(NULL)); |
| 892 window->Init(ui::LAYER_NOT_DRAWN); | 893 window->Init(ui::LAYER_NOT_DRAWN); |
| 893 | 894 |
| 894 RenderWidgetHostViewAura* rwhva = | 895 RenderWidgetHostViewAura* rwhva = |
| 895 static_cast<RenderWidgetHostViewAura*>( | 896 static_cast<RenderWidgetHostViewAura*>( |
| 896 shell()->web_contents()->GetRenderWidgetHostView()); | 897 shell()->web_contents()->GetRenderWidgetHostView()); |
| 897 rwhva->ResetHasSnappedToBoundary(); | 898 rwhva->ResetHasSnappedToBoundary(); |
| 898 EXPECT_FALSE(rwhva->has_snapped_to_boundary()); | 899 EXPECT_FALSE(rwhva->has_snapped_to_boundary()); |
| 899 window->AddChild(shell()->web_contents()->GetNativeView()); | 900 window->AddChild(shell()->web_contents()->GetNativeView()); |
| 900 EXPECT_TRUE(rwhva->has_snapped_to_boundary()); | 901 EXPECT_TRUE(rwhva->has_snapped_to_boundary()); |
| 901 } | 902 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 details = dispatcher->OnEventFromSource(&release); | 1127 details = dispatcher->OnEventFromSource(&release); |
| 1127 ASSERT_FALSE(details.dispatcher_destroyed); | 1128 ASSERT_FALSE(details.dispatcher_destroyed); |
| 1128 WaitAFrame(); | 1129 WaitAFrame(); |
| 1129 | 1130 |
| 1130 EXPECT_LT(0, tracker.num_overscroll_updates()); | 1131 EXPECT_LT(0, tracker.num_overscroll_updates()); |
| 1131 EXPECT_FALSE(tracker.overscroll_completed()); | 1132 EXPECT_FALSE(tracker.overscroll_completed()); |
| 1132 } | 1133 } |
| 1133 } | 1134 } |
| 1134 | 1135 |
| 1135 } // namespace content | 1136 } // namespace content |
| OLD | NEW |