Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 #include "public/platform/WebString.h" | 40 #include "public/platform/WebString.h" |
| 41 #include "public/platform/WebThread.h" | 41 #include "public/platform/WebThread.h" |
| 42 #include "public/platform/WebURL.h" | 42 #include "public/platform/WebURL.h" |
| 43 #include "public/platform/WebURLRequest.h" | 43 #include "public/platform/WebURLRequest.h" |
| 44 #include "public/platform/WebURLResponse.h" | 44 #include "public/platform/WebURLResponse.h" |
| 45 #include "public/platform/WebUnitTestSupport.h" | 45 #include "public/platform/WebUnitTestSupport.h" |
| 46 #include "public/web/WebSettings.h" | 46 #include "public/web/WebSettings.h" |
| 47 #include "web/WebLocalFrameImpl.h" | 47 #include "web/WebLocalFrameImpl.h" |
| 48 #include "web/WebViewImpl.h" | 48 #include "web/WebViewImpl.h" |
| 49 #include "web/tests/FrameTestHelpers.h" | 49 #include "web/tests/FrameTestHelpers.h" |
| 50 #include "wtf/Assertions.h" | |
| 50 #include "wtf/Vector.h" | 51 #include "wtf/Vector.h" |
| 51 #include <gtest/gtest.h> | 52 #include <gtest/gtest.h> |
| 52 | 53 |
| 53 using blink::URLTestHelpers::toKURL; | 54 using blink::URLTestHelpers::toKURL; |
| 54 using blink::URLTestHelpers::registerMockedURLLoad; | 55 using blink::URLTestHelpers::registerMockedURLLoad; |
| 55 | 56 |
| 56 namespace blink { | 57 namespace blink { |
| 57 | 58 |
| 58 class PageSerializerTest : public testing::Test { | 59 class PageSerializerTest : public testing::Test { |
| 59 public: | 60 public: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 | 117 |
| 117 void serialize(const char* url) | 118 void serialize(const char* url) |
| 118 { | 119 { |
| 119 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), KURL(m_base Url, url).string().utf8().data()); | 120 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), KURL(m_base Url, url).string().utf8().data()); |
| 120 PageSerializer serializer(&m_resources, nullptr); | 121 PageSerializer serializer(&m_resources, nullptr); |
| 121 | 122 |
| 122 serializer.setRewriteURLFolder(m_rewriteFolder); | 123 serializer.setRewriteURLFolder(m_rewriteFolder); |
| 123 for (const auto& rewriteURL: m_rewriteURLs) | 124 for (const auto& rewriteURL: m_rewriteURLs) |
| 124 serializer.registerRewriteURL(rewriteURL.key, rewriteURL.value); | 125 serializer.registerRewriteURL(rewriteURL.key, rewriteURL.value); |
| 125 | 126 |
| 126 serializer.serialize(m_helper.webViewImpl()->mainFrameImpl()->frame()->p age()); | 127 Frame* frame = m_helper.webViewImpl()->mainFrameImpl()->frame(); |
| 128 for (; frame; frame = frame->tree().traverseNext()) { | |
| 129 // This is safe, because tests do not do cross-site navigation | |
| 130 // (and therefore don't have remote frames). | |
| 131 LocalFrame* localFrame = toLocalFrame(frame); | |
| 132 serializer.serializeFrame(*localFrame); | |
|
dcheng
2015/11/18 03:27:12
Nit: just inline toLocalFrame(*frame) here.
Łukasz Anforowicz
2015/11/18 18:40:41
Done.
| |
| 133 } | |
| 127 } | 134 } |
| 128 | 135 |
| 129 Vector<SerializedResource>& getResources() | 136 Vector<SerializedResource>& getResources() |
| 130 { | 137 { |
| 131 return m_resources; | 138 return m_resources; |
| 132 } | 139 } |
| 133 | 140 |
| 134 | |
| 135 const SerializedResource* getResource(const char* url, const char* mimeType) | 141 const SerializedResource* getResource(const char* url, const char* mimeType) |
| 136 { | 142 { |
| 137 KURL kURL = KURL(m_baseUrl, url); | 143 KURL kURL = KURL(m_baseUrl, url); |
| 138 String mime(mimeType); | 144 String mime(mimeType); |
| 139 for (size_t i = 0; i < m_resources.size(); ++i) { | 145 for (size_t i = 0; i < m_resources.size(); ++i) { |
| 140 const SerializedResource& resource = m_resources[i]; | 146 const SerializedResource& resource = m_resources[i]; |
| 141 if (resource.url == kURL && !resource.data->isEmpty() | 147 if (resource.url == kURL && !resource.data->isEmpty() |
| 142 && (mime.isNull() || equalIgnoringCase(resource.mimeType, mime)) ) | 148 && (mime.isNull() || equalIgnoringCase(resource.mimeType, mime)) ) |
| 143 return &resource; | 149 return &resource; |
| 144 } | 150 } |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 EXPECT_EQ("saved from url=(0015)http://foo.com/", PageSerializer::markOfTheW ebDeclaration(KURL(ParsedURLString, "http://foo.com"))); | 527 EXPECT_EQ("saved from url=(0015)http://foo.com/", PageSerializer::markOfTheW ebDeclaration(KURL(ParsedURLString, "http://foo.com"))); |
| 522 EXPECT_EQ("saved from url=(0015)http://f-o.com/", PageSerializer::markOfTheW ebDeclaration(KURL(ParsedURLString, "http://f-o.com"))); | 528 EXPECT_EQ("saved from url=(0015)http://f-o.com/", PageSerializer::markOfTheW ebDeclaration(KURL(ParsedURLString, "http://f-o.com"))); |
| 523 EXPECT_EQ("saved from url=(0019)http://foo.com-%2D/", PageSerializer::markOf TheWebDeclaration(KURL(ParsedURLString, "http://foo.com--"))); | 529 EXPECT_EQ("saved from url=(0019)http://foo.com-%2D/", PageSerializer::markOf TheWebDeclaration(KURL(ParsedURLString, "http://foo.com--"))); |
| 524 EXPECT_EQ("saved from url=(0024)http://f-%2D.com-%2D%3E/", PageSerializer::m arkOfTheWebDeclaration(KURL(ParsedURLString, "http://f--.com-->"))); | 530 EXPECT_EQ("saved from url=(0024)http://f-%2D.com-%2D%3E/", PageSerializer::m arkOfTheWebDeclaration(KURL(ParsedURLString, "http://f--.com-->"))); |
| 525 EXPECT_EQ("saved from url=(0020)http://foo.com/?-%2D", PageSerializer::markO fTheWebDeclaration(KURL(ParsedURLString, "http://foo.com?--"))); | 531 EXPECT_EQ("saved from url=(0020)http://foo.com/?-%2D", PageSerializer::markO fTheWebDeclaration(KURL(ParsedURLString, "http://foo.com?--"))); |
| 526 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D", PageSerializer::markO fTheWebDeclaration(KURL(ParsedURLString, "http://foo.com#--"))); | 532 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D", PageSerializer::markO fTheWebDeclaration(KURL(ParsedURLString, "http://foo.com#--"))); |
| 527 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz", PageSerializer: :markOfTheWebDeclaration(KURL(ParsedURLString, "http://foo.com#bar--baz"))); | 533 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz", PageSerializer: :markOfTheWebDeclaration(KURL(ParsedURLString, "http://foo.com#bar--baz"))); |
| 528 } | 534 } |
| 529 | 535 |
| 530 } // namespace blink | 536 } // namespace blink |
| OLD | NEW |