OLD | NEW |
---|---|
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 4759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4770 range = frame->SelectionRange(); | 4770 range = frame->SelectionRange(); |
4771 ASSERT_TRUE(range.IsNull()); | 4771 ASSERT_TRUE(range.IsNull()); |
4772 } | 4772 } |
4773 | 4773 |
4774 TEST_P(ParameterizedWebFrameTest, GetContentAsPlainText) { | 4774 TEST_P(ParameterizedWebFrameTest, GetContentAsPlainText) { |
4775 FrameTestHelpers::WebViewHelper web_view_helper; | 4775 FrameTestHelpers::WebViewHelper web_view_helper; |
4776 web_view_helper.InitializeAndLoad("about:blank", true); | 4776 web_view_helper.InitializeAndLoad("about:blank", true); |
4777 // We set the size because it impacts line wrapping, which changes the | 4777 // We set the size because it impacts line wrapping, which changes the |
4778 // resulting text value. | 4778 // resulting text value. |
4779 web_view_helper.Resize(WebSize(640, 480)); | 4779 web_view_helper.Resize(WebSize(640, 480)); |
4780 WebFrame* frame = web_view_helper.WebView()->MainFrame(); | 4780 WebLocalFrame* frame = web_view_helper.WebView()->MainFrameImpl(); |
4781 | 4781 |
4782 // Generate a simple test case. | 4782 // Generate a simple test case. |
4783 const char kSimpleSource[] = "<div>Foo bar</div><div></div>baz"; | 4783 const char kSimpleSource[] = "<div>Foo bar</div><div></div>baz"; |
4784 KURL test_url = ToKURL("about:blank"); | 4784 KURL test_url = ToKURL("about:blank"); |
4785 FrameTestHelpers::LoadHTMLString(frame, kSimpleSource, test_url); | 4785 FrameTestHelpers::LoadHTMLString(frame, kSimpleSource, test_url); |
4786 | 4786 |
4787 // Make sure it comes out OK. | 4787 // Make sure it comes out OK. |
4788 const std::string expected("Foo bar\nbaz"); | 4788 const std::string expected("Foo bar\nbaz"); |
4789 WebString text = WebFrameContentDumper::DumpWebViewAsText( | 4789 WebString text = WebFrameContentDumper::DumpWebViewAsText( |
4790 web_view_helper.WebView(), std::numeric_limits<size_t>::max()); | 4790 web_view_helper.WebView(), std::numeric_limits<size_t>::max()); |
4791 EXPECT_EQ(expected, text.Utf8()); | 4791 EXPECT_EQ(expected, text.Utf8()); |
4792 | 4792 |
4793 // Try reading the same one with clipping of the text. | 4793 // Try reading the same one with clipping of the text. |
4794 const int kLength = 5; | 4794 const int kLength = 5; |
4795 text = WebFrameContentDumper::DumpWebViewAsText(web_view_helper.WebView(), | 4795 text = WebFrameContentDumper::DumpWebViewAsText(web_view_helper.WebView(), |
4796 kLength); | 4796 kLength); |
4797 EXPECT_EQ(expected.substr(0, kLength), text.Utf8()); | 4797 EXPECT_EQ(expected.substr(0, kLength), text.Utf8()); |
4798 | 4798 |
4799 // Now do a new test with a subframe. | 4799 // Now do a new test with a subframe. |
4800 const char kOuterFrameSource[] = "Hello<iframe></iframe> world"; | 4800 const char kOuterFrameSource[] = "Hello<iframe></iframe> world"; |
4801 FrameTestHelpers::LoadHTMLString(frame, kOuterFrameSource, test_url); | 4801 FrameTestHelpers::LoadHTMLString(frame, kOuterFrameSource, test_url); |
4802 | 4802 |
4803 // Load something into the subframe. | 4803 // Load something into the subframe. |
4804 WebFrame* subframe = frame->FirstChild(); | 4804 WebLocalFrame* subframe = frame->FirstChild()->ToWebLocalFrame(); |
Łukasz Anforowicz
2017/06/06 18:25:44
This seems safe in practice.
dcheng
2017/06/06 19:49:49
Acknowledged. Long-term, I'm hoping some sort of l
| |
4805 ASSERT_TRUE(subframe); | 4805 ASSERT_TRUE(subframe); |
4806 FrameTestHelpers::LoadHTMLString(subframe, "sub<p>text", test_url); | 4806 FrameTestHelpers::LoadHTMLString(subframe, "sub<p>text", test_url); |
4807 | 4807 |
4808 text = WebFrameContentDumper::DumpWebViewAsText( | 4808 text = WebFrameContentDumper::DumpWebViewAsText( |
4809 web_view_helper.WebView(), std::numeric_limits<size_t>::max()); | 4809 web_view_helper.WebView(), std::numeric_limits<size_t>::max()); |
4810 EXPECT_EQ("Hello world\n\nsub\ntext", text.Utf8()); | 4810 EXPECT_EQ("Hello world\n\nsub\ntext", text.Utf8()); |
4811 | 4811 |
4812 // Get the frame text where the subframe separator falls on the boundary of | 4812 // Get the frame text where the subframe separator falls on the boundary of |
4813 // what we'll take. There used to be a crash in this case. | 4813 // what we'll take. There used to be a crash in this case. |
4814 text = | 4814 text = |
(...skipping 2806 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7621 base_url_ + "foo_with_image.html"); | 7621 base_url_ + "foo_with_image.html"); |
7622 | 7622 |
7623 // 2 images are requested, and each triggers 2 willSendRequest() calls, | 7623 // 2 images are requested, and each triggers 2 willSendRequest() calls, |
7624 // once for preloading and once for the real request. | 7624 // once for preloading and once for the real request. |
7625 EXPECT_EQ(client.NumOfImageRequests(), 4); | 7625 EXPECT_EQ(client.NumOfImageRequests(), 4); |
7626 } | 7626 } |
7627 | 7627 |
7628 TEST_P(ParameterizedWebFrameTest, WebNodeImageContents) { | 7628 TEST_P(ParameterizedWebFrameTest, WebNodeImageContents) { |
7629 FrameTestHelpers::WebViewHelper web_view_helper; | 7629 FrameTestHelpers::WebViewHelper web_view_helper; |
7630 web_view_helper.InitializeAndLoad("about:blank", true); | 7630 web_view_helper.InitializeAndLoad("about:blank", true); |
7631 WebFrame* frame = web_view_helper.WebView()->MainFrame(); | 7631 WebLocalFrame* frame = web_view_helper.WebView()->MainFrameImpl(); |
7632 | 7632 |
7633 static const char kBluePNG[] = | 7633 static const char kBluePNG[] = |
7634 "<img " | 7634 "<img " |
7635 "src=\"data:image/" | 7635 "src=\"data:image/" |
7636 "png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+" | 7636 "png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+" |
7637 "9AAAAGElEQVQYV2NkYPj/n4EIwDiqEF8oUT94AFIQE/cCn90IAAAAAElFTkSuQmCC\">"; | 7637 "9AAAAGElEQVQYV2NkYPj/n4EIwDiqEF8oUT94AFIQE/cCn90IAAAAAElFTkSuQmCC\">"; |
7638 | 7638 |
7639 // Load up the image and test that we can extract the contents. | 7639 // Load up the image and test that we can extract the contents. |
7640 KURL test_url = ToKURL("about:blank"); | 7640 KURL test_url = ToKURL("about:blank"); |
7641 FrameTestHelpers::LoadHTMLString(frame, kBluePNG, test_url); | 7641 FrameTestHelpers::LoadHTMLString(frame, kBluePNG, test_url); |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8494 EXPECT_EQ(100, layout_view_item.LogicalWidth().Floor()); | 8494 EXPECT_EQ(100, layout_view_item.LogicalWidth().Floor()); |
8495 EXPECT_EQ(200, layout_view_item.LogicalHeight().Floor()); | 8495 EXPECT_EQ(200, layout_view_item.LogicalHeight().Floor()); |
8496 EXPECT_FLOAT_EQ(1.0, web_view_impl->PageScaleFactor()); | 8496 EXPECT_FLOAT_EQ(1.0, web_view_impl->PageScaleFactor()); |
8497 EXPECT_FLOAT_EQ(1.0, web_view_impl->MinimumPageScaleFactor()); | 8497 EXPECT_FLOAT_EQ(1.0, web_view_impl->MinimumPageScaleFactor()); |
8498 EXPECT_FLOAT_EQ(1.0, web_view_impl->MaximumPageScaleFactor()); | 8498 EXPECT_FLOAT_EQ(1.0, web_view_impl->MaximumPageScaleFactor()); |
8499 | 8499 |
8500 const char kSource[] = "<meta name=\"viewport\" content=\"width=200\">"; | 8500 const char kSource[] = "<meta name=\"viewport\" content=\"width=200\">"; |
8501 | 8501 |
8502 // Load a new page before exiting fullscreen. | 8502 // Load a new page before exiting fullscreen. |
8503 KURL test_url = ToKURL("about:blank"); | 8503 KURL test_url = ToKURL("about:blank"); |
8504 WebFrame* frame = web_view_helper.WebView()->MainFrame(); | 8504 WebLocalFrame* frame = web_view_helper.WebView()->MainFrameImpl(); |
8505 FrameTestHelpers::LoadHTMLString(frame, kSource, test_url); | 8505 FrameTestHelpers::LoadHTMLString(frame, kSource, test_url); |
8506 web_view_impl->DidExitFullscreen(); | 8506 web_view_impl->DidExitFullscreen(); |
8507 web_view_impl->UpdateAllLifecyclePhases(); | 8507 web_view_impl->UpdateAllLifecyclePhases(); |
8508 | 8508 |
8509 // Make sure the new page's layout size and scale factor limits aren't | 8509 // Make sure the new page's layout size and scale factor limits aren't |
8510 // overridden. | 8510 // overridden. |
8511 layout_view_item = | 8511 layout_view_item = |
8512 web_view_impl->MainFrameImpl()->GetFrameView()->GetLayoutViewItem(); | 8512 web_view_impl->MainFrameImpl()->GetFrameView()->GetLayoutViewItem(); |
8513 EXPECT_EQ(200, layout_view_item.LogicalWidth().Floor()); | 8513 EXPECT_EQ(200, layout_view_item.LogicalWidth().Floor()); |
8514 EXPECT_EQ(400, layout_view_item.LogicalHeight().Floor()); | 8514 EXPECT_EQ(400, layout_view_item.LogicalHeight().Floor()); |
(...skipping 3176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
11691 ASSERT_TRUE(theme.IsMockTheme()); | 11691 ASSERT_TRUE(theme.IsMockTheme()); |
11692 ASSERT_TRUE(theme.UsesOverlayScrollbars()); | 11692 ASSERT_TRUE(theme.UsesOverlayScrollbars()); |
11693 ScrollbarThemeOverlayMock& mock_overlay_theme = | 11693 ScrollbarThemeOverlayMock& mock_overlay_theme = |
11694 (ScrollbarThemeOverlayMock&)theme; | 11694 (ScrollbarThemeOverlayMock&)theme; |
11695 mock_overlay_theme.SetOverlayScrollbarFadeOutDelay( | 11695 mock_overlay_theme.SetOverlayScrollbarFadeOutDelay( |
11696 kMockOverlayFadeOutDelayMs / 1000.0); | 11696 kMockOverlayFadeOutDelayMs / 1000.0); |
11697 | 11697 |
11698 web_view_impl->ResizeWithBrowserControls(WebSize(640, 480), 0, false); | 11698 web_view_impl->ResizeWithBrowserControls(WebSize(640, 480), 0, false); |
11699 | 11699 |
11700 WebURL base_url = URLTestHelpers::ToKURL("http://example.com/"); | 11700 WebURL base_url = URLTestHelpers::ToKURL("http://example.com/"); |
11701 FrameTestHelpers::LoadHTMLString(web_view_impl->MainFrame(), | 11701 FrameTestHelpers::LoadHTMLString(web_view_impl->MainFrameImpl(), |
11702 "<!DOCTYPE html>" | 11702 "<!DOCTYPE html>" |
11703 "<style>" | 11703 "<style>" |
11704 " #space {" | 11704 " #space {" |
11705 " width: 1000px;" | 11705 " width: 1000px;" |
11706 " height: 1000px;" | 11706 " height: 1000px;" |
11707 " }" | 11707 " }" |
11708 " #container {" | 11708 " #container {" |
11709 " width: 200px;" | 11709 " width: 200px;" |
11710 " height: 200px;" | 11710 " height: 200px;" |
11711 " overflow: scroll;" | 11711 " overflow: scroll;" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12010 | 12010 |
12011 private: | 12011 private: |
12012 WebContextMenuData menu_data_; | 12012 WebContextMenuData menu_data_; |
12013 DISALLOW_COPY_AND_ASSIGN(ContextMenuWebFrameClient); | 12013 DISALLOW_COPY_AND_ASSIGN(ContextMenuWebFrameClient); |
12014 }; | 12014 }; |
12015 | 12015 |
12016 bool TestSelectAll(const std::string& html) { | 12016 bool TestSelectAll(const std::string& html) { |
12017 ContextMenuWebFrameClient frame; | 12017 ContextMenuWebFrameClient frame; |
12018 FrameTestHelpers::WebViewHelper web_view_helper; | 12018 FrameTestHelpers::WebViewHelper web_view_helper; |
12019 WebViewBase* web_view = web_view_helper.Initialize(true, &frame); | 12019 WebViewBase* web_view = web_view_helper.Initialize(true, &frame); |
12020 FrameTestHelpers::LoadHTMLString(web_view->MainFrame(), html, | 12020 FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(), html, |
12021 ToKURL("about:blank")); | 12021 ToKURL("about:blank")); |
12022 web_view->Resize(WebSize(500, 300)); | 12022 web_view->Resize(WebSize(500, 300)); |
12023 web_view->UpdateAllLifecyclePhases(); | 12023 web_view->UpdateAllLifecyclePhases(); |
12024 RunPendingTasks(); | 12024 RunPendingTasks(); |
12025 web_view->SetInitialFocus(false); | 12025 web_view->SetInitialFocus(false); |
12026 RunPendingTasks(); | 12026 RunPendingTasks(); |
12027 | 12027 |
12028 WebMouseEvent mouse_event(WebInputEvent::kMouseDown, | 12028 WebMouseEvent mouse_event(WebInputEvent::kMouseDown, |
12029 WebInputEvent::kNoModifiers, | 12029 WebInputEvent::kNoModifiers, |
12030 WebInputEvent::kTimeStampForTesting); | 12030 WebInputEvent::kTimeStampForTesting); |
(...skipping 15 matching lines...) Expand all Loading... | |
12046 EXPECT_FALSE(TestSelectAll("<div contenteditable></div>")); | 12046 EXPECT_FALSE(TestSelectAll("<div contenteditable></div>")); |
12047 EXPECT_TRUE(TestSelectAll("<div contenteditable>nonempty</div>")); | 12047 EXPECT_TRUE(TestSelectAll("<div contenteditable>nonempty</div>")); |
12048 EXPECT_TRUE(TestSelectAll("<div contenteditable>\n</div>")); | 12048 EXPECT_TRUE(TestSelectAll("<div contenteditable>\n</div>")); |
12049 } | 12049 } |
12050 | 12050 |
12051 TEST_F(WebFrameTest, ContextMenuDataSelectedText) { | 12051 TEST_F(WebFrameTest, ContextMenuDataSelectedText) { |
12052 ContextMenuWebFrameClient frame; | 12052 ContextMenuWebFrameClient frame; |
12053 FrameTestHelpers::WebViewHelper web_view_helper; | 12053 FrameTestHelpers::WebViewHelper web_view_helper; |
12054 WebViewBase* web_view = web_view_helper.Initialize(true, &frame); | 12054 WebViewBase* web_view = web_view_helper.Initialize(true, &frame); |
12055 const std::string& html = "<input value=' '>"; | 12055 const std::string& html = "<input value=' '>"; |
12056 FrameTestHelpers::LoadHTMLString(web_view->MainFrame(), html, | 12056 FrameTestHelpers::LoadHTMLString(web_view->MainFrameImpl(), html, |
12057 ToKURL("about:blank")); | 12057 ToKURL("about:blank")); |
12058 web_view->Resize(WebSize(500, 300)); | 12058 web_view->Resize(WebSize(500, 300)); |
12059 web_view->UpdateAllLifecyclePhases(); | 12059 web_view->UpdateAllLifecyclePhases(); |
12060 RunPendingTasks(); | 12060 RunPendingTasks(); |
12061 web_view->SetInitialFocus(false); | 12061 web_view->SetInitialFocus(false); |
12062 RunPendingTasks(); | 12062 RunPendingTasks(); |
12063 | 12063 |
12064 web_view->MainFrameImpl()->ExecuteCommand(WebString::FromUTF8("SelectAll")); | 12064 web_view->MainFrameImpl()->ExecuteCommand(WebString::FromUTF8("SelectAll")); |
12065 | 12065 |
12066 WebMouseEvent mouse_event(WebInputEvent::kMouseDown, | 12066 WebMouseEvent mouse_event(WebInputEvent::kMouseDown, |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
12181 if (obj->IsText()) { | 12181 if (obj->IsText()) { |
12182 LayoutText* layout_text = ToLayoutText(obj); | 12182 LayoutText* layout_text = ToLayoutText(obj); |
12183 text = layout_text->GetText(); | 12183 text = layout_text->GetText(); |
12184 break; | 12184 break; |
12185 } | 12185 } |
12186 } | 12186 } |
12187 EXPECT_EQ("foo alt", text.Utf8()); | 12187 EXPECT_EQ("foo alt", text.Utf8()); |
12188 } | 12188 } |
12189 | 12189 |
12190 } // namespace blink | 12190 } // namespace blink |
OLD | NEW |