| Index: third_party/WebKit/Source/core/dom/ScriptLoaderTest.cpp
|
| diff --git a/third_party/WebKit/Source/core/dom/ScriptLoaderTest.cpp b/third_party/WebKit/Source/core/dom/ScriptLoaderTest.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d3ac6f93a3ea1da5145e4d945a1ec6ad33d57c1a
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/dom/ScriptLoaderTest.cpp
|
| @@ -0,0 +1,89 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "core/dom/ScriptLoader.h"
|
| +
|
| +#include "core/dom/MockScriptElementBase.h"
|
| +#include "core/frame/Settings.h"
|
| +#include "core/testing/DummyPageHolder.h"
|
| +#include "platform/testing/URLTestHelpers.h"
|
| +#include "platform/testing/UnitTestHelpers.h"
|
| +#include "public/platform/Platform.h"
|
| +#include "public/platform/WebURLLoaderMockFactory.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace blink {
|
| +
|
| +namespace {}
|
| +
|
| +using ::testing::Return;
|
| +
|
| +class ScriptLoaderTest : public ::testing::Test {
|
| + public:
|
| + ScriptLoaderTest()
|
| + : dummy_page_holder_(DummyPageHolder::Create(IntSize(800, 600))) {}
|
| +
|
| + Document& GetDocument() const { return dummy_page_holder_->GetDocument(); }
|
| +
|
| + private:
|
| + std::unique_ptr<DummyPageHolder> dummy_page_holder_;
|
| +};
|
| +
|
| +TEST_F(ScriptLoaderTest, ClassicParserInsertedDeferScript) {
|
| + MockScriptElementBase* element = MockScriptElementBase::Create();
|
| +
|
| + EXPECT_CALL(*element, GetDocumentPointer())
|
| + .WillRepeatedly(Return(&GetDocument()));
|
| +
|
| + ScriptLoader* script_loader =
|
| + ScriptLoader::Create(element, true, false, false);
|
| +
|
| + KURL script_url(kParsedURLString, "http://example.com/test.js");
|
| +
|
| + URLTestHelpers::RegisterMockedURLLoad(
|
| + script_url, testing::WebTestDataPath("touch-action-tests.js"),
|
| + "text/javascript");
|
| +
|
| + EXPECT_CALL(*element, IsConnected()).WillRepeatedly(Return(true));
|
| + EXPECT_CALL(*element, TypeAttributeValue()).WillRepeatedly(Return(String()));
|
| + EXPECT_CALL(*element, LanguageAttributeValue())
|
| + .WillRepeatedly(Return(String()));
|
| + EXPECT_CALL(*element, AsyncAttributeValue()).WillRepeatedly(Return(false));
|
| + EXPECT_CALL(*element, DeferAttributeValue()).WillRepeatedly(Return(true));
|
| + EXPECT_CALL(*element, HasSourceAttribute()).WillRepeatedly(Return(true));
|
| + EXPECT_CALL(*element, SourceAttributeValue())
|
| + .WillRepeatedly(Return("test.js"));
|
| + EXPECT_CALL(*element, NomoduleAttributeValue()).WillRepeatedly(Return(false));
|
| + EXPECT_CALL(*element, EventAttributeValue()).WillRepeatedly(Return(String()));
|
| + EXPECT_CALL(*element, ForAttributeValue()).WillRepeatedly(Return(String()));
|
| + EXPECT_CALL(*element, CrossOriginAttributeValue())
|
| + .WillRepeatedly(Return(String()));
|
| + EXPECT_CALL(*element, IsNonceableElement()).WillRepeatedly(Return(false));
|
| + EXPECT_CALL(*element, CharsetAttributeValue())
|
| + .WillRepeatedly(Return(String()));
|
| + EXPECT_CALL(*element, IntegrityAttributeValue())
|
| + .WillRepeatedly(Return(String()));
|
| + EXPECT_CALL(*element, InitiatorName())
|
| + .WillRepeatedly(Return("TestInitiatorName"));
|
| +
|
| + // Set CanExecuteScript() to true.
|
| + GetDocument().GetFrame()->GetPage()->GetSettings().SetScriptEnabled(true);
|
| +
|
| + // Make CompleteURL() to work.
|
| + GetDocument().SetURL(KURL(kParsedURLString, "http://example.com/"));
|
| +
|
| + // Hits 1st Clause, Step 23 of "prepare a script".
|
| + EXPECT_TRUE(script_loader->PrepareScript());
|
| + EXPECT_TRUE(script_loader->WillBeParserExecuted());
|
| + EXPECT_TRUE(script_loader->AlreadyStarted());
|
| + EXPECT_FALSE(script_loader->ReadyToBeParserExecuted());
|
| + EXPECT_EQ(ScriptType::kClassic, script_loader->GetScriptType());
|
| +
|
| + // Following logic is implemented in HTMLParserScriptRunner and is not
|
| + // tested here.
|
| +
|
| + // Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
|
| +}
|
| +
|
| +} // namespace blink
|
|
|