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

Side by Side Diff: webkit/glue/webframe_unittest.cc

Issue 164225: Switch to WebFrame from the WebKit API.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « webkit/glue/webframe_impl.cc ('k') | webkit/glue/webframeloaderclient_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/string_util.h" 5 #include "base/string_util.h"
6 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "webkit/api/public/WebData.h" 7 #include "webkit/api/public/WebData.h"
8 #include "webkit/api/public/WebFrame.h"
9 #include "webkit/api/public/WebString.h"
8 #include "webkit/api/public/WebURL.h" 10 #include "webkit/api/public/WebURL.h"
9 #include "webkit/glue/webframe.h"
10 #include "webkit/glue/webview.h" 11 #include "webkit/glue/webview.h"
11 #include "webkit/tools/test_shell/test_shell_test.h" 12 #include "webkit/tools/test_shell/test_shell_test.h"
12 13
14 using WebKit::WebFrame;
15 using WebKit::WebString;
16
13 class WebFrameTest : public TestShellTest { 17 class WebFrameTest : public TestShellTest {
14 public: 18 public:
15 }; 19 };
16 20
17 TEST_F(WebFrameTest, GetContentAsPlainText) { 21 TEST_F(WebFrameTest, GetContentAsPlainText) {
18 WebView* view = test_shell_->webView(); 22 WebView* view = test_shell_->webView();
19 WebFrame* frame = view->GetMainFrame(); 23 WebFrame* frame = view->GetMainFrame();
20 24
21 // Generate a simple test case. 25 // Generate a simple test case.
22 const char simple_source[] = "<div>Foo bar</div><div></div>baz"; 26 const char simple_source[] = "<div>Foo bar</div><div></div>baz";
23 GURL test_url("http://foo/"); 27 GURL test_url("http://foo/");
24 frame->LoadHTMLString(simple_source, test_url); 28 frame->loadHTMLString(simple_source, test_url);
25 test_shell_->WaitTestFinished(); 29 test_shell_->WaitTestFinished();
26 30
27 // Make sure it comes out OK. 31 // Make sure it comes out OK.
28 const std::wstring expected(ASCIIToWide("Foo bar\nbaz")); 32 const string16 expected(ASCIIToUTF16("Foo bar\nbaz"));
29 std::wstring text; 33 string16 text = frame->contentAsText(std::numeric_limits<size_t>::max());
30 frame->GetContentAsPlainText(std::numeric_limits<int>::max(), &text);
31 EXPECT_EQ(expected, text); 34 EXPECT_EQ(expected, text);
32 35
33 // Try reading the same one with clipping of the text. 36 // Try reading the same one with clipping of the text.
34 const int len = 5; 37 const int len = 5;
35 frame->GetContentAsPlainText(len, &text); 38 text = frame->contentAsText(len);
36 EXPECT_EQ(expected.substr(0, len), text); 39 EXPECT_EQ(expected.substr(0, len), text);
37 40
38 // Now do a new test with a subframe. 41 // Now do a new test with a subframe.
39 const char outer_frame_source[] = "Hello<iframe></iframe> world"; 42 const char outer_frame_source[] = "Hello<iframe></iframe> world";
40 frame->LoadHTMLString(outer_frame_source, test_url); 43 frame->loadHTMLString(outer_frame_source, test_url);
41 test_shell_->WaitTestFinished(); 44 test_shell_->WaitTestFinished();
42 45
43 // Load something into the subframe. 46 // Load something into the subframe.
44 WebFrame* subframe = frame->GetChildFrame(L"/html/body/iframe"); 47 WebFrame* subframe = frame->findChildByExpression(
48 WebString::fromUTF8("/html/body/iframe"));
45 ASSERT_TRUE(subframe); 49 ASSERT_TRUE(subframe);
46 subframe->LoadHTMLString("sub<p>text", test_url); 50 subframe->loadHTMLString("sub<p>text", test_url);
47 test_shell_->WaitTestFinished(); 51 test_shell_->WaitTestFinished();
48 52
49 frame->GetContentAsPlainText(std::numeric_limits<int>::max(), &text); 53 text = frame->contentAsText(std::numeric_limits<size_t>::max());
50 EXPECT_EQ("Hello world\n\nsub\ntext", WideToUTF8(text)); 54 EXPECT_EQ("Hello world\n\nsub\ntext", UTF16ToUTF8(text));
51 55
52 // Get the frame text where the subframe separator falls on the boundary of 56 // Get the frame text where the subframe separator falls on the boundary of
53 // what we'll take. There used to be a crash in this case. 57 // what we'll take. There used to be a crash in this case.
54 frame->GetContentAsPlainText(12, &text); 58 text = frame->contentAsText(12);
55 EXPECT_EQ("Hello world", WideToUTF8(text)); 59 EXPECT_EQ("Hello world", UTF16ToUTF8(text));
56 } 60 }
57 61
58 TEST_F(WebFrameTest, GetFullHtmlOfPage) { 62 TEST_F(WebFrameTest, GetFullHtmlOfPage) {
59 WebView* view = test_shell_->webView(); 63 WebView* view = test_shell_->webView();
60 WebFrame* frame = view->GetMainFrame(); 64 WebFrame* frame = view->GetMainFrame();
61 65
62 // Generate a simple test case. 66 // Generate a simple test case.
63 const char simple_source[] = "<p>Hello</p><p>World</p>"; 67 const char simple_source[] = "<p>Hello</p><p>World</p>";
64 GURL test_url("http://hello/"); 68 GURL test_url("http://hello/");
65 frame->LoadHTMLString(simple_source, test_url); 69 frame->loadHTMLString(simple_source, test_url);
66 test_shell_->WaitTestFinished(); 70 test_shell_->WaitTestFinished();
67 71
68 std::wstring text; 72 string16 text = frame->contentAsText(std::numeric_limits<size_t>::max());
69 frame->GetContentAsPlainText(std::numeric_limits<int>::max(), &text); 73 EXPECT_EQ("Hello\n\nWorld", UTF16ToUTF8(text));
70 EXPECT_EQ("Hello\n\nWorld", WideToUTF8(text));
71 74
72 const std::string html = frame->GetFullPageHtml(); 75 const std::string html = frame->contentAsMarkup().utf8();
73 76
74 // Load again with the output html. 77 // Load again with the output html.
75 frame->LoadHTMLString(html, test_url); 78 frame->loadHTMLString(html, test_url);
76 test_shell_->WaitTestFinished(); 79 test_shell_->WaitTestFinished();
77 80
78 EXPECT_EQ(html, frame->GetFullPageHtml()); 81 EXPECT_EQ(html, UTF16ToUTF8(frame->contentAsMarkup()));
79 82
80 text = L""; 83 text = frame->contentAsText(std::numeric_limits<size_t>::max());
81 frame->GetContentAsPlainText(std::numeric_limits<int>::max(), &text); 84 EXPECT_EQ("Hello\n\nWorld", UTF16ToUTF8(text));
82 EXPECT_EQ("Hello\n\nWorld", WideToUTF8(text));
83 85
84 // Test selection check 86 // Test selection check
85 EXPECT_FALSE(frame->HasSelection()); 87 EXPECT_FALSE(frame->hasSelection());
86 frame->SelectAll(); 88 frame->selectAll();
87 EXPECT_TRUE(frame->HasSelection()); 89 EXPECT_TRUE(frame->hasSelection());
88 frame->ClearSelection(); 90 frame->clearSelection();
89 EXPECT_FALSE(frame->HasSelection()); 91 EXPECT_FALSE(frame->hasSelection());
90 std::string selection_html = frame->GetSelection(true); 92 WebString selection_html = frame->selectionAsMarkup();
91 EXPECT_TRUE(selection_html.empty()); 93 EXPECT_TRUE(selection_html.isEmpty());
92
93 } 94 }
94
OLDNEW
« no previous file with comments | « webkit/glue/webframe_impl.cc ('k') | webkit/glue/webframeloaderclient_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698