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

Side by Side Diff: Source/WebKit/chromium/tests/WebFrameTest.cpp

Issue 13704012: Improve mobile device rotation behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #include "config.h" 31 #include "config.h"
32 32
33 #include "WebFrame.h" 33 #include "WebFrame.h"
34 34
35 #include "DocumentMarkerController.h" 35 #include "DocumentMarkerController.h"
36 #include "FloatRect.h" 36 #include "FloatRect.h"
37 #include "Frame.h" 37 #include "Frame.h"
38 #include "FrameTestHelpers.h" 38 #include "FrameTestHelpers.h"
39 #include "FrameView.h" 39 #include "FrameView.h"
40 #include "HitTestResult.h"
40 #include "PlatformContextSkia.h" 41 #include "PlatformContextSkia.h"
41 #include "Range.h" 42 #include "Range.h"
42 #include "RenderView.h" 43 #include "RenderView.h"
43 #include "ResourceError.h" 44 #include "ResourceError.h"
44 #include "Settings.h" 45 #include "Settings.h"
45 #include "SkBitmap.h" 46 #include "SkBitmap.h"
46 #include "SkCanvas.h" 47 #include "SkCanvas.h"
47 #include "URLTestHelpers.h" 48 #include "URLTestHelpers.h"
48 #include "WebDataSource.h" 49 #include "WebDataSource.h"
49 #include "WebDocument.h" 50 #include "WebDocument.h"
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 m_webView->resize(WebSize(viewportWidth, viewportHeight)); 567 m_webView->resize(WebSize(viewportWidth, viewportHeight));
567 m_webView->layout(); 568 m_webView->layout();
568 569
569 m_webView->setPageScaleFactor(2, WebPoint()); 570 m_webView->setPageScaleFactor(2, WebPoint());
570 571
571 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView); 572 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
572 EXPECT_EQ(1, webViewImpl->page()->mainFrame()->frameScaleFactor()); 573 EXPECT_EQ(1, webViewImpl->page()->mainFrame()->frameScaleFactor());
573 EXPECT_EQ(980, webViewImpl->page()->mainFrame()->contentRenderer()->unscaled DocumentRect().width()); 574 EXPECT_EQ(980, webViewImpl->page()->mainFrame()->contentRenderer()->unscaled DocumentRect().width());
574 EXPECT_EQ(980, webViewImpl->mainFrameImpl()->frameView()->contentsSize().wid th()); 575 EXPECT_EQ(980, webViewImpl->mainFrameImpl()->frameView()->contentsSize().wid th());
575 } 576 }
577
578 static WebCore::FloatSize computeRelativeOffset(const WebCore::IntPoint& absolut eOffset, const WebCore::LayoutRect& rect)
579 {
580 WebCore::FloatSize relativeOffset = WebCore::FloatPoint(absoluteOffset) - re ct.location();
581 relativeOffset.scale(1.f / rect.width(), 1.f / rect.height());
aelias_OOO_until_Jul13 2013/04/08 04:24:52 Delete .f
jdduke (slow) 2013/04/10 16:58:19 Done.
582 return relativeOffset;
583 }
584
585 TEST_F(WebFrameTest, resizePreservesRelativeScrollOffset)
586 {
587 registerMockedHttpURLLoad("resize_scroll_anchor.html");
588
589 const WebSize viewportSize = WebSize(320, 240);
590
591 m_webView = FrameTestHelpers::createWebViewAndLoad(m_baseURL + "resize_scrol l_anchor.html", true);
592 m_webView->settings()->setViewportEnabled(true);
593 m_webView->setPageScaleFactor(2.0f, WebPoint());
594 m_webView->enableFixedLayoutMode(false);
aelias_OOO_until_Jul13 2013/04/08 04:24:52 This is odd, on Android fixedLayoutMode setting is
jdduke (slow) 2013/04/10 16:58:19 Nothing broken, I was too lazy to check the defaul
595 WebViewImpl* webViewImpl = static_cast<WebViewImpl*>(m_webView);
596
597 // Resize at origin
598 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height));
599 webViewImpl->mainFrame()->setScrollOffset(WebSize());
600 ASSERT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset());
aelias_OOO_until_Jul13 2013/04/08 04:24:52 Delete this assert.
jdduke (slow) 2013/04/10 16:58:19 Done.
601 webViewImpl->resize(WebSize(viewportSize.height * 2 , viewportSize.width / 2 ));
602 EXPECT_EQ(WebSize(), webViewImpl->mainFrame()->scrollOffset());
603
604 // Resize as rotation
605 const WebSize scrollOffset = WebSize(200, 400);
606 webViewImpl->resize(WebSize(viewportSize.width, viewportSize.height));
607 webViewImpl->mainFrame()->setScrollOffset(scrollOffset);
608 ASSERT_EQ(scrollOffset, webViewImpl->mainFrame()->scrollOffset());
aelias_OOO_until_Jul13 2013/04/08 04:24:52 Delete this assert.
jdduke (slow) 2013/04/10 16:58:19 Done.
609
610 WebCore::IntPoint anchorPoint = WebCore::IntPoint(scrollOffset) + WebCore::I ntPoint(viewportSize.width / 2, 0);
611 RefPtr<WebCore::Node> anchorNode
612 = webViewImpl->mainFrameImpl()->frame()->eventHandler()->hitTestResultAt Point(anchorPoint).innerNode();
613 ASSERT(anchorNode);
614
615 const WebCore::FloatSize preResizeRelativeOffset
616 = computeRelativeOffset(anchorPoint, anchorNode->Node::boundingBox());
617 webViewImpl->resize(WebSize(viewportSize.height, viewportSize.width));
618 WebCore::IntPoint newAnchorPoint = WebCore::IntPoint(webViewImpl->mainFrame( )->scrollOffset()) + WebCore::IntPoint(viewportSize.height / 2, 0);
619 const WebCore::FloatSize postResizeRelativeOffset
620 = computeRelativeOffset(newAnchorPoint, anchorNode->Node::boundingBox()) ;
aelias_OOO_until_Jul13 2013/04/08 04:24:52 anchorNode->boundingBox()
621 EXPECT_NEAR(preResizeRelativeOffset.width(), postResizeRelativeOffset.width( ), 0.1f);
622 }
576 #endif 623 #endif
577 624
578 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip) 625 TEST_F(WebFrameTest, pageScaleFactorScalesPaintClip)
579 { 626 {
580 registerMockedHttpURLLoad("fixed_layout.html"); 627 registerMockedHttpURLLoad("fixed_layout.html");
581 628
582 FixedLayoutTestWebViewClient client; 629 FixedLayoutTestWebViewClient client;
583 client.m_screenInfo.deviceScaleFactor = 1; 630 client.m_screenInfo.deviceScaleFactor = 1;
584 int viewportWidth = 50; 631 int viewportWidth = 50;
585 int viewportHeight = 50; 632 int viewportHeight = 50;
(...skipping 1975 matching lines...) Expand 10 before | Expand all | Expand 10 after
2561 EXPECT_FALSE(client.wasProgrammaticScroll()); 2608 EXPECT_FALSE(client.wasProgrammaticScroll());
2562 EXPECT_TRUE(client.wasUserScroll()); 2609 EXPECT_TRUE(client.wasUserScroll());
2563 client.reset(); 2610 client.reset();
2564 2611
2565 m_webView->close(); 2612 m_webView->close();
2566 m_webView = 0; 2613 m_webView = 0;
2567 } 2614 }
2568 2615
2569 2616
2570 } // namespace 2617 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698