| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "content/public/renderer/render_view.h" | 14 #include "content/public/renderer/render_view.h" |
| 15 #include "content/public/renderer/render_view_observer.h" | 15 #include "content/public/renderer/render_view_observer.h" |
| 16 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 17 #include "content/renderer/savable_resources.h" | 17 #include "content/renderer/savable_resources.h" |
| 18 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 19 #include "content/test/content_browser_test.h" | 19 #include "content/test/content_browser_test.h" |
| 20 #include "content/test/content_browser_test_utils.h" | 20 #include "content/test/content_browser_test_utils.h" |
| 21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 22 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
| 23 #include "third_party/WebKit/public/platform/WebCString.h" | 23 #include "third_party/WebKit/public/platform/WebCString.h" |
| 24 #include "third_party/WebKit/public/platform/WebData.h" | 24 #include "third_party/WebKit/public/platform/WebData.h" |
| 25 #include "third_party/WebKit/public/platform/WebString.h" | 25 #include "third_party/WebKit/public/platform/WebString.h" |
| 26 #include "third_party/WebKit/public/platform/WebURL.h" | 26 #include "third_party/WebKit/public/platform/WebURL.h" |
| 27 #include "third_party/WebKit/public/platform/WebVector.h" | 27 #include "third_party/WebKit/public/platform/WebVector.h" |
| 28 #include "third_party/WebKit/public/web/WebDocument.h" | 28 #include "third_party/WebKit/public/web/WebDocument.h" |
| 29 #include "third_party/WebKit/public/web/WebElement.h" | 29 #include "third_party/WebKit/public/web/WebElement.h" |
| 30 #include "third_party/WebKit/public/web/WebElementCollection.h" |
| 30 #include "third_party/WebKit/public/web/WebFrame.h" | 31 #include "third_party/WebKit/public/web/WebFrame.h" |
| 31 #include "third_party/WebKit/public/web/WebNode.h" | 32 #include "third_party/WebKit/public/web/WebNode.h" |
| 32 #include "third_party/WebKit/public/web/WebNodeCollection.h" | |
| 33 #include "third_party/WebKit/public/web/WebNodeList.h" | 33 #include "third_party/WebKit/public/web/WebNodeList.h" |
| 34 #include "third_party/WebKit/public/web/WebPageSerializer.h" | 34 #include "third_party/WebKit/public/web/WebPageSerializer.h" |
| 35 #include "third_party/WebKit/public/web/WebPageSerializerClient.h" | 35 #include "third_party/WebKit/public/web/WebPageSerializerClient.h" |
| 36 #include "third_party/WebKit/public/web/WebView.h" | 36 #include "third_party/WebKit/public/web/WebView.h" |
| 37 | 37 |
| 38 using blink::WebCString; | 38 using blink::WebCString; |
| 39 using blink::WebData; | 39 using blink::WebData; |
| 40 using blink::WebDocument; | 40 using blink::WebDocument; |
| 41 using blink::WebElement; | 41 using blink::WebElement; |
| 42 using blink::WebElementCollection; |
| 42 using blink::WebFrame; | 43 using blink::WebFrame; |
| 43 using blink::WebNode; | 44 using blink::WebNode; |
| 44 using blink::WebNodeCollection; | |
| 45 using blink::WebNodeList; | 45 using blink::WebNodeList; |
| 46 using blink::WebPageSerializer; | 46 using blink::WebPageSerializer; |
| 47 using blink::WebPageSerializerClient; | 47 using blink::WebPageSerializerClient; |
| 48 using blink::WebNode; | |
| 49 using blink::WebString; | 48 using blink::WebString; |
| 50 using blink::WebURL; | 49 using blink::WebURL; |
| 51 using blink::WebView; | 50 using blink::WebView; |
| 52 using blink::WebVector; | 51 using blink::WebVector; |
| 53 | 52 |
| 54 namespace { | 53 namespace { |
| 55 | 54 |
| 56 // The first RenderFrame is routing ID 1, and the first RenderView is 2. | 55 // The first RenderFrame is routing ID 1, and the first RenderView is 2. |
| 57 const int kRenderViewRoutingId = 2; | 56 const int kRenderViewRoutingId = 2; |
| 58 | 57 |
| 59 } | 58 } |
| 60 | 59 |
| 61 namespace content { | 60 namespace content { |
| 62 | 61 |
| 63 // Iterate recursively over sub-frames to find one with with a given url. | 62 // Iterate recursively over sub-frames to find one with with a given url. |
| 64 WebFrame* FindSubFrameByURL(WebView* web_view, const GURL& url) { | 63 WebFrame* FindSubFrameByURL(WebView* web_view, const GURL& url) { |
| 65 if (!web_view->mainFrame()) | 64 if (!web_view->mainFrame()) |
| 66 return NULL; | 65 return NULL; |
| 67 | 66 |
| 68 std::vector<WebFrame*> stack; | 67 std::vector<WebFrame*> stack; |
| 69 stack.push_back(web_view->mainFrame()); | 68 stack.push_back(web_view->mainFrame()); |
| 70 | 69 |
| 71 while (!stack.empty()) { | 70 while (!stack.empty()) { |
| 72 WebFrame* current_frame = stack.back(); | 71 WebFrame* current_frame = stack.back(); |
| 73 stack.pop_back(); | 72 stack.pop_back(); |
| 74 if (GURL(current_frame->document().url()) == url) | 73 if (GURL(current_frame->document().url()) == url) |
| 75 return current_frame; | 74 return current_frame; |
| 76 WebNodeCollection all = current_frame->document().all(); | 75 WebElementCollection all = current_frame->document().all(); |
| 77 for (WebNode node = all.firstItem(); | 76 for (WebElement element = all.firstItem(); |
| 78 !node.isNull(); node = all.nextItem()) { | 77 !element.isNull(); element = all.nextItem()) { |
| 79 if (!node.isElementNode()) | |
| 80 continue; | |
| 81 // Check frame tag and iframe tag | 78 // Check frame tag and iframe tag |
| 82 WebElement element = node.to<WebElement>(); | |
| 83 if (!element.hasTagName("frame") && !element.hasTagName("iframe")) | 79 if (!element.hasTagName("frame") && !element.hasTagName("iframe")) |
| 84 continue; | 80 continue; |
| 85 WebFrame* sub_frame = WebFrame::fromFrameOwnerElement(element); | 81 WebFrame* sub_frame = WebFrame::fromFrameOwnerElement(element); |
| 86 if (sub_frame) | 82 if (sub_frame) |
| 87 stack.push_back(sub_frame); | 83 stack.push_back(sub_frame); |
| 88 } | 84 } |
| 89 } | 85 } |
| 90 return NULL; | 86 return NULL; |
| 91 } | 87 } |
| 92 | 88 |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 const int kTotalBaseTagCountInTestFile = 2; | 603 const int kTotalBaseTagCountInTestFile = 2; |
| 608 | 604 |
| 609 // Since for this test, we assume there is no savable sub-resource links for | 605 // Since for this test, we assume there is no savable sub-resource links for |
| 610 // this test file, also all links are relative URLs in this test file, so we | 606 // this test file, also all links are relative URLs in this test file, so we |
| 611 // need to check those relative URLs and make sure document has BASE tag. | 607 // need to check those relative URLs and make sure document has BASE tag. |
| 612 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); | 608 WebFrame* web_frame = FindSubFrameByURL(GetWebView(), file_url); |
| 613 ASSERT_TRUE(web_frame != NULL); | 609 ASSERT_TRUE(web_frame != NULL); |
| 614 WebDocument doc = web_frame->document(); | 610 WebDocument doc = web_frame->document(); |
| 615 ASSERT_TRUE(doc.isHTMLDocument()); | 611 ASSERT_TRUE(doc.isHTMLDocument()); |
| 616 // Go through all descent nodes. | 612 // Go through all descent nodes. |
| 617 WebNodeCollection all = doc.all(); | 613 WebElementCollection all = doc.all(); |
| 618 int original_base_tag_count = 0; | 614 int original_base_tag_count = 0; |
| 619 for (WebNode node = all.firstItem(); !node.isNull(); | 615 for (WebElement element = all.firstItem(); !element.isNull(); |
| 620 node = all.nextItem()) { | 616 element = all.nextItem()) { |
| 621 if (!node.isElementNode()) | |
| 622 continue; | |
| 623 WebElement element = node.to<WebElement>(); | |
| 624 if (element.hasTagName("base")) { | 617 if (element.hasTagName("base")) { |
| 625 original_base_tag_count++; | 618 original_base_tag_count++; |
| 626 } else { | 619 } else { |
| 627 // Get link. | 620 // Get link. |
| 628 WebString value = GetSubResourceLinkFromElement(element); | 621 WebString value = GetSubResourceLinkFromElement(element); |
| 629 if (value.isNull() && element.hasTagName("a")) { | 622 if (value.isNull() && element.hasTagName("a")) { |
| 630 value = element.getAttribute("href"); | 623 value = element.getAttribute("href"); |
| 631 if (value.isEmpty()) | 624 if (value.isEmpty()) |
| 632 value = WebString(); | 625 value = WebString(); |
| 633 } | 626 } |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1023 NavigateToURL(shell(), file_url); | 1016 NavigateToURL(shell(), file_url); |
| 1024 | 1017 |
| 1025 PostTaskToInProcessRendererAndWait( | 1018 PostTaskToInProcessRendererAndWait( |
| 1026 base::Bind( | 1019 base::Bind( |
| 1027 &DomSerializerTests:: | 1020 &DomSerializerTests:: |
| 1028 SubResourceForElementsInNonHTMLNamespaceOnRenderer, | 1021 SubResourceForElementsInNonHTMLNamespaceOnRenderer, |
| 1029 base::Unretained(this), file_url)); | 1022 base::Unretained(this), file_url)); |
| 1030 } | 1023 } |
| 1031 | 1024 |
| 1032 } // namespace content | 1025 } // namespace content |
| OLD | NEW |