| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "core/dom/ScriptLoader.h" |
| 6 |
| 7 #include "core/dom/MockScriptElementBase.h" |
| 8 #include "core/frame/Settings.h" |
| 9 #include "core/testing/DummyPageHolder.h" |
| 10 #include "platform/testing/URLTestHelpers.h" |
| 11 #include "platform/testing/UnitTestHelpers.h" |
| 12 #include "public/platform/Platform.h" |
| 13 #include "public/platform/WebURLLoaderMockFactory.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace blink { |
| 17 |
| 18 namespace {} |
| 19 |
| 20 using ::testing::Return; |
| 21 |
| 22 class ScriptLoaderTest : public ::testing::Test { |
| 23 public: |
| 24 ScriptLoaderTest() |
| 25 : dummy_page_holder_(DummyPageHolder::Create(IntSize(800, 600))) {} |
| 26 |
| 27 Document& GetDocument() const { return dummy_page_holder_->GetDocument(); } |
| 28 |
| 29 private: |
| 30 std::unique_ptr<DummyPageHolder> dummy_page_holder_; |
| 31 }; |
| 32 |
| 33 TEST_F(ScriptLoaderTest, ClassicParserInsertedDeferScript) { |
| 34 MockScriptElementBase* element = MockScriptElementBase::Create(); |
| 35 |
| 36 EXPECT_CALL(*element, GetDocumentPointer()) |
| 37 .WillRepeatedly(Return(&GetDocument())); |
| 38 |
| 39 ScriptLoader* script_loader = |
| 40 ScriptLoader::Create(element, true, false, false); |
| 41 |
| 42 KURL script_url(kParsedURLString, "http://example.com/test.js"); |
| 43 |
| 44 URLTestHelpers::RegisterMockedURLLoad( |
| 45 script_url, testing::WebTestDataPath("touch-action-tests.js"), |
| 46 "text/javascript"); |
| 47 |
| 48 EXPECT_CALL(*element, IsConnected()).WillRepeatedly(Return(true)); |
| 49 EXPECT_CALL(*element, TypeAttributeValue()).WillRepeatedly(Return(String())); |
| 50 EXPECT_CALL(*element, LanguageAttributeValue()) |
| 51 .WillRepeatedly(Return(String())); |
| 52 EXPECT_CALL(*element, AsyncAttributeValue()).WillRepeatedly(Return(false)); |
| 53 EXPECT_CALL(*element, DeferAttributeValue()).WillRepeatedly(Return(true)); |
| 54 EXPECT_CALL(*element, HasSourceAttribute()).WillRepeatedly(Return(true)); |
| 55 EXPECT_CALL(*element, SourceAttributeValue()) |
| 56 .WillRepeatedly(Return("test.js")); |
| 57 EXPECT_CALL(*element, NomoduleAttributeValue()).WillRepeatedly(Return(false)); |
| 58 EXPECT_CALL(*element, EventAttributeValue()).WillRepeatedly(Return(String())); |
| 59 EXPECT_CALL(*element, ForAttributeValue()).WillRepeatedly(Return(String())); |
| 60 EXPECT_CALL(*element, CrossOriginAttributeValue()) |
| 61 .WillRepeatedly(Return(String())); |
| 62 EXPECT_CALL(*element, IsNonceableElement()).WillRepeatedly(Return(false)); |
| 63 EXPECT_CALL(*element, CharsetAttributeValue()) |
| 64 .WillRepeatedly(Return(String())); |
| 65 EXPECT_CALL(*element, IntegrityAttributeValue()) |
| 66 .WillRepeatedly(Return(String())); |
| 67 EXPECT_CALL(*element, InitiatorName()) |
| 68 .WillRepeatedly(Return("TestInitiatorName")); |
| 69 |
| 70 // Set CanExecuteScript() to true. |
| 71 GetDocument().GetFrame()->GetPage()->GetSettings().SetScriptEnabled(true); |
| 72 |
| 73 // Make CompleteURL() to work. |
| 74 GetDocument().SetURL(KURL(kParsedURLString, "http://example.com/")); |
| 75 |
| 76 // Hits 1st Clause, Step 23 of "prepare a script". |
| 77 EXPECT_TRUE(script_loader->PrepareScript()); |
| 78 EXPECT_TRUE(script_loader->WillBeParserExecuted()); |
| 79 EXPECT_TRUE(script_loader->AlreadyStarted()); |
| 80 EXPECT_FALSE(script_loader->ReadyToBeParserExecuted()); |
| 81 EXPECT_EQ(ScriptType::kClassic, script_loader->GetScriptType()); |
| 82 |
| 83 // Following logic is implemented in HTMLParserScriptRunner and is not |
| 84 // tested here. |
| 85 |
| 86 // Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests()
; |
| 87 } |
| 88 |
| 89 } // namespace blink |
| OLD | NEW |