Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/html/parser/HTMLPreloadScanner.h" | |
| 7 | |
| 8 #include "core/MediaTypeNames.h" | |
| 9 #include "core/css/MediaValuesCached.h" | |
| 10 #include "core/html/parser/HTMLParserOptions.h" | |
| 11 #include "core/html/parser/HTMLResourcePreloader.h" | |
| 12 #include "core/testing/DummyPageHolder.h" | |
| 13 #include <gtest/gtest.h> | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 typedef struct { | |
| 18 const char* baseURL; | |
| 19 const char* inputHTML; | |
| 20 const char* preloadedURL; | |
| 21 const char* outputBaseURL; | |
| 22 Resource::Type type; | |
| 23 int resourceWidth; | |
| 24 } TestCase; | |
| 25 | |
| 26 class MockHTMLResourcePreloader : public ResourcePreloader { | |
| 27 public: | |
| 28 void preloadRequestVerification(Resource::Type type, const String& url, cons t String& baseURL, int width) | |
| 29 { | |
| 30 EXPECT_EQ(m_preloadRequest->resourceType(), type); | |
| 31 EXPECT_STREQ(m_preloadRequest->resourceURL().ascii().data(), url.ascii( ).data()); | |
| 32 EXPECT_STREQ(m_preloadRequest->baseURL().ascii().data(), baseURL.ascii() .data()); | |
| 33 EXPECT_EQ(m_preloadRequest->resourceWidth(), width); | |
| 34 } | |
| 35 | |
| 36 protected: | |
| 37 virtual void preload(PassOwnPtr<PreloadRequest> preloadRequest) | |
| 38 { | |
| 39 m_preloadRequest = preloadRequest; | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 | |
| 44 OwnPtr<PreloadRequest> m_preloadRequest; | |
| 45 }; | |
| 46 | |
| 47 class HTMLPreloadScannerTest : public testing::Test { | |
| 48 protected: | |
| 49 HTMLPreloadScannerTest() | |
| 50 : m_dummyPageHolder(DummyPageHolder::create()) | |
| 51 { | |
| 52 } | |
| 53 | |
| 54 PassRefPtr<MediaValues> createMediaValues() | |
| 55 { | |
| 56 MediaValuesCached::MediaValuesCachedData data; | |
| 57 data.viewportWidth = 500; | |
| 58 data.viewportHeight = 600; | |
| 59 data.deviceWidth = 500; | |
| 60 data.deviceHeight = 500; | |
| 61 data.devicePixelRatio = 2.0; | |
| 62 data.colorBitsPerComponent = 24; | |
| 63 data.monochromeBitsPerComponent = 0; | |
| 64 data.primaryPointerType = PointerTypeFine; | |
| 65 data.defaultFontSize = 16; | |
| 66 data.threeDEnabled = true; | |
| 67 data.mediaType = MediaTypeNames::screen; | |
| 68 data.strictMode = true; | |
| 69 data.displayMode = WebDisplayModeBrowser; | |
| 70 return MediaValuesCached::create(data); | |
| 71 } | |
| 72 | |
| 73 virtual void SetUp() | |
| 74 { | |
| 75 HTMLParserOptions options(&m_dummyPageHolder->document()); | |
| 76 KURL documentURL(ParsedURLString, "http://whatever.test/"); | |
| 77 m_scanner = createHTMLPreloadScanner(options, documentURL, createMediaVa lues()); | |
| 78 | |
| 79 } | |
| 80 | |
| 81 void test(TestCase testCase) | |
| 82 { | |
| 83 MockHTMLResourcePreloader preloader; | |
| 84 KURL baseURL(ParsedURLString, testCase.baseURL); | |
| 85 m_scanner->appendToEnd(String(testCase.inputHTML)); | |
| 86 m_scanner->scan(&preloader, baseURL); | |
| 87 | |
| 88 preloader.preloadRequestVerification(testCase.type, testCase.preloadedUR L, testCase.outputBaseURL, testCase.resourceWidth); | |
| 89 } | |
| 90 | |
| 91 private: | |
| 92 PassOwnPtr<HTMLPreloadScanner> createHTMLPreloadScanner(const HTMLParserOpti ons& options, const KURL& documentURL, PassRefPtr<MediaValues> mediaValues) | |
|
kouhei (in TOK)
2015/04/30 12:59:21
Move this as HTMLPreloadScanner::create
| |
| 93 { | |
| 94 return adoptPtr(new HTMLPreloadScanner(options, documentURL, mediaValues )); | |
| 95 } | |
| 96 | |
| 97 OwnPtr<DummyPageHolder> m_dummyPageHolder; | |
| 98 OwnPtr<HTMLPreloadScanner> m_scanner; | |
| 99 }; | |
| 100 | |
| 101 TEST_F(HTMLPreloadScannerTest, testImages) | |
| 102 { | |
| 103 TestCase testCases[] = { | |
| 104 {"http://example.test", "<img src='bla.gif'>", "bla.gif", "http://exampl e.test/", Resource::Image, 0}, | |
| 105 {0, 0, 0, 0, Resource::Raw, 0} // Do not remove the terminator line. | |
| 106 }; | |
| 107 | |
| 108 for (unsigned i = 0; testCases[i].inputHTML; ++i) { | |
| 109 TestCase testCase = testCases[i]; | |
| 110 test(testCase); | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 } | |
| OLD | NEW |