This source file includes following definitions.
- SetUp
- TearDown
- registerMockedURLLoad
- loadURLInTopFrame
- page
- TEST_F
#include "config.h"
#include "FrameTestHelpers.h"
#include "URLTestHelpers.h"
#include "WebFrame.h"
#include "WebView.h"
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Location.h"
#include "core/page/Page.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/Platform.h"
#include "public/platform/WebString.h"
#include "public/platform/WebURL.h"
#include "public/platform/WebURLRequest.h"
#include "public/platform/WebURLResponse.h"
#include "public/platform/WebUnitTestSupport.h"
#include "public/web/WebDocument.h"
#include <gtest/gtest.h>
using namespace blink;
using WebCore::Document;
using WebCore::LocalFrame;
using WebCore::Page;
using WebCore::KURL;
using blink::URLTestHelpers::toKURL;
namespace {
class MHTMLTest : public testing::Test {
public:
MHTMLTest()
{
}
protected:
virtual void SetUp()
{
m_helper.initialize();
}
virtual void TearDown()
{
Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
}
void registerMockedURLLoad(const std::string& url, const WebString& fileName)
{
URLTestHelpers::registerMockedURLLoad(toKURL(url), fileName, WebString::fromUTF8("mhtml/"), WebString::fromUTF8("text/html"));
}
void loadURLInTopFrame(const WebURL& url)
{
WebURLRequest urlRequest;
urlRequest.initialize();
urlRequest.setURL(url);
m_helper.webView()->mainFrame()->loadRequest(urlRequest);
Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
}
Page* page() const { return m_helper.webViewImpl()->page(); }
private:
FrameTestHelpers::WebViewHelper m_helper;
};
TEST_F(MHTMLTest, CheckDomain)
{
const char kFileURL[] = "file:///simple_test.mht";
WebURL url = toKURL(kFileURL);
registerMockedURLLoad(kFileURL, WebString::fromUTF8("simple_test.mht"));
loadURLInTopFrame(url);
ASSERT_TRUE(page());
LocalFrame* frame = page()->mainFrame();
ASSERT_TRUE(frame);
Document* document = frame->document();
ASSERT_TRUE(document);
EXPECT_STREQ(kFileURL, frame->domWindow()->location().href().ascii().data());
WebCore::SecurityOrigin* origin = document->securityOrigin();
EXPECT_STRNE("localhost", origin->domain().ascii().data());
}
}