Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Unified Diff: third_party/WebKit/Source/core/dom/ScriptLoaderTest.cpp

Issue 2847363002: Create unit tests of ScriptLoader
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/MockScriptElementBase.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « third_party/WebKit/Source/core/dom/MockScriptElementBase.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698